Easy Basics: Project 24c One high power 6v/9v DC motor, L293D chip

of Acoptex.com in UNO

Basics: Project 24c

Project name: One high power 6v/9v DC motor, L293D chip

Attachments: sketch

In this project, you needed these parts :

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

2.Jumper cables

3. Momentary switch 2 pcs

4. L293D Dual H-Bridge Motor Driver 600mA 1 pc

5. Potentiometer

6. Resistor 2 pcs (2pcs 10 kOm)

7. Breadboard half size 

8. DC motor 6V/9V 1 pc

9. 9V battery 1 pc

10. Battery snap 1 pc

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


We will learn how to connect one high power motor to Arduino board by dual H-bridge motor driver integrated circuit L293D.

Understanding the DC motor

Controlling motors with an Arduino is more complicated than just controlling LEDs for a couple of reasons. First, motors require more current than the Arduino’s output pins can supply, and second, motors can generate their own current througha process called induction, which can damage your circuit if you don’t plan for it.However, motors make it possible to move physical things, making your projectsmuch more exciting. They’re worth the complications!Moving things takes a lot of energy. Motorstypically require more current than the Arduino can provide. Some motors require a higher voltage as well. To startmoving, and when it has a heavy load attached, a motor will draw as much current as it can. The Arduino can only provide 40 milliamps (mA) from its digital pins, much less than what most motors require to work. Transistors are components that allow you to control high current and high voltagepower sources from the low current output of the Arduino. There are many different kinds, but they work on the same principle. You can think of transistors as digitalswitches. When you provide voltage to one of the transistor’s pins, called the gate, itcloses the circuit between the other two pins, called the source and drain. This way you can turn a higher current/voltage motor on and off with your Arduino. Motors are a type of inductive device. Induction is a process by which a changingelectrical current in a wire can generate a changing magnetic field around the wire.When a motor is given electricity, a tightly wound coil inside the housing of coppercreates a magnetic field. This field causes the shaft (the part that sticks out of thehousing) to spin around.The reverse is also true: a motor can generate electricity when the shaft is spunaround. Try attaching an LED to the two leads of your motor, then spin the shaftwith your hand. If nothing happens, spin the shaft the other way. The LED shouldlight up. You’ve just made a tiny generator out of your motor.When you stop supplying energy to a motor, it will continue to spin, because ithas inertia. When it’s spinning, it will generate a voltage in the opposite direction than the current you gave it. You saw this effect when you made your motor lightup an LED. This reverse voltage, sometimes called back-voltage, can damage yourtransistor. For this reason, you should put a diode in parallel with the motor, sothat the back voltage passes through the diode. The diode will only allow electricity to flow in one direction, protecting the rest of the circuit.

Understanding the L293D

Since motors require more current then the microcontroller pin can typically generate, you need some type of a switch (Transistors, MOSFET, Relay etc.,) which can accept a small current, amplify it and generate a larger current, which further drives a motor. This entire process is done by what is known as a motor driver.

Motor driver is basically a current amplifier which takes a low-current signal from the microcontroller and gives out a proportionally higher current signal which can control and drive a motor. In most cases, a transistor can act as a switch and perform this task which drives the motor in a single direction.Turning a motor ON and OFF requires only one switch to control a single motor in a single direction. What if you want your motor to reverse its direction? The simple answer is to reverse its polarity. This can be achieved by using four switches that are arranged in an intelligent manner such that the circuit not only drives the motor, but also controls its direction. Out of many, one of the most common and clever design is a H-bridge circuit where transistors are arranged in a shape that resembles the English alphabet "H".

As you can see in the image, the circuit has four switches A, B, C and D. Turning these switches ON and OFF can drive a motor in different ways.

  1. Turning on Switches A and D makes the motor rotate clockwise
  2. Turning on Switches B and C makes the motor rotate anti-clockwise
  3. Turning on Switches A and B will stop the motor (Brakes)
  4. Turning off all the switches gives the motor a free wheel drive
  5. Lastly turning on A & C at the same time or B & D at the same time shorts your entire circuit. So, do not attempt this.

H-bridges can be built from scratch using relays, mosfets, field effect transistors (FET), bi-polar junction transistors (BJT), etc. But if your current requirement is not too high and all you need is a single package which does the job of driving a small DC motor in two directions, then all you need is a L293D IC. This single inexpensive package can interface not one, but two DC motors. L293, L293B and few other versions also does the same job, but pick the L293D version as this one has an inbuilt flyback diode which protects the driving transistors from voltage spikes that occur when the motor coil is turned off.

L293D is a dual H-bridge motor driver integrated circuit (IC). L293D contains two inbuilt H-bridge driver circuits. In its common mode of operation, two DC motors can be driven simultaneously, both in forward and reverse direction. The motor operations of two motors can be controlled by input logic at pins 2 & 7 and 10 & 15. Input logic 00 or 11 will stop the corresponding motor. Logic 01 and 10 will rotate it in clockwise and anticlockwise directions, respectively. Enable pins 1 and 9 (corresponding to the two motors) must be high for motors to start operating. When an enable input is high, the associated driver gets enabled. As a result, the outputs become active and work in phase with their inputs. Similarly, when the enable input is low, that driver is disabled, and their outputs are off and in the high-impedance state.

Signals and connections of the L293D


Connect power and ground from one side of your breadboard to the Arduino. Add 2 momentary switches to the breadboard, connecting one side of each to power. Add a 10Kohm pull-down resistor in series with ground on the output pin of both switches. The switch on pin 4 will control direction; the switch on pin 5 will turn the motor on and off. Connect the potentiometer to the breadboard. Wire 5V to one side and ground to the other. Attach the center pin to analog input 0 on the Arduino. This will be used to control the speed of the motor. Place the L293D on your breadboard so it straddles the center. Connect pin 1 of the L293D to digital pin 9 on the Arduino. This is the enable pin on the L293D. When it receives 5V, it turns the motor on, when it receives 0V, it turns the motor off. You will use this pin to PWM the L293D, and adjust the speed of the motor. Connect pin 2 on the L293D to digital pin 3 on the Arduino. Connect pin 7 to digital pin 2. These are the pins you will use to communicate with the L293D, telling it which direction to spin. If pin 3 is LOW and pin 2 is HIGH, the motor will spin in one direction. If pin 2 is LOW and pin 3 is HIGH, the motor will spin in the opposite direction. If both the pins are HIGH or LOW at the same time, the motor will stop spinning. The L293D get its power from pin 16, plug that into 5V. Pins 4 and 5 both go to ground. Attach your motor to pins 3 and 6 on the L293D. These two pins will switch on and off depending on the signals you send to pins 2 and 7. Plug the battery connector (without the battery attached!) to the other power rails on your breadboard. Connect ground from your Arduino to the battery's ground. Connect pin 8 from the L293D to the battery power. This is the pin that the L293D powers the motor from. Make sure you do not have your 9V and 5V power lines connected. They must be separate, only ground should be connected between the two.


Create constants for the output and input pins. Use variables to hold the values from your inputs. You’ll be doing state change detection for both switches, comparing the state from one loop to the next, similar to the Hourglass Project. So, in addition to storing the current state, you’ll need to record the previous state of each switch. motorDirection keeps track of which direction the motor is spinning, and motorPower keeps track of whether the motor is spinning or not. In setup(), set the direction of each input and output pin. Turn the enable pin LOW to start, so the motor isn’t spinning right away. In your loop(), read the state of the On/Off switch and store it in the onOffSwitchState variable. If there is a difference between the current switch state and the previous, and the switch is currently HIGH, set the motorPower variable to 1. If it is LOW, set the variable to 0. Read the values of the direction switch and potentiometer. Store the values in their respective variables. Check to see if the direction switch is currently in a different position than it was previously. If it is different, change the motor direction variable. There are only 2 ways for the motor to spin, so you’ll want to alternate the variable between two states. One way to accomplish this is by using the inversion operator like so: motorDirection =!motorDirection. The motorDirection variable determines which direction the motor is turning. To set the direction, you set the control pins setting one HIGH and the other LOW. When motorDirection changes, reverse the states of the control pins. If the direction switch gets pressed, you’ll want to spin the motor in the other direction by reversing the state of the controlPins. If the motorEnabled variable is 1, set the speed of the motor using analogWrite() to PWM the enable pin. If motorEnabled is 0, then turn the motor off by setting the analogWrite value to 0. Before exiting the loop(), save the current state of the switches as the previous state for the next run through the program.

Step by Step instruction

  1. Plug a 9V battery to your battery snap.
  2. Plug your Adruino Uno board into your PC and select the correct board and com port
  3. Open up serial monitor and set your baud to 9600 baud
  4. Verify and upload the the sketch to your Adruino Uno board
  5. When you press the On/Off switch, the motor should start spinning. If you turn the potentiometer, it should speed up and slow down. Pressing the On/Off button another time will stop the motor. Try pressing the direction button and verify the motor spins both ways. Also, if you turn the knob on the pot, you should see the motor speed up or slow down depending on the value it is sending. Maximum speed of DC motor is 255.


We have learnt how to connect one high power DC motor to Arduino board by L293D


  • No libraries required for this project


  • See attachments on the begining of this project description. 

Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019

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