Professional Documents
Culture Documents
3. THEORY
Servo motor
Stepper motor
A DC motor (Direct Current motor) is the most common type of motor. DC motors normally have just
two leads, one positive and one negative. If you connect these two leads directly to a battery, the
motor will rotate. If you switch the leads, the motor will rotate in the opposite direction.
Warning − Do not drive the motor directly from Arduino board pins. This may damage the board.
4.CIRCUIT DIAGRAM
5. PROCEDURE..
NOTE--Follow the circuit diagram and make the connections as shown in the image given below.
int motorPin = 3;
void setup() {
}
void loop() {
digitalWrite(motorPin, HIGH);
Code to Note
The transistor acts like a switch, controlling the power to the motor. Arduino pin 3 is used to turn the
transistor on and off and is given the name 'motorPin' in the sketch.
boolean motor_dir = 0;
int motor_speed;
void setup() {
pinMode(button, INPUT_PULLUP);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
}
void loop() {
motor_speed = analogRead(pot) / 4;
if(motor_dir)
analogWrite(pwm1, motor_speed);
else
analogWrite(pwm2, motor_speed);
if(!digitalRead(button)){ // If direction button is pressed
while(!digitalRead(button)); // Wait until direction button released
motor_dir = !motor_dir; // Toggle direction variable
if(motor_dir)
digitalWrite(pwm2, 0);
else
digitalWrite(pwm1, 0);
}
}
7.RESULT
Designing of simple DC motor control circuit using arduino is verified after uploading the program.
Evaluation Grid: