Controlling DC Motors using L293D and Arduino

In this tutorial we are going to control DC Geared motors using an Arduino Uno and L293D Motor Driver IC.

Why L293D Driver IC is required?

The current output per pin of Arduino Uno is 20mA which is not sufficient to drive a motor, it will damage that pin on which the motor is connected by drawing more current (100mA – 5A) than expected. Also the output voltage of Arduino pins is 5V and the motor requires 9V-12V.

L293D is a Dual H-Bridge Motor Driver for DC or Steppers

We can run four solenoids, two DC motors or one bi-polar or uni-polar stepper with up to 600mA per channel using the L293D Motor Driver IC.

Pins of L293D

L293D Motor Driver IC Pin Diagram | Alpha Electronz

Enable 1,2/3,4 – We have to give 5V at this pins for the IC to work. And if ground is provided the IC will not Operate.

INPUT 1&2 – To control the 2 terminals of Motor we need to give 1’s and 0’s to this pins, input pins for the motor.

OUTPUT 1&2 – The 2 terminals of the motor will be connected on this Pins of the IC.

INPUT 3&4 – To control the 2 terminals of second Motor we need to give 1’s and 0’s to this pins, input pins for the motor.

OUTPUT 3&4 – The 2 terminals of the second motor will be connected on this Pins of the IC.

GND (4, 5, 12, 13) – This pins will be connected to the ground of the circuit.

VCC2 – This supply will be provided to the motor. If your motor works on 12V apply 12V on this pin.

VCC1 – This is the Supply for the whole IC which is 5V, so connect 5V on this pin.

Components Required

  • Arduino Uno – (Checkout)
  • L293D IC – (Checkout)
  • Breadboard & Jumpers – (Checkout)
  • DC Motors 9V – (Checkout)

Circuit Diagram

Arduino DC Motors L293D Circuit Diagram | Alpha Electronz

We have too short all the grounds of L293D, Arduino and 9V battery. The remaining connection you can refer to the Diagram Above.

Code

/* Code for testing 2 DC Motors using Arduino Uno and L293D Motor Driver IC

For more information visit : http://alphaelectronz.com

*/

//First Motor

int MotorA1 = 4;

int MotorA2 = 5;

//Second Motor
int MotorB1 = 6;
int MotorB2 = 7;

void setup() {
Serial.begin (9600); //configure pin modes
pinMode (MotorA1, OUTPUT);
pinMode (MotorA2, OUTPUT);
pinMode (MotorB1, OUTPUT);
pinMode (MotorB2, OUTPUT);
}

void loop() {
Serial.println ("Motion Forward");
digitalWrite (MotorA1, LOW);
digitalWrite (MotorA2, HIGH);
digitalWrite (MotorB1, LOW);
digitalWrite (MotorB2, HIGH);
delay (3000);

Serial.println ("Motion Backwards");
digitalWrite (MotorA1,HIGH);
digitalWrite (MotorA2,LOW);
digitalWrite (MotorB1,HIGH);
digitalWrite (MotorB2,LOW);
delay (3000);

Serial.println ("Stoping motors");

digitalWrite (MotorA1,LOW);
digitalWrite (MotorA2,LOW);
digitalWrite (MotorB1,LOW);
digitalWrite (MotorB2,LOW);
delay (3000)

}

 

Leave a Reply

Your e-mail address will not be published. Required fields are marked *