Tutorial: L293D H Bridge DC motor controller with Arduino

On this tutorial, we will show you how to use the L293D DC motor controller with the Arduino. The L293D is a H Bridge type IC and can control DC motors up to 36V. For detailed specs, check the datasheet.

Let's take a look at the L293D pinout:

As shown in the picture above, it's possible to drive 2 motors with a single L293D, however the power supply has to be strong enough to provide enough current. Here we will demonstrate with just one motor. The following table shows how to make the motor turn clockwise and anti-clockwise:

For example, if the pins 1 and 7 are in HIGH state, and the pin 2 in the LOW, the motor will rotate clockwise. On the other hand, if the pins 1 and 2 are in HIGH, and the pin 7 in the LOW, the motor will turn to the other way.

With a push button, a 10Kohm resistor, a DC motor, a 9V battery, an Arduino and the L293D, let's make this circuit:

On this circuit, the 9V battery supply the energy to the DC motor. Be careful, check you motor datasheet before connect it to the circuit!

After that, open your Arduino IDE and upload this code:

int switchPin = 2; // switch input
int motor1Pin1 = 3; // pin 2 on L293D
int motor1Pin2 = 4; // pin 7 on L293D
int enablePin = 9; // pin 1 on L293D

void setup() {
    // set the switch as an input:
    pinMode(switchPin, INPUT);

    // set all the other pins you're using as outputs:
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(enablePin, OUTPUT);

    // set enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
}

void loop() {
    // if the switch is high, motor will turn on one direction:
    if (digitalRead(switchPin) == HIGH) {
        digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
        digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D high
    }
    // if the switch is low, motor will turn in the opposite direction:
    else {
        digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high
        digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
    }
}

Turn on your circuit and the motor will rotate to one direction. Press the button and the motor will rotate to the other side.

That it! Feel free to comment and post your thoughts. The Garage Lab is and open space to share knowledge and talk about electronics, open hardware, arduino and DIY stuff and hacking.

References:

http://luckylarry.co.uk/arduino-projects/control-a-dc-motor-with-ar...

http://arduino.cc/playground/Main/InterfacingWithHardware

http://www.datasheetcatalog.org/datasheet/stmicroelectronics/1330.pdf

Views: 29821

Tags: L293D, arduino, dc, h-bridge, motor, tutorial

Comment by Rahul Vyas on September 9, 2012 at 3:30am

Hi,

Need urgent help.
 I have a 12v motor which takes 4.55A current at full throttle. I want to control 2 of these motors with my reciever.

Check this link for the motor datasheet- http://www.pitsco.com/sharedimages/resources/DCDriveMotorSpecs.pdf

Also, Can this circuit be modified to control it with a RC reciever/transmitter?

Comment by Marcelo Rodrigues on September 9, 2012 at 7:47am

Rahul,

As the L293 can not drive so high current for your motors, you have to use another thing. I suggest you use an H-Bridge circuit like this one:

Image from http://wiki.mech.uwa.edu.au/index.php/Micro_crash_course/pwm

The idea is making the current flow through the load (motor) in the 2 different directions, making the motor spin to both directions, depending on what mosfets are active. You still can use PWM to control the speed.

Take a look at the article (link above) to understand how it works.

Good luck!

Comment by Ethan on November 3, 2012 at 3:28pm

I was woundering if you could use xbees to make this wireless.  Also can I do this with 2 motors and 1 arduino?  I need help! 

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

GarageLab commented on GarageLab's blog post Tutorial: Using GPS Shield as an Anti-Theft Device
"Hello Pierre, Yes, You can do it. Use a GPS module like one…"
7 hours ago
GarageLab posted a blog post

VoLumen — The Most Advanced Persistence of Vision Display Yet

We’re just blown away by this new project by [Maximilian Mali] and [Sebastian Haushofer]. It’s a…See More
8 hours ago
Amy Ciesielka posted a blog post
12 hours ago
Dam Srasquasz commented on GarageLab's blog post Tutorial: Using GPS Shield as an Anti-Theft Device
"@up you can buy any shield you want for example: click sending text messase is easy and…"
yesterday
Profile IconMarek Florianczyk, Amy Ciesielka and Dam Srasquasz joined GarageLab (arduino, electronics, robotics, hacking)
yesterday
David Braithwaite posted a discussion

Robot, motor, relay kits

Hi,I have been playing around with bots for a few years now, I have found these guys that sell a…See More
yesterday
David Braithwaite replied to derrrick wiltshire's discussion dc motor (small 5v) reverse direction control circuit
" Hi, Check these guys out for these kits, Rk Online Store Laters "
yesterday
Chas Stearns updated their profile
Monday
GarageLab posted a blog post

Real-life Spider-Man webshooter uses a coil gun instead of web fluid

In honor of The Amazing Spider-Man 2 opening tomorrow in Germany (among other places), German laser…See More
Apr 17
Shannon Bradley and Marcelo Rodrigues are now friends
Apr 16
Terry Renner is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 16
Andy S posted a discussion

Arduino MEGA boolean?

Hi everyone,been banging my head against the wall a few days now.i have a small project, where i…See More
Apr 16
Bobby Marshall posted a video

SELFIE Mirror

Meet the S.E.L.F.I.E., the "The Self Enhancing Live Feed Image Engine". Find out how it works: http://istrategylabs.com/2014/04/take-an-instant-selfie-with-t...
Apr 15
GarageLab posted a blog post
Apr 15
pj jones posted a status
"Designing an Home Automation Project"
Apr 14
Profile Iconpj jones, Robert Kribel and Lars Goldschlager joined GarageLab (arduino, electronics, robotics, hacking)
Apr 14
Fontaine Pierre commented on GarageLab's blog post Tutorial: Using GPS Shield as an Anti-Theft Device
"Hi, Is it possible to make a car tracker with this GPS + GSM shield to send a message if limits…"
Apr 11
GarageLab posted a blog post
Apr 11
Profile Iconeslam mohamed haredy, Wesley Castillo and Lise Pape joined GarageLab (arduino, electronics, robotics, hacking)
Apr 10

© 2014   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service