hi welcome turn our doing a tutorial from Robo Jax my name is Ahmed sham city presenting this
tutorial from Canada in this tutorial I'm going to show you how we can use this l-29
8n motor controller module to control DC motors with push buttons for example for this murder
I have counterclockwise and clockwise push button and also start and stop if I press
this the motor restore rotating and if I press it the motor referred in different
direction or I can stop it so you can change the direction clockwise and counterclockwise
and also start I'll stop you can control to Moodle for this module you can get the code
for this by clicking at the link below the video in the description which will take
you to Robo Jack's comm slash learn flash or do we know let's get started with this
a separate video explaining this module I have written a library for this that you can use
this to control DC motor very easily make sure to watch that video and make sure that you are able
to control to DC motor without any push-button or any other component just ethically connected so
it will be very easy for you to continue in this tutorial otherwise you will have a lot
of issues there are instances that you need to control a DC motor for example to press a push
button and motor will rotate it and then you need to press the stop button to stop it and
also there is another push button that you need to change the direction from clockwise
to counter clockwise and vice versa so this code is for that applications and for some
other purpose also you can just manipulate and change the coordinates instead of push
button you can control the motor or some kind of signal sensor or external parameters as well
let me explain the wiring for this module this is my battery wire wherever I connect my battery
and the positive will be connected at this point you can connect from six to thirty five volts if
you are using 5 volts connect five or six volts because they're very a little voltage drop here
so depending on your motor voltage connected if you have 24 volts motor connect 24 volts if you
have 35 volts after 35 volts can be connected in here and the second wire is here ground from this
point I have this gray wire which is connected to all do we know you need to connect a common
ground between the module and the last one is output of 5 volts I've explained this in my
separate video so the 5 volts come from here and you will supply 5 volts to Arduino by connecting
it death then you will connect it only if the USB is not connected when your program it and
the power is here make sure to disconnect it so that current does not flow between the two
devices and here for the push-button this is for clockwise and counterclockwise control and this
is for stop and start and I'm using this long type push button with a long pins which I've
purchased from eBay this side is connected using this wire to this blue line this is my
ground and from here also I've connected this to the ground from this point I've three wires
like this orange has connected to the left pin of this switch and then red is connected to the left
of stop and from this point there's a ground I've connected the ground here to ground off Arduino at
this point and then from for the right push-button the orange is connected to pin 8 and then for the
left or store the stop push button that it is connected to pin 9 and here for murder one we
are using three pens and these three pens will be used for murder two dishes enable a en a and E and
a spouse's modulation in Ableton it is connected to pin 3 which as possible modulation tilde as
you can see five six also has a tilde nine ten and eleven that is or not and make sure you will
connect this enable a to a pin that is possible modulation enabled and put one is connected to
pin 2 using gray wire and input 2 is connected using white wires too painful and here is the
wiring for the second motor this is for clockwise and counterclockwise for the second motor this is
for the start and stop of a second motor the same way as before the right side is connected to the
ground this is my ground which I have already connected only this one for the actual switch
Green is connected to pin 10 for this clockwise counter clockwise and for the stop using blue
it has been connected to pin 11 and here for the data this is in 3 this is in 4 and that's
enable B I've connected accordingly in Reverse enable B is connected to pin 5 because this is
positive ovulation and the next one is green this is connected to pin fix and put 4 and input 3 is
blue there has been connected to pin 7 my second motor is connected at this point on this side
let me explain the code now as I've explained you have to download and install the library watch the
introduction video this line says include Robo jacks l-29 it in DC motor this is a library that
I have written and it will be included because it is needed and we are defining in one pin two three
and four in two and pin three four enable a pin das has this tilde it means passive modulation in
Ableton and you must have pulse width modulation in Ableton for this and we are defining CCW as a
number two and CW as one and motor one as one motor two and us to do not change these will
be used internally and here this is a constant integers push-button delay time this is the time
that when you press a push-button it takes a while before you left your pin up with finger up or when
you press it you need some time so this time is experimentally determined that it will work
for me you can change it either reduce it make it smaller value or which means it will be faster or
increase it until you find the right value this portion that says all for motor one and we are
defining an integer motor speed because we cannot change the value of the speed of a motor you
can permanently set some value here and the code either whatever value and percent so the 60 means
60 percent of the speed if you wanted full speed just make it hundred and some value in between if
you wish otherwise constant integer motor one push button direction this is a direction push button
I have defined an eight and then this is a stop push button defined the nine and because motors
needs some initial value passes modulation value to make it start moving so you can either set it
to zero or set it to certain value and direction of mother one we put some value do not change this
this will immediately will change when you push the button but we have some value when the program
works always this will be updated as CCW or CW and then the motor starts stop state this is holding
the push-button for the start and stop and this is also for initial value if you want the motor to be
stopped this high means stop and if you wanted the motor to run as soon as Arduino source then
set this to low this line we are creating from the class of from library we are creating an
object we call it murder and we pass this in one in two and enable a plan values to this class so
it can set it up and if you want the comment the debugging information for example if I open the
serial monitor these values are printed because we have here true if you remove this like that
the debugging information will not be displayed so you will initially will have it once everything
worked fine they move it and then because I will reduce some resources so to eliminate
that this is for the second motor which I will explain later inside the setup we initialize a
serial monitor with serial dot began with 115200 bought per second and this line means motor dot
begin we are using that object that began as a method of a function belong to this object and
it uses all those values and other parameters to set up the library with for the model and this
line pin mode we are using this line to define a motor one push button for the direction and also
for the stop to initialize a input pin for the input and here I've used input under school pull
up this pull up refers to setting the input pin as a pull up internally so you do need to use a
resistor otherwise you have to use a resistor if you use it like this of an input so I’ve separate
video explaining that the link will be below the video in the description inside the loop it state
1 this is updating the state of motor 1 for the push buttons and which I will explain in next and
here we check F model stop state if it is high just to evil mean compare this value with high
which means stop have been requested then murder dot break more than one some other one will break
else means every so model is running then we say model dot rotate and we pass three parameters you
see I've been separated to comma so we have three values the first value is more than one which
murdered and this motor one speed and murder one direction clockwise or counter clockwise and this
line is commented but if you want to check your mother's just uncomment this and then if you put
two motor to will be tested as you run one would our one will be tested with different parameters
clockwise counterclockwise with different speeds and this is another example in case if
you want to use it or needed and this is a delay push-button delay time that we have defined above
but the push-button never attempt the loop runs that this delay will give enough time for the
push button to be pressed or released and this is the end of the loop and it will continuously
just take the same action now update the state is a function that I say traffic I will explain
it now every time the loop lands first this will run and let's check what it does updated state is
a function that does not return anything it says void and we use digital read motor one push button
direction we read the push button and this is a value every time we push it is said the value
will be low and if you don't push it we because we use we used and put pull-up it is up or high
or five volts that's why when you push it will be low so we check if it is equal low which means the
push button is pressed now we have to toggle or change the direction and now here we check
F motor Direction is equal equal this means compared and see if it is CW then set modal
direction to CW see here we have one equal sign this is for comparing and this is for assigning
so this value is assigned to this and we also print this and every else means if it is not CW
then it is CCW now we change it we put CW to this value we change the value so this will change the
direction and then also in the same time we check the stop push button this value will check if it
is low which means stop have been requested or pushed start or stop this time we do differently
with let's say if the motor was in stop if it was low what we do is this value will be low so
one is high and low is 0 so 1 - 0 will be 1 so the value for this calculation will be 1 will
be stored here which means the value have been updated evidence was 1 let's say if this was 1
1 - 1 will be 0 and we just stole the 0 in the valuable and the start-stop value has changed
the for the demonstration of controlling single Moodle I will do the two murders together next
I've connected my battery here the power is on and also this USB is not connected I've
connected the power five volts from this module to this point and I will open the serial monitor
so you can see now I'm holding it so now it shows 60% CCW if I prefer it goes to CW I can stop it
now remember the for CCW if I press this the direction has already changed but if
I run it now you will see that it goes a CCW because death switch
des press button works regardless if this start and stop is running this
will change the status and then when you stop or start you will see their factory
now let me demonstrate to you controlling two motors I will
open the serial monitor as well so you can see it
right now it shows murder one motor tooth they are all braked so they are not moving
and now if I press this this is for controlling murder to stop and start
and this is clockwise counter clockwise and this is for murder one clockwise and
counter clockwise I will thrust this and hold the motor so they do not move
now this model is moving
and I can change the direction as you can see all that shows here
I can stop it and now let's go for this this is running it shows water one
and now the variation changed now they've turned this on as well both of these are now running at
CCW one is PW and one 850w my switch was not properly connected it's very loose but the
reason for the 60% speed is that I've set the speed here this is a speeded-up set you can
change it this is a 60% if you want your motor to run a hundred percent you can make it hundred
you
thank you for watching therefore how to use the l-29 8n module to control DC motor with
two push buttons if you liked this video and learned something please stamp up as this will
help my video in the search algorithm of YouTube if you have comment or question posted a comment
section below I try to answer and reply if you want to get updates of my upcoming videos
make sure to subscribe and I can change the direction as you can see all that shows here
now we're holding it so now it shows 60% CCW if I prefer it goes to seed