Monday, October 31, 2016

Connecting a 5V DC motor to Arduino using L293D

Controlling a single 5V DC motor thru an Arduino.

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)

 ( check that Pins 1..8 on left and Pin 16 are connected to connect a single 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) ;
   }

No comments:

Post a Comment