Arduino L293D DC motors control

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

Requirements

  • L293D chip
  • Arduino (I’m using UNO)
  • 2x DC Motors
  • 4x AA batteries and holder

First, here’s the chip

L293D

and the specs – the darker small semi-circle is on the TOP –

learn_raspberry_pi_L293D

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)

l293d_arduino_bb

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

This way, you can use a simple chip to control 2 DC Motors.

l293d-2

Happy coding

References

http://computers.tutsplus.com/tutorials/controlling-dc-motors-using-python-with-a-raspberry-pi–cms-20051

https://learn.adafruit.com/adafruit-raspberry-pi-lesson-9-controlling-a-dc-motor/lm293d

9 Replies to “Arduino L293D DC motors control

  1. This explanation was very useful. I finally managed to get my 2WD robot car going. Especially the info that explains which pins to use for the motor direction helped me. I was also hesitating whether or not to use two batteries (one for Arduino, one for motors) but after seeing this I tested it with 4xAA and it worked just fine. Next step for me will be trying to use PWM and adding a power switch.

  2. can i get complete code with Analogwrite and pins …. i have used same configuration but it’s not working , i have powered up my motors with external power of 9v battery …..

    1. Hi Ali.

      The full code is on the page. If you wanna try with Analog PINs, just exchange the 4 PINs controlling the motors with A0, A1…A5 and give it a try.

      Swap the 9v battery for another… Are you sure the battery has charge ?
      Best regards

  3. The code works. However when I use a 9v battery connector to the board the motors dont reverse. Why is that?

    1. Hello !
      In what PIN of the LD293D chip are you powering your circuit ? Do you have enough power ? Are you powering the circuit with an external source (just for the motors) or with the Arduino ?

      Best regards

    1. Hi JarrettF !

      Just use another L293D to control the other two motors. Replicate the schematic with other Arduino PINS – If you want them to move at the same time, connect them to the same PINs as the first one..

Leave a Reply

Your email address will not be published. Required fields are marked *