L293 Motor Driver and H-Bridges

W. Durfee


The most common method to drive DC motors in two directions under control of a computer is with an H-bridge motor driver. H-bridges can be built from scratch with bi-polar junction transistors (BJT) or with field effect transistors (FET), or can be purchased as an integrated unit in a single integrated circuit package such as the L293. The L293 is simplest and inexpensive for low current motors, For high current motors, it is less expensive to build your own H-bridge from scratch.

ITP Physical Computing has a terrific tutorial on using an Arduino and an L293 to control a bi-directional motor.

The Twin Cities Robotics Club has an *excellent* tutorial on H-bridges, and complete detail on how to build your own $5.00 H-bridge good for several amps. From the same source is a detailed tech note on PWM speed control of a motor using an H-bridge and a PIC microcontroller

The L293 is an integrated circuit motor driver that can be used for simultaneous, bi-directional control of two small motors. Small means small. The L293 is limited to 600 mA, but in reality can only handle much small currents unless you have done some serious heat sinking to keep the case temperature down. Unsure about whether the L293 will work with your motor? Hook up the circuit and run your motor while keeping your finger on the chip. If it gets too hot to touch, you can't use it with your motor. (Note to ME2011 students: The L293 should be OK for your small motor but is not OK for your gear motor.)

The L293 comes in a standard 16-pin, dual-in line integrated circuit package. There is an L293 and an L293D part number. Pick the "D" version because it has built in flyback diodes to minimize inductive voltage spikes. The L293D can be purchased for somewhere between $2 and $3 (quantity one) from www.mouser.com (PN 511-L293D) or www.digikey.com (PN 296-9518-5-ND). For complete information, consult the Unitrode L293 data sheet (PDF file, 626Kb).

A more recent, improved specification, pin-for-pin compatible chip is recommended for new designs: the TI SN754410NE motor driver. Available from mouser.com, Mouser part number 595-SN754410NE, $1.88. Data sheet (PDF file, 172Kb).

The pinout for the L293 in the 16-pin package is shown below in top view. Pin 1 is at the top left when the notch in the package faces up. Note that the names for pin functions may be slightly different than what is shown in the following diagrams.

The following schematic shows how to connect the L293 to your motor and the Arduino. Each motor takes 3 Arduino pins. (See notes below for a two Arduino pin solution.) If you are only using one motor, leave L293 pins 9, 10, 11, 12, 13, 14, and 15 empty.

Assume you have only one motor connected with the enable tied to Arduino Pin 3, and the two direction controls tied to Arduino Pins 4 and 5.

Here is a table describing the control pin functions.

ENABLE
DIRA
DIRB
Function
H
H
L
Turn right
H
L
H
Turn left
H
L/H
L/H
Fast stop
L
either
either
Slow stop

 

And here is a short sample program that exercises the L293.

/************************
Exercise the motor using
the L293 chip
************************/

#define ENABLE 3
#define DIRB 4
#define DIRA 5

void setup() {
  int i;

  //---set pin direction
  pinMode(ENABLE,OUTPUT);
  pinMode(DIRA,OUTPUT);
  pinMode(DIRB,OUTPUT);

  //---back and forth example

  digitalWrite(ENABLE,HIGH); // enable on
  for (i=0;i<5;i++) {
    digitalWrite(DIRA,HIGH); //one way
    digitalWrite(DIRB,LOW);
    delay(500);
    digitalWrite(DIRA,LOW);  //reverse
    digitalWrite(DIRB,HIGH);
    delay(500);
  }
  digitalWrite(ENABLE,LOW); // disable
  delay(4000);

  //---fast/slow stop example
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(1000);
  digitalWrite(ENABLE,LOW); //slow stop
  delay(3000);
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(1000);
  digitalWrite(DIRA,LOW); //fast stop
  delay(3000);

  //---PWM example, full speed then slow
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(2000);
  analogWrite(ENABLE,128); //half speed
  delay(2000);
  digitalWrite(ENABLE,LOW); //all done
}

void loop() {
}

Notes

  1. You can save on Arduino pins by connecting the Enable pin to +5V and using just the two direction pins to change directions and turn the motor on and off. Put one pin high and the other low for one direction, reverse the state of the pins for the other direction and put both pins low to turn the motor off.
  2. Put your finger on top of the L293 when running the motor to see if it is getting too hot.
  3. The L293 ground goes to both the battery minus and the Arduino GND.
  4. The L293 has an automatic thermal shutdown which means the chip will stop working if it gets too hot.
  5. You can use the L293 to drive relays and solenoids. Just connect the relay coil or solenoid between one of the driver outputs (pins 3, 6, 11, or 14) and ground and turn it on or off with the control pin (pins 2, 7, 10, 15). This is handy because you could run one bidirectional motor and two relays using just 4 Arduino pins and a single L293.
  6. The L293 is made by several companies. Use these links to get more information and other versions of the L293 data sheet: Texas Instruments (who bought Unitrode) and STS Thomson (who made the original part)
  7. If the L293 is getting too hot it means a drive is needed that can handle more current. Get another L293 and solder it piggy back on top of the first. This will double the drive current.