Arduino L293D DC motors control
Use a L293D chip to power 2 motors with Arduino

A long time ago, i wrote a little tutorial on how to use a L298 Dual H-bridge motor driver, but i thought i could go further and this time I tried with a L293D chip.
The L293D Chip is a Dual H-Bridge Motor Driver for DC or Step motors. It can handle two Motors or one step motor. It can power motors until 36V and 600mA of steady current – Max of 1.2A.
The chip is easy to use and takes little space
In this tutorial will see how to use it to power 1 or 2 DC Motors
NOTE: If you don’t want to mess with ICs and need a more easy approach, I recommend Grove I2C Motor Driver from Seeed. It’s easy to use and very straightforward. (about seeed)
In a few weeks, I will create something awesome with it. Keep in touch
Requirements
- L293D chip
- Arduino (I’m using UNO)
- 2x DC Motors
- 4x AA batteries and holder
First, here’s the chip
and the specs – the darker small semi-circle is on the TOP –
A little explanation on the Chip PINs
NOTE: As you can see, L293D as two power PINs – 8 (+Vmotor) and 16 (+V). The PIN 8 provides power for the motors ( Separate power source) and the PIN 16 provides power for the chip (provided by the Arduino)
Motor control PINs
EN1 | Enable Motor 1 |
EN2 | Enable Motor 2 |
IN1 | Direction 1 Motor A |
IN2 | Direction 2 Motor A |
IN3 | Direction 1 Motor B |
IN4 | Direction 2 Motor B |
PIN values and meaning to the bridge and motors
PIN | Value | |
IN1 | HIGH | Enables Motor A |
LOW | Disables Motor A | |
IN2 | HIGH | Enables Motor B |
LOW | Disables Motor B | |
IN1 | HIGH | Motor A Forward |
IN2 | LOW | |
IN1 | LOW | Motor A Backwards |
IN2 | HIGH | |
IN1 | LOW | Motor A Stops |
IN2 | LOW | |
IN1 | HIGH | |
IN2 | HIGH |
The same happens when using EN3 and EN4
Wiring
The wiring is simple, but requires atention. Here’s a schematic from Fritzing (click the image for a bigger version)
A table with the connections
L293 PIN | Arduino PIN |
EN1 | 5 |
IN1 | 6 |
IN2 | 7 |
EN2 | 8 |
IN3 | 9 |
IN4 | 10 |
NOTE: In the code i’ve used digitalWrite to enable the IN(x) PINs, but you can use analogWrite (and change INx PINS to PWM PINs) and use values from 0-255 to control speed.
Coding
Here’s the code for the programm
/** * Bruno Santos, 2013 * feiticeir0@whatgeek.com.pt * Small code to test DC motors - 2x with a L298 Dual H-Bridge Motor Driver * Free to share **/ //Testing the DC Motors with // L293D //Define Pins //Motor A int enableA = 5; int MotorA1 = 6; int MotorA2 = 7; //Motor B int enableB = 8; int MotorB1 = 9; int MotorB2 = 10; void setup() { Serial.begin (9600); //configure pin modes pinMode (enableA, OUTPUT); pinMode (MotorA1, OUTPUT); pinMode (MotorA2, OUTPUT); pinMode (enableB, OUTPUT); pinMode (MotorB1, OUTPUT); pinMode (MotorB2, OUTPUT); } void loop() { //enabling motor A Serial.println ("Enabling Motors"); digitalWrite (enableA, HIGH); digitalWrite (enableB, HIGH); delay (1000); //do something Serial.println ("Motion Forward"); digitalWrite (MotorA1, LOW); digitalWrite (MotorA2, HIGH); digitalWrite (MotorB1, LOW); digitalWrite (MotorB2, HIGH); //3s forward delay (3000); Serial.println ("Motion Backwards"); //reverse digitalWrite (MotorA1,HIGH); digitalWrite (MotorA2,LOW); digitalWrite (MotorB1,HIGH); digitalWrite (MotorB2,LOW); //5s backwards delay (3000); Serial.println ("Stoping motors"); //stop digitalWrite (enableA, LOW); digitalWrite (enableB, LOW); delay (3000); }
This way, you can use a simple chip to control 2 DC Motors.
Happy coding
References
https://learn.adafruit.com/adafruit-raspberry-pi-lesson-9-controlling-a-dc-motor/lm293d
Studio Seeed is the IoT hardware enabler providing services over 10 years that empower makers to realize their projects and products. Seeed offers a wide array of hardware platforms and sensor modules ready to be integrated with existing IoT platforms and one-stop PCB manufacturing and Prototype PCB Assembly. Seeed Studio provides a wide selection of electronic parts including Arduino, Raspberry Pi and many different development board platforms. Especially the Grove System help engineers and makers to avoid jumper wires problems. Seeed Studio has developed more than 280 Grove modules covering a wide range of applications that can fulfill a variety of needs.