Monday, October 31, 2016
Connecting a 5V DC and a 12V DC motor to Arduino using L293D
Controlling a single 5V DC motor, and a 12V DC thru an Arduino.
Both are same connections -except that for a 5V, the Vss Motor Supply ( pin 8) will be fed 5V from the wall adapter
for a 12V, the Vss will be fed 12Vwall adapter, and the GND will be common across all.
Connect Pins 8 and 9 of the Arduino to Pins 3 and 7 of the L293D
Arduino L293D
Pin 8 Pin 7
Pin 9 Pin 2
GND -> GND // or else it wont work
Pin 4 -> GND
Pin 5 -> GND
Pin 1 -> +5V
Pin 16-> +5V ( or tie them up)
Pin 3 -> Output to Motor
Pin 6 -> Output to Motor
Pin 2, and 7 ( as described above, goes to Arduino Pins 8 and 9)
Pin 8 -> motor supply +5V ( Pin 1, 16 and Pin 8 - can all be tied to +5V)
For a 5V motor
Pins 1..8 on left and Pin 16 are connected to connect a single DC motor in case of a 5V.)
Pin 8 -> +5V ( all of them as 5V )
For a 12V motor
Check 1 and 16 are internal - so 5V.
Pins 8 is +12V
For a 5V DC motor.
For a 12V DC motor.
void setup()
{
pinMode(8,OUTPUT) ; //Logic pins are also set as output
pinMode(9,OUTPUT) ;
Serial.begin (9600);
}
void loop()
{
forward_motor ();
delay(3000) ;
stop_motor ();
delay(3000);
backward_motor ();
delay(3000);
stop_motor ();
delay(5000);
}
void forward_motor () {
Serial.println ("forward");
digitalWrite(8,HIGH) ;
digitalWrite(9,LOW) ;
}
void stop_motor ()
{
// Stop
Serial.println ("Stop " );
digitalWrite(8,LOW) ;
digitalWrite(9,LOW) ;
}
void backward_motor ()
{
Serial.println("backward");
digitalWrite(8,LOW) ;
digitalWrite(9,HIGH) ;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment