hi welcome to ESP32 tutorial from Robojax my name is Ahmad Shamshiri and presenting this tutorial
from Canada. in this video we are going to learn how we can control 2 DC motors using is p32 and
l2 98n module and heard about the demonstration it shows motor one goes at clockwise this is just
a test of Moodle 1 and have if the beneficiary of controlling 2 motors as you can see 2 motor break
you can get the code for this by clicking at the link below the video in the description which will
take you to Robojax.com/learn/arduino let's get started with this
controlling a DC motors controlling DC motors require h-bridge if you want to use a chip
something like this L 2 9 8 n this is a dual h-bridge module which means that with one each
bridge you can control fully DC Moodle and clockwise counter clockwise and also with
another H bridge you can control the second one so that's why this is a dual edged bridge and
when you want to control a DC motor using Arduino it's very straight forward much easier but a TSP
32 because we are able to change the frequency the bit rate and the selecting different channel for
the purpose each can be configured so it's not straightforward with EFE 32 and if the 32 have
a library for controlling the intensity of light of LEDs now I'm using the same library that I've
written for this forward winner now we are using it for the 32 to control the speed of this motor
in this tutorial separate video explaining full functionality features datasheet and specification
of this module you can use it easily with Arduino the link will be available below this video opera
video explaining how you can get started with the SP 32 and I have 2 videos a short video to be able
to get started the other is for details of this the link will be below this video this module and
l-29 it in module we connect one more this port is motor 1 this is connected to this point and the
motor to this wire is connected at this point we have three terminals here this is the positive you
will connect your external power these two wires are for external power you connect your power here
if your motor is 12 volts connector volts if it's sex during sexual and so forth up to 25 volts can
be connected here and this is a 5 volt regulator which outputs from this point if I volts at the
third terminal from here also can supply this 5-volt back to your yes bitterly - or any other
module that you have now in terms of power for a smart collar for other purpose that you have
you might have infill of one motor to motor on the left side and then to move out of here so
you would have four motors but the two other on the left side can be connected in parallel
so this is one motor you will connect another motor also at this point and also two motors
can be connected in parallel in here in terms of power this can handle two ampere continuously on
this channel and 2 ampere continuously on this channel so as your motors each consume
one ampere then you will be good because two of them will be too impaired on this side and two
on this side so and that that's one of the major question and concern of people who are using it
because if you don't know the power this module will die if you overload it with this heating
and if you replace it hissing with a larger one this can handle about 2.5A continuous current
let me explain the wiring we will connect motor 1 at this point the polarity doesn't matter because
it will rotate either clockwise or counter clockwise the other will be connected a second
motor will be connected to this point and you will connect yours correct your external power at these
two points this point from the ground you will connect one more wire to the ground to one of the
ground of ESB 32 because I have multiple ground this is one of the ground that I'm using and
once the programming is done once you disconnect USB from here from this 5 volts you can connect
the 5 volts to ESP32 V 5 to SP 32 V 5 or 5 volts 10 I've explained it in a separate video how to
use the 5 volts of this make sure to watch that the link is below this video for this module we
have enable a and input 1 input 2 these two are for the first smoother on that side and this is
input 3 input 4 and the last one is enable B this enable is where we feed their partial modulation
signal for the mother to and that's this possible modulation pin for murder one and I've used here I
won you sing all these pins in a sequence so you don't make in terms of wiring any mistake and I
started here from pin 1918 and 5 17 and 16 and enabled a is connected to pin 19 and then input
1 input 2 are connected to pin 18 and 5 and in for 3 & 4 are connected to 17 and 16 and enable
B is connected to 10 for at this point and as you can see they are all under arranged ideas
in order to start using ESP32 with Arduino ide you need to prepare Arduino ide for this purpose
you will copy and paste it here you see this package is the 32 index dot JSON at the end so
once you paste it here click OK click OK this is telling Arduino ide where to get the board
driver click on tools and then both boards board manager and here wait for this to complete at the
bottom this bar graph and then type here ESP32 you see ESP32 biased reserve systems this is
installed in your case it will not be insulted you will have install button here click on it
and it will take maybe few seconds or a minute and their solution was is completed click close
now we have to tell Arduino ide which board you're working with because the driver is ready click on
tool ports this is Arduino ide which you will usually work but scroll down and tell you see
a line below that all of these are SP 32 + SP 32 rover module is the one that you click and
select and the dot will appear now we have to select the port for that we have to find
out which pulls we are using right click on the Start menu device manager and you see port click
on this arrow to collapse it and mine is using comport silicon lab if I disconnect it now you
will see that it will disappear connecting it back so this has come sex note that click on tool port
and you will see conflicts is already selected and now you can write your program and run it
let me now explain the code I've written library for L298N this library is working with ESP32 and
Arduino I will provide you the link as a zip file you download it in your computer and save it as if
after that click on sketch include library go to add and Allsop library and then browse to where
you have saved it for example in your pc if it was saved inside download go and find it for example
if this was your zip file for that I've already selected and click open after that close Arduino
and you see I have two instances close them all and then reopen it the reason for that is that you
will be able to see the list after you close it because Arduino will not show it once you reopen
it click on file example and scroll down until you will see RobojaxESPL298N DC motor and I have
to sketch here what is DC single motor one is DC two models select this a single mother and open it
this is a file this line includes RobojaxESPL298N d c-- dot h this is part of the library which will
include the library and then we are defining channel for the pulse width modulation control
attached to the led c portion of ESP32 so we have to use one of the sixteen channels so we are using
only two channel hairs channel zero for motor one and then this trip answer for the module enable
a and one in two and I have defined discipline accordingly how they appear on the board so you
don't make mistake of course you can change it if you wish and then this CCW and CW are defined as
a constant variables and they are used inside the library do not change it and here we define motor
one and if you wanted some other word that's fine but make sure that the number one must refer to
mother one if you have robots robot let's say left arm or some portion of something put some word
here but this should be one and then the other one should be two and here we are creating an instance
of the class and we call it murder or you can call it robot and then we pass these values of that we
have defined here all of these four we pass in one in to enable a channel a and this true if
you want to see the debugging information if the true if here you will be able to see the debugging
information it shows the models the pin that Duty for debugging but you don't need it for the real
world application otherwise just delete that with a comma and then we have three four values
separated with three commas and then it will just when this runs you open serial monitor there will
not be anything so we create this object which is an instance of this class which we will use that
later on inside the code and inside the setup we have serial dot begin this is the baud rate
of the serial monitor when you click on tools' serial monitor the value that you see on the
right side lower corner is the one that is printed if you select this with the wrong value you will
not be able to see the text here either your C strange characters you really don't see anything
if he will see something like that so otherwise change it accordingly and then this one name you
put you must put it here with the dot begin this will initialize with those pins the leg ready for
the motor and then here motor door demo if you want to demonstrate and see all the functionality
of different test and comment this weight like that and then this will run demonstration widget
which is a bit available inside the library I'm not going to run it so here is how you can control
your mother's you type motor dot rotate and then motor one which you define defined above and then
this sixty means 60 percent of the speed and CW means clockwise and this will run the motor one
at sixty percent in clockwise direction for three seconds and then motor 1 dot brake motor dot break
one this motor one will break for two seconds so if you want motor to break just change this to 2
and here motor 1 rotate hundred clockwise and this is a loop that I changes from zero to 100 and here
we are changing the III 0 1 2 3 up to hundred so the motor will speed up slowly and in between we
give at hundred millisecond so the motor can move or slowly increase the speed so as simple as this
you can control the model with this code I have done a lot of different tests here and now if
we go to example and then open the two models this is the code I have defined for pin for motor 1 for
parameters which is tripping channel ears internal is it's not a pin and this is for motor to these
pins and then here we have defined in the for the second mother and here this time we are passing
and 1 as you can see in 1 and to enable 8 this is for one motor including the channel for parameters
and for hair for channel B and if you want the same thing for 1 for the second we talent and
put through at the end to read the values that and then here I've defined them I call it robot as you
can see robot dot begin and have robot dot rotate motor one with r2 and these speeds which I'm
going to demonstrate that next and the loop will continuously do the same thing over and over again
and heard about the demonstration issues murder one goes at clockwise
this is just a test of Moodle one now it's a hundred percent
and as you can see it slowly increases this motor will start rotating as 50%
and then at break also it shows a break and then
change the direction now it's a 60% that you can see and stopped
and here is a number it increases
I'll have if they're beneficial controlling two
motors as you can see two motor break one motor is now running
and as you can see this first motorists are rotating now motor one it shows air
motor one braked and then now motor to will speed up slowly until it reaches some threshold value
now both motels are running one is a clockwise the other counter clockwise and stop
so this was a cool - of demonstration of controlling two motors
I have the demonstration using it without USB and I will connect here my power supply and it
must be around seven falls in order to get 5 volts regulated for death so 7 wolf enters and
and then you will have five volts here and I've connected the five volts to the v5 of
this module a separate video explaining that so I'm not going to spend time on
that so this it says v5 and I'm connecting it at this pin and also the ground is also
connected to this pin this brown wire we connected the demonstration is now running
you
thank you for watching the tutorial from Robojax 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