I have a question regrading the DC motor. In my microcontroller class, all we have worked with is Servo motors, which has a input, ground, and positive connection. From my understanding, I went to the electronics store and bought a 12VDC motor with two MOM buttons. The problem is, I'm not sure how to write the code, and how to setup the actual board. I really just want to say that if the start button is pressed, the motor will be energized. If the stop button is pressed, the motor will stop running. Also, I need a potiementer in the project to control the speed of the motor. If anyone can help me understand the logic, that would be greatly appreciated.
Regards
You need a transistor and a diode in the mix, something along these lines.
for the code, this is what i understood so far.
int startMotor = 6; //start button
int stopMotor = 7; //stop button
int poti = 8; // potiometer
int posMotor = 9; // postive terminal of 12VDC motor
int negMotor = 10; // negitave terminal of 12VDC motor
void setup() {
pinMode(startMotor, OUTPUT);
pinMode ( stopMotor, OUTPUT);
pinMode (poti, OUTPUT);
pinMode (posMotor, OUTPUT);
pinMode (negMotor, OUTPUT);
}
void START ()
{
digitalWrite(6, HIGH);
delay(2);
}
void STOP ()
{
digitalWrite(10, HIGH);
delay(2);
}
void RES ()
{
digitalWrite(8,HIGH);
delay(2);
}
void POSITIVE ()
{
digitalWrite(9,HIGH);
delay(2);
}
void NEG ()
{
digitalWrite(10,HIGH);
delay(2);
}
void loop()
{
if (startMotor) == HIGH;
{
START();
RES();
POSITIVE();
}
else if (stopMotor) = HIGH;
{
STOP();
RES();
NEG();
}
}
}