hi welcome to an Arduino step-by-step course by Robojax
in this lecture we are going to learn how to use this l293d quadruple h drive motor driver
this this can be used to control dc motor with a current of 600 milliampere
and the operating voltage of this one is between 4.5 to 36 volts
here is the data sheet for l293 and l293d we're concerned with l293d this is called quadruple
half branch every time we mention the word a half bridge or full bridge full bridge means
if you are able to control a motor in two direction that is called full bridge and
every time you can just control a motor turn it on and off without being able to control
the direction that is called half bridge when this is quadruple half bridge it means it has dual full
bridge which means it can control two motors fully in both direction clockwise and counterclockwise
we are going to use it and see the operating voltage is 4.5 to 36 volts
what it means is that you can use a 5 volts motor 6 volts 12 volts 24 36 volts
any voltage between this range will be able to operate or controlled by this motor
controller it has separate logic input which means you can control it using Arduino which
can have separate voltage of 5 volts and the motor will have separate voltage high noise
immunity which means noise will not have affected it has internal electrostatic discharge protection
so it will protect it against any electrostatic when your body has static charges when you touch
the device it will protect it this is important for that we need to have a look at it for l293d
the maximum current each channel or per channel will be 600 milliampere maximum peak the output
peak current for l293d will be 1.2 and there is two ampere for the l293 and one ampere per channel
is 293 before we need a diode clamp for inductive transient and l293d means diode that this device
has already built in diode and it makes circuitry and wiring very easy so this is a logic diagram
this is a motor driver so we have quadruple we have four of this this is the input and that is
the output most of the time because you control a motor in both directions this pin one is for
this half bridge and this half bridge uh one and two so there's a half bridge one half bridge two
and this is three and four so one and two can be control enabled using this pen you put you
connect this pen to five volts and this will be enabled then you can control it turn on and off so
this is on and off and this is control in the next tutorial we are going to talk about this
but for now just learn that this can this should be high in order for the output to be high
voltage the control signal comes here and it waits until this is high when this is high
the current will pass and the same thing if this is high this will pass and we will connect our
motors and these 2 1 7 10 9 and 15 these numbers are the pen of this remember 1 a 2 a 3 a 4 a all
a's are the input and y are the output 1 a and 1 y 1 a is the input of this quadruple
driver and 1 y is the output and the same thing 2a2y3a3y and 4a4y and each of them have their
own pin on the actual physical chip and here is a 16 pin chip that we are going to use
one a this is the input of a and that's one y that's the output of y this this is one
half bridge driver and pin four and five is heat sink and also it will be connected to the ground
on this side also we have pin 12 and 13 are heating and ground so we will be connecting
4 5 12 and 13 to the ground I have branch number one that's half bridge number 2,
2 a is the input two y is the output for both of this on this side we have one
enable pen one two so if you set this pin one to five volts or connected to five volts
this half bridge and this half bridge will be enabled and on this side we have this is vcc2
this is the actual power for the motor and this is power for the logic internally in order to control
this and turn on and off enable and disable this needs 5 volts so this will be connected in our
case to Arduino and this we will see next and this is number three this is a half bridge of number
three and this is half bridge number four as you can see a4 is the input and that is the output
and the a is the input and three y is the output and these pins have been numbered from here one
two three four five eight pin we have on one side and an eight pin we have on the other side
from pin 1 2 and 16. how we know this because of this notch here you can identify it by this
by this and by this round from this side we know that this is forward and this dot here
it tells you that one starts from here so this dot will tell you that one starts from here and
so you count one two three four five six seven eight eight is here and 16 is there
so it comes from here 9 10 11 12 13 14 15 16. keep that in mind and that is why that the input 1 a
will be pin 2 so we will connect the signal from Arduino to this and then this will be the output
and we this is enabled which we will connect it to 5 volts or we will use other means
here is how we can control one motor using single half bridge
in one direction in order to change the direction of the motor manually we can just switch these two
wires otherwise when you turn it on whatever wire you have it will rotate in the pre-set direction
so when a will be high and the output will be connected here and it will wait until enable
pin is high in this case in our chip pin 2 a this will be connected to Arduino pen
three is the output we will connect it to the motor and pin one of the chip is
enabled which we will connect to five volts the other side of this wire will be connected to low
and here is a wiring diagram for l293d motor driver first on the breadboard I have
assigned this line on the breadboard with a blue beside it as in the ground and the one with the
red line beside it has five volts the five volts line have been connected to five volts of Arduino
the ground have been connected to the ground so we have ground and five volts here
when you prepare l293d chip or working with Arduino first prepare your breadboard like this
and pay attention here pin one is on this side and the notch is here so pin one up to eight
and from here nine to sixteen first two pin at the middle we have three pin on this side
repeating on this side pin four and five connect them together with a piece of jumper wire and then
from other wire connected to the blue side of this breadboard and then the other side two pin
together connected with this wire with one piece of wire and then from this or this because they
are now together put another wire to the ground so this side is connected to the ground and two
pin from the other side have been connected to the ground now two more pin left and eight on
this side and 16 on the other side eight will be connected to positive and 16 will be connected to
positive this is the logic main one will never change but this one if you need to use your
battery you remove it and connect your battery directly here which I’m going to explain it
within the wiring diagram when we are using external power and then for the motor we need
separate voltage in this case because my motor is 5 volts I’m connecting this wire directly to
5 volts and here is when you need to use external power supply or battery doesn't matter remove the
pin 8 which was connected to this 5 volts and then from your positive terminal of the
power supply or the battery connect a wire to pin eight of this chip and
from the negative terminal you must connect also to the ground if you do not connect this
with one wire the system will not work the chip in terms of power and biasing is done now two pin
one is the input, input have been connected to pin two and then pin one is enable. enable have been
connected to pin three of Arduino and my motor ground have been connected to the ground and one
of the pen of the motor have been connected to pin 3 which is the output for l293d chip
it says the l293d chip or ic and here if I tilt it at some angle you will be able to see to see
the pin one mark here from this dot this is pin one two three four five six seven eight
and then from here nine it goes up to sixteen and here is the pen layout from the data sheet pin one
two pin sixteen on my breadboard the blue line on this side have been dedicated for the ground and
the red on this side have been dedicated for 5 volts so I will connect my 5 volts from Arduino
to this line somewhere and my ground somewhere in here and pin 4 and 5 12 and 13 are supposed
to be connected to the ground and here you can see pin four have been connected to pin five
using this wire I’ve been connected to the ground and pin 12 and 13 have been connected together
they are where the yellow wire have been connected to the ground so these two pin at
the middle on the left and two pin that at the middle on the right are for the ground pin 16
is vcc one or logic this has been connected to five volts using the blue wire this is a pin 16
vcc one pin it has been connected using this red wire to five volts for this reason we will use
only one half branch pin two is the input and pin 3 is the output here I’ve connected pin 2
of Arduino to the pin 2 of this chip and print 3 of Arduino I’ve connected it to pin 1 of this chip
for my power supply ground has been connected to the ground to the blue side and five volts
have been connected to this red side for my motor
as I’ve shown you in the wiring diagram blue is my ground and for my motor blue is connected to
the ground and this purple or red have been connected to pin three now the wiring is done
let me now explain the code first we define pin two as motor 1 this is our constant which
will be used throughout the code and then we define pin 2 for enable 1 2. and inside
the setup we initialize the serial monitor so this can print the text for us with 9600 baht
and we use pen mode motor one as well as outputs and then again we use pen mode enable two as
output so we don't need any input these two are output from Arduino in order to run the motor
we have to have enable one always high so I use digital right high it will always send
pen three as high inside the loop this is a very simple control of motor
we print this text using serial print ln motor one on and then digital right motor one this has been
too high so we turn motor one on and for five seconds so this weight means
keep the motor running for just five seconds after that
we turn the motor to motor one low print this text and then wait for three seconds
because this is a loop there is nothing else continuously loop will execute these codes
and motor will just run for five seconds stop for three seconds and goes on
I’ve connected the motor as you can see motor is running let me open the serial monitor
it will just reset it prints motor one on and also the motor is rotating as you can see it's
going clockwise
and when it says stop the motor is stopped
now if you pay attention and see the motor is rotating clockwise
to change the direction of rotation just swap the two wires from the motor let me just change it
now the motor will rotate counter clockwise
and here is the new code that you can control the speed
the change that I brought was that I commented this line out by putting this forward slash so
enable pin is not high at the beginning in the setup using this enable pin we send a pulse width
modulation signal and control the speed of motor we set the motor 1 input high it must be high then
we use analog write and for pen enable 1 2 we send 2 5 5 of pulse width modulation 255 or 255 means
maximum and 0 means stop so we send that value and also we print this on the screen
and we wait for 3 seconds so the motor runs at 255 password modulation value or 100 for three seconds
after that then we change the speed to half by sending 127 password modulation print the text
and this happens for five seconds after that we change the speed to 95 for five seconds then we
send zero pulses modulation which means stop the motor the motor will be stopped for 5 seconds
after that we send again 255 the maximum speed for 3 second and then we use another method again
by sending low to the input to stop the motor as you can see we can stop the
motor either by sending the zero pulses modulation or sending the input to low
in order for the motor to run neither of these should be low at any time
when we have zero value at the input the motor will stop or the motor will slow
down and here let me connect the motor
and I open the pulse with modulation as you can see this is the maximum speed
and now we are at half speed
now it's at 95.
then we send zero value the motor is stopped then again at the maximum 255
and this is a stop using low signal again the loop repeats 255
and then 127 and then 95 which will be very slow and then zero as you can see we cannot
go to zero because this motor each model will be different this motor will stop at around 80 or 90.
I tried different value and 95 was the lowest that I could go while the motor was running
this was how to control a motor with the speed without changing the direction
in the next video we are going to have a look at changing the direction of the motor
please make sure to subscribe by clicking at the subscribe button in here thank you
thank you for watching tutorial from Robojax if you learned something and found this useful
please thumb up as this will help my video in the search algorithm of YouTube
if you have comment or question please post it at the comment section below
I try to answer and reply and don't forget to subscribe to get updates on my upcoming video