Easy Advanced: Project 027c L293D H-bridge motor control shield, two or four DC motors

of Lex C in UNO

Advanced: Project 027c

Project name: L293D H-bridge motor control shield, 2 or 4 DC motors

Attachments: 2DC motors with library sketch1, 4DC motors with library sketch3libraries

Tags: Arduino, DC motor, L293D H-bridge motor control shield, Adafruit motor shield

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables

4. Breadboard

5. L293D H-bridge motor control shield (Adafruit motor shield) 1 pc

6. Small-sized DC Motor 4 pcs


We will learn how to connect L293D H-bridge motor control shield and 2 or 4 DC motors to Arduino board.

Understanding the L293D H-bridge motor control shield for Arduino (old Adafruit Motor Shield)

"Adafruit Motor Shield" was designed by Adafruit but Adafruit stopped to make it in 2014 due to a new and much better motor shield production. We will get explaned the old motor shield here as it is still activelly used around the world and there are clone boards produced in China. This shield contains two L293D motor drivers and one 74HC595 shift register. The shift register expands 3 pins of the Arduino to 8 pins to control the direction for the motor drivers. The output enable of the L293D is directly connected to PWM outputs of the Arduino.

It appears that SN754410 pin-compatible motor driver chip (it has output diodes and can provide 1A per motor, 2A peak) output diodes are designed for ESD protection only and that the use of them as kickback-protection is a hack and not guaranteed for performance. For that reason the motor shield did not come with the SN754410 and instead uses the L293D with integrated kickback-protection diodes. If you're willing to risk it, and need the extra currrent, feel free to buy SN754410's and replace the provided chips.

To increase the maximum current, the L293D allows extra chips with "piggyback". Piggyback is soldering one or two or three extra L293D drivers on top of the L293D drivers on the board to increase the maximum current. The L293D allows parallel operation. Figure out is how much current your motor will need.The motor driver chips that come with the kit are designed to provide up to 600 mA per motor, with 1.2A peak current. Note that once you head towards 1A you'll probably want to put a heatsink onthe motor driver, otherwise you will get thermal failure, possibly burning out the chip.

You can use 2 DC 5V servos and up to 4 DC motors or 2 stepper motors (or 1 stepper and up to 2 DC motors).

Motors take a lot of power, and can cause 'brownouts' that reset the Arduino. For that reason the shield is designed for seperate (split) supplies - one for the electronics and one for the motor. Doing this will prevent brownouts. It does not work for 3V motors as its meant for larger 6V+ motors. Unless you overdrive them at 6V and then they will burn out faster.The first important thing to figure out what voltage the motor is going to use. If you're lucky your motor came with some sort of specifications. Some small hobby motors are only intended to run at 1.5V, but its just as common to have 6-12V motors. The motor controllers on this shield are designed to run from 4.5V to 25V. MOST 1.5-3V MOTORS WILL NOT WORK.

All 6 analog input pins are available as they are not used on the motor shield. They can also be used as digital pins (pins #14 thru 19). Digital pin 2, and 13 are not used.

The DC/Stepper motors are NOT connected to the Arduino directly. They are connected to the 74HC595 latch which is spoken to by the Arduino. You CANNOT talk directly to the motors, you MUST use the motor shield library.
The motors used in the 4WD robot platforms from Maker Shed, DF Robotics, Jameco and others have a lot of "brush noise". This feeds back into the Arduino circuitry and causes unstable operation. This problem can be solved by soldering 3 noise suppression ceramic or disc 0.1uF capacitors to the motor: 1 between the motor terminals, and one from each terminal to the motor casing.
If your motor already has a capacitor on it and still doesn't work - it is because these motors generate a lot of brush noise and usually need the full 3-capacitor treatment for
adequate suppression. These extra capacitors would not be effective on the shield as the noise must be suppressed at the source or the motor leads will act like antennae and broadcast it to the rest of the system.
You can't run motors off of a 9V battery so don't even waste your time/batteries! Use a big Lead Acid or NiMH battery pack. Its also very much suggested that you set up two power supplies (split supply) one for the Arduino and one for the motors. 99% of 'weird motor problems' are due to noise on the power line from sharing power supplies and/or not having a powerful enough supply
Adafruit motor shield v1 features:
  • 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal shutdown protection, 4.5V to 25V
  • Pull down resistors keep motors disabled during power-up
  • Big terminal block connectors to easily hook up wires (10-22AWG) and power
  • Arduino reset button brought up top
  • 2-pin terminal block to connect external power, for seperate logic/motor supplies
  • Tested compatible with Mega, Diecimila, & Duemilanove
  • 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution dedicated timer - no jitter. The servo motors use the +5V of the Arduino board. The voltage regulator on the Arduino board could get hot. To avoid this, the newer Motor Shields have connection points for a separate +5V for the servo motors. Hobby servos are the easiest way to get going with motor control. They have a 3-pin 0.1" female header connection with +5V, ground and signal inputs. The motor shield simply brings out the 16bit PWM output lines to two 3-pin headers so that its easy to plug in and go. They can take a lot of power so a 9V battery wont last more than a few minutes! 5V 'Hobby' servos are the easiest way to get going with motor control. They have a 3-pin 0.1" female header connection with +5V, ground and signal inputs. The motor shield simply brings out the 16bit PWM output lines to two 3-pin headers so that its easy to plug in and go. They can take a lot of power so a 9V battery wont last more than a few minutes.
  • Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5%resolution)
  • Up to 2 stepper motors (unipolar or bipolar)with single coil, double coil, interleaved or micro-stepping.

L293D is a typical Motor driver or Motor Driver IC which allows DC motor to drive on either direction. L293D is a 16-pin IC which can control a set of two DC motors simultaneously in any direction. It means that you can control two DC motor with a single L293D IC. In a single L293D chip there are two H-Bridge circuit inside the IC which can rotate two dc motor independently. H-bridge is a circuit which allows the voltage to be flown in either direction. H-bridge IC are ideal for driving a DC motor.Due its size it is very much used in robotic application for controlling DC motors.

See more information about L293D here.

You can find L293D datasheet here.

Understanding the DC motors

Converts electrical energy into mechanical energy when electricity is applied to its leads. Coils of wire inside the motor become magnetized when current flows through them These magnetic fields attract and repel magnets, causing the shaft to spin. If the direction of the electricity is reversed, the motor will spin in the opposite direction.

The maximum current of an Arduino I/O port is 20 mA but the drive current of a motor is at least 70 mA. Therefore, we cannot directly use the I/O port to drive the current; instead, we can use an L293D to drive the motor.

This is a 5V DC motor. Give the two terminals of the copper sheet one high and one low level, and the motor will rotate. For convenient purposes, you can weld the pins to it.

Size: 25*20*15MM                                                  

Free-run speed (3V): 13000 RPM 

Stall current (3V): 800 mA;                                  

Shaft diameter: 2 mm

Operation Voltage: 1-6V                                      

Free-run current (3V): 70 mA 

 Note that the H-bridge chip is not meant for driving loads over 0.6A or that peak over 1.2A so this is for small motors. Check the datasheet for information about the motor to verify its OK.

Signals and connections of DC motors

To connect a motor, simply solder two wires to the terminals and then connect them to either the Port1 (M1), Port 2 (M2), Port 3 (M3) or Port 4 (M4) of the L293D motor driver shield. 

Signals and connections of the L293D H-bridge motor control shield for Arduino

  • Supply the power either through the Arduino Board or the power header of the Motor Shield.
  • Power jumper - only if the Arduino Board and the Shield use a separate power supply, it must be removed.
  • 2 5V servo motors can be connected to Servo 1 andServo2. Pins - (GND or Ground), + (VCC), s (Signal);
  • Power LED + indicates that the DC/Stepper motor power supply is working. If it is not lit, then the DC/Stepper motors will not run. The servo ports are 5V powered and does not use the DC motor supply;
  • Reset button - Arduino board reset button;
  • 4 DC bi-directional motors can be connected to terminal blocks M1 (A,B), M2 (A,B), M3 (A,B), M4 (A,B). That means they can be driven forwards and backwards. The speed can also be varied at 0.5% increments using the high-quality built in PWM. This means the speed is very smooth and won't vary! Note that the H-bridge chip is not meant for driving loads over 0.6A or that peak over 1.2A so this is for small motors. Check the datasheet for information about the motor to verify its GOOD to use. 
    The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V. Don't
    connect the motor power supply to the 5V line. This is a very very very bad idea unless you are
    sure you know what you're doing!
    The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V. Don't connect the motor power supply to the 5V line. This is a very bad idea unless you are sure you know what you're doing!
  • 2 stepper motors: one can be connected to terminal blocks M1 (A,B), GND, M2(A,B), another to terminal blocks M4 (A,B), GND, M3 (A,B);
  • Power for the Servos comes from the Arduino's on-board 5V regulator, powered directly from the USB or DC power jack on the Arduino. If you need an external supply, cut the trace right below the servo pins (on v1.2 boards) and connect a 5V or 6V DC supply directly. Using an external supply is for advanced users as you can accidentally destroy the servos by connecting a power supply incorrectly! When using the external supply header for servos, take care that the bottom of the header pins do not contact the metal USB port housing on the Arduino. A piece of electrical tape on the housing will protect against shorts;
  • There are two places you can get your DC motor 'high voltage supply' from. One is the DC jack on the Arduino board and the other is the 2-terminal block on the shield that is labeled EXT_PWR. The DC Jack on the Arduino has a protection diode so you won't be able to mess things up too bad if you plug in the wrong kind of power. However the EXT_PWR terminals on the shield do not have a protection diode (for a fairly good reason). Be careful not to plug it in backwards or you will destroy the motor shield and/or your Arduino!

If you would like to have a single DC power supply for the Arduino and motors, simply plug it into the DC jack on the Arduino or the 2-pin PWR_EXT block on the shield. Place the power jumper on the motor shield.

If you have a Diecimila Arduino, set the Arduino power source jumper to EXT. Note that you may have problems with Arduino resets if the battery supply is not able to provide constant power, and it is not a suggested way of powering your motor project.

If you would like to have the Arduino powered off of USB and the motors powered off of a DC power supply, plug in the USB cable. Then connect the motor supply to the PWR_EXT block on the shield. Do not place the jumper on the shield. This is a suggested method of powering your motor project. (If you have a Diecimila Arduino, don't forget to set the Arduino power jumper to USB. If you have a Diecimila, you can alternately do the following: plug the DC power supply into the Arduino, and place the jumper on the motor shield.)

If you would like to have 2 separate DC power supplies for the Arduino and motors. Plug in the supply for the Arduino into the DC jack, and connect the motor supply to the PWR_EXT block. Make sure the jumper is removed from the motor shield. If you have a Diecimila Arduino, set the Arduino jumper to EXT. This is a suggested method of powering your motor project

Either way, if you want to use the DC motor/Stepper system the motor shield LED should be lit indicating good motor power.

Shields are boards that can be plugged on top of the Arduino PCB extending its capabilities. The different shields follow the same philosophy as the original toolkit: they are easy to mount, and cheap to produce.Every Arduino shield must have the same form-factor as the standard Arduino. Power and ground pins on one eight (previously six) pin header, and analog pins on a six-pin header next to that. Digital pins cover the other edge on the other side, an eight-pin header separated from a 10-pin by that weird 0.5" spacing. Some shields also require a connection to the Arduino’s ICSP header (the 2x3 programming header on the end).Some shields use every pin on the Arduino, while others only use a couple. When stacking shields, it’s important to make sure they don’t use overlapping pins. Some shields communicate with the Arduino via SPI, I2C, or Serial, and others use the Arduino’s interrupts or analog inputs.

Build the circuit

The following picture shows the needed connections with the Arduino Uno.

L293D motor driver shield installed on top of Arduino Uno board

1. Method. Arduino board powered off of PC USB and DC motors powered off of a DC power supply. DC motors powered from external DC supply connected to the PWR_EXT block on the L293D motor driver shield. Do not place the Power jumper on the L293D motor driver shield. Arduino board powered from PC USB.

2. Method. 2 separate DC power supplies for the Arduino board and motors. Plug in external supply for the Arduino board into Arduino Board DC jack, and connect the external DC supply for DC motors to the PWR_EXT block on the L293D motor driver shield. Make sure the Power jumper is removed from the L293D motor driver shield.


  • Make sure you include library code
  • Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge and latches. The constructor takes two arguments.  The first is which port the motor is connected to, 1, 2, 3 or 4. frequency is how fast the speed controlling signal is. For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, or MOTOR12_1KHZ. A high speed like 64KHz wont be audible but a low speed like 1KHz will use less power. Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given.
  • Then you can set the speed of the motor using setSpeed(speed) where the speed ranges from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.
  • To run the motor, call run(direction) where direction is FORWARD, BACKWARD or RELEASE. Of course, the Arduino doesn't actually know if the motor is 'forward' or 'backward', so if you want to change which way it thinks is forward, simply swap the two wires from the motor to the shield.

Step by Step instruction

  1. Install the AFMotor library. See notes below in Library section.
  2. Open Arduino IDE.
  3. Plug your Adruino Uno board into your PC and select the correct board and com port
  4. Open up serial monitor and set your baud to 9600 baud
  5. Verify and upload the the sketch to your Adruino Uno board


We have learnt how to connect L293D motor control shield and 2 or 4 DC motors to Arduino board. 


  • Before you can use the Adafruit Motor shield, you must install the AFMotor library. We have attached it on the begining of this project.So download, unzip and add to libraries in your PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC.


  • See attachments on the begining of this project description. 

Other projects of Lex C
Easy Basics: Project 057a ACR122U NFC Reader of Lex C, Not selected 17-01-2018

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 08-09-2017
Viewed: 425 times