Это видео недоступно.
Сожалеем об этом.
HOW TO: control DC Motors with Arduino + L298N
HTML-код
- Опубликовано: 6 дек 2014
- This quickly explains how to connect a DC motor to an Arduino using a L298N module. I keep it as simple an explanation as possible.
I have the feeling that you are a very nice person, just from listening to your language and tone :)
+Jan That is the coolest complement I have received; thank you for that!
Does this work with a 9v battery? Because mine doesn't want to work. Am I using too low voltage? I am trying to make a 3v dvd motor run. If I can get that working, I can build my ev longboard
Sound like Takumi from Initial explaining his techniques. Quite lovely to ear
+boowonder888 motors draw quite a bit of current. assuming your motor is OK and properly connected it might be a regular 9v battery is not enough. have you tried with a external power supply?
No because I'm afraid I will fry the Arduino or the ln28. hardky touched it since..... Also I need a good sketch!
this was so incredibly helpful.
I'm a super beginner and you explain things very plainly.
thank you hahah
You can use this circuit as well, this is a powerful 30A design: ruclips.net/video/9UVxvpHyqMI/видео.html
"super beginer" nice term , lol
Great, the only video quick, and straight to the point, showing change in direction
I fried a couple of L293's so I upgraded to L298 and you took all the mystery out of it. Thanks for sharing.
Perfect. Learned in 10 minutes what I've been trying to figure out all week(plus I smoked one L298n). Thanks.
the best tutorial on the youtube for these electronic items.. The best teacher.Thanks! Keep it up!
Thanks. I misunderstood a comment in amazon Q&A on how to run this controller. Your video explains this perfectly. Thanks!
With a stepper you will be using digital 4 wires per motor(assuming a 4 wire stepper) so an uno could control 3 and a mega could control 13.
But for that many motors there are other options depending upon the size of your motor. There is a A4988 module which only uses 2 pins for each motor. One is for direction and one for steps. These boards can also do 1/6th microsteps so very nice feature there.
The A4988 is pretty much equally rated capacity-wise if you put a little heatsink on it along with paying attention to cooling.
So with the A4988 you would halve the wires used and in theory double the number of motors under control.
I'm testing this module which I bought last week...its unable to turn even the smallest motor (thumb size)...it just changes its hum. I don't know...Solution it needs a 12 volt power supply and a 5 volt at the same time.
Hello at the 8:33 minute of the video that "analogwrite (9,50);" Where did that nine come from? I'm new to arduino!
A bit late now, but 9 is the pin you are addressing.
I just watched your video again. Definitely worth while. Very imformative. Im a newbie at this. I'm so so with Electronics..I know the basics but programming and the Arduino are totally new to me. Im going to visit your website to get the details. Thanks for sharing your time and knowledge.
This is very helpful and makes everything so simple thank you so much!
the code:
void setup() {
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
analogWrite(9, 80);
delay(1000);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
analogWrite(9, 80);
delay(1000);
}
Thank you very much for this video..nice explanation! I would like to ask you: why do we need to connect the common ground from the L298N to Arduino GRD pin since you are powering arduino with USB? I tried it with no common ground and the motor doesn't work...why? This would really help me to clear a few things in my mind..
This video was well made and very helpful to my project. Thanks!
Josh Tomada No problem. Suggest further videos if you are stuck somewhere.
I always fold the exposed metal over the cable and clamp them both in. Then I don't need to worry about it coming loose later because it's not gripping that very thin cable.
Absolutely wonderful video. I will make a longer commend when I'm done with my project
Theoretically you could also use 4 PWM pins, instead of 4 Digital 2 PWM.
one of the better videos good work brother it was a big help.
simple necessary explanations
+William Williams Thank you. When I am looking for things like this, I would rather simple to get started learning, than complex and comprehensive. Comprehensive can come later.
Well done. Thanks. One on the way to drive my actuator for sailboat autopilot. Solves problem of reversing relay and power transistor
being straightforward ,I liked this one..
There is a quite big voltage drop trough the circuit so I recommend to use 15 v on input to get 12 on output
very good explanation , clear voice , nice graphic quality ! thank you for all of that ! :)
can you just explain more the idea about the capacitor , i'm trying to make a 12 V motor work on Low RPM ...
thank you again :)
Dear great teacher, I really need a help from you,I'm trying to figure out if it's possible to make some servo motors by using some Rotary encoders from an old ball mouse or from an old printer and a car wiper motor to use in a cnc project. I've seen homefaciens doing it but i really really don't understand a thing he is saying. Due to your charisma of explaining everything so well I beg you to help me in this matter.
I like the simple way that you explain this, May I ask you, I have seen lots of people feeding the power output of a motor "Out of a cheap servo.. on to the H-Bridge.. so my question is, Can one feed the signal directly out of the receiver on to the H-Bridge and bypass the servo pc board?
your website is a work of art sir! thank you for the tutorials. Safe journeys
Too clear to be true 😎Thank you dear man.
Excellent example. Thank you for your time and effort.
Thank you very much bro! Your videos are great and very clean, thank you for sharing.
I have a question. What is the formula or method to determine the capacitor to smooth the modulation as you said at the end of the video?
Thankkk youuuu!
This was sooo helpful for me awesome work.
Very nice tutoring !! Exactly what I was looking for. Thank you.
Amazing demonstration. Very detailed. Have you stopped making videos?
Great video thanks... nicely paced, clear, understandable, just what I needed. While I was watching it the courier delivered two L298N modules I was waiting for! Guess why I was watching!! :o)
This was incredibly helpful, thank you! I am building a robot with my son. I know software pretty well, but this hardware stuff is not my forte.
Thanks for nice video. I would like to see the schematic for L298N explained.
Great video! Thank you for making this.
samastersr You are welcome!
Thanks you for such a nice video. If you had some time to spare I'd like to ask: How would I design a controller that does the following to a 2.5 to 3 rpm D.C. Motor, 4W, 11V: run clockwise for 2 minutes, pause for 2 minutes, run counter clock wise for 2 minute, pause and repeat. The other modes of operation would be clockwise only - as in, 2 minutes rotate clockwise, pause 2 minutes, repeat. Same thing for the counterclockwise scenario. Thanks in advance!
Great video thanks,
How fast can this circuit switch from forward to reverse if the load is just resistive?
Awesome tutorial. Totally understood. Thank you. How can I revise the code if I want to control the dc motor for only 3 seconds forward as I supply the required voltage and as soon as I stop supplying that voltage, this time 3 seconds reverse? Just like a park assist of a side mirror of a car. With reverse gear side mirros will move down for 3 seconds and with forward gear it will move back 3 seconds to its starting position. Maybe the scenario might be enriched.
This video is very enlightening, thank you very much!
Thank you so much for the tutorial. Really helped me a lot.
Great video. Simple to follow, and a big help as the L298N I bought did not come with any pin out info. Question though. How do I figure out the capacitor value needed to smooth out the PW at lower speeds?
Thank you,
+kb3cxe There are formulas for doing this but personally I do it by guess and by golly. I will eyeball the motor and think about the voltages coming out. Then I will eyeball the capacitors and their capacitance and their voltage ratings. Then I will start moving down through the capacitances until I have the smallest one that will work.
Where I usually have this (and it makes the formula just that much harder) is when sending a PWM signal to a motor. At slower speeds the PWM often won't keep the motor moving and/or makes it whine. A capacitor is then not only to keep it moving smoothly but to make that annoying whine go away.
For perfection you could connect an oscilloscope up to the motor leads to see how your capacitor is smoothing things and to theoretically measure how much smoothing is needed.
The key is that while I love math this is somewhere that you quickly build up experience at being able to pick the nearly perfect capacitor every time.
That all said, I primarily work with pretty tiny motors. If I were doing this for a huge motors (5-10Amps or more) then I would get out the math first as this would be where mistakes could be costly and dangerous.
+LessonStudio jfiexnhss ju
Thankz a lot man this was very helpful! cheers.
Nice 👍. Can you make a video for larger motors pl ?! I mean of the motors with stepper or servo with drives . Thx for this video 🙏
Thank you so much! Here with a new robot project for beginners, so it helped a lot! Just wondering how to do it with the arduino not connected to the PC. Thank's!
+Albert Borràs Pons Sorry for the delay. I suspect you figured this one out. There are a huge variety of ways to get power to the arduino once you have programmed it but one of the easiest is to buy a 5v USB battery pack and just plug the Arduino into that. One of those tiny cigarette lighter sized packs will power an arduino for pretty much forever.
If you are using this LN298N then you can tap the 5v and the GND on this module to run into the VIN and GND to send power to the arduino. This module is excellent for robotics projects.
thanks for upload this video. it very help me to do my assignment. thanks very much sir !!!!
Hi can you help explain how I would go about choosing the capacitor mentioned at the end of the video to smooth out the PWM voltage? I am trying to make my DC motor operate at a very low RPM, but when I decrease the pulse width, it whines and wont turn (as shown in your video).
I'd like to see the math on this as well!
I have not done this but I can put you near the answer. RC = Time in seconds. Therefore C = T/R where R is in ohms and C is in Farads, not microfarads. Plug in the time length of the ON pulse width and probably divide that by 2 or 3 so as to not flatten the entire width, and calculate R to be the voltage divided by the current drain through the motor. That R=volts/amps is not actually the DC resistance because motors are inductive, not resistors, but also measure the DC resistance of the winding anyway to approximate R in a second way and see if those two Rs are close. That will give you a starting idea of farads (example: 0.1s/2 divided by 50 ohms = 0.001 farads = 1000mF). You see capacitor size depends on how much current the motor draws and the pulse width; the smaller motor and smaller pulse width means the smaller the capacitor. I would experiment with values around that kind of calculation. To be more precise maybe you can measure inductance of your motor winding and plug that in for R using a reactance and frequency equation. But I think instead do this by experimentation after you get close with the easier estimate. You need diodes to flatten the flyback current of a motor; L298N spec sheet shows them. What about the polarity of a capacitor? AC capacitor, not DC electrolytic.
brother, youve helped me so much! thank you
You could have used the 5v pin/GND on the arduino to power it.
hello, that was a great help, but when i tried the motor didn't turn because there was 0 volt coming from out3 can you tell me why ?
thank u!!!! i got a geared wheel motor and 9 v battery to turn with this code! thank you :)
REALLY REALLY HELPFUL VIDEO BUDDY THNX SOO MUCH UR REALLY GUD :)
+#simplyInvent Thanks
Thanks for making this helpful tutorial. I got one question; what is the point of having a common ground with the arduino since the arduino has its own power supply from the USB?
+brusk qadir A common ground is generally how electronic work. The main occasion where you isolate things is when those things might be naughty and feed current back through the ground. This common ground is so standard that you will find many circuit diagrams that don't actually show the entirety of the wiring style circuit but every time something goes to the common ground there will be a line terminating at the GND symbol even though all of those grounds are actually connected.
Check out many circuit boards. They will do all kinds of things such as a ground plane and whatnot where the ground sort of makes up a huge proportion of the board's copper. When looking at a circuit board that is usually the giveaway that you are looking at the ground, it connects to pretty much everything.
Nice and simple. Thanks.
Thanks
this simple code helped me a lot
Nice vid very informative. Just one question though, how do you stop the motor from turning and hold its position?
+3D Printwiz With a DC motor, holding position is tricky. With a servo motor is is very easy, and with a stepper mostly easier. The key is that if you are putting power into a DC motor it will usually move. Thus to hold it in position would require that you are only putting enough power into the motor to prevent it from being forced in a different direction or to rapidly move it back to the desired position so rapidly that it appears still. Thus the first step is to identify that your motor is being moved. The easiest (but not only way) would be some kind of sensor that detects either movement or position of the DC motor. So effectively what you would end up doing is creating some kind of feedback to compensate for the movement of the motor. What you would be doing is to recreating a servo motor; which is a DC motor with a sensor and positional feedback.
Thus the answer is probably to use a servo motor. There are servo motors that can rotate 360 degrees although most commodity servos are limited to around 180 degrees of motion.
Awesome Tutorial.
Was wondering tho, what if I wanted to run 4 Dcs ( So 2 H Bridge blocks there ).
Would Those 4 Batt. be enough? or would I have to have a second Batt-pack? And how would I wire it if it was just one Batt-Pack?
I know this tutorial was done in 2014 but I hope that someone might be able to help me with those questions.
Thanks alot in advance!
-Basil
Great video! I have a question. Can you use pwm on two motors connected to the L298N simultaneously. Could i have one motor doing it's thing and another doing it's thing, or will they both rely on the same pwm?
Very nice video. could you explain how to add trigger and countdown timer in this dc motor controller. I want to make a motor work by trigger (water level sensor) and will be stop after lets say 10 second. Can we only add some code? thanks
thank you sir, i find it very useful. i can understand the concept, im still new with these stuffs. you explained this well
but sir, for the codes, why did you use "analogwrite" meanwhile its in digital pin? i still cant get it
0:00 it says that the lesson is going to end at less than 10 mins. but the length is itself 10 mins 57 secs.
Thanks for the beautiful explanation in video. could you make a video with a bipolar stepper motor to 4 son please
Now Controll anything in adrunio via keyboard{makeAnyprojects}
ruclips.net/video/jAHLtRmgRiI/видео.html
What is the advantage of using this board over just a bare H-bridge, other than the voltage regulator? And what is the advantage of any H-bridge design over a simple transistor to control motor speed (if you don't need to run in reverse)?
Jonathan Tucker A bare h-bridge is superior in cost and size if you know what you are doing. The key advantages of this board is that it is close to brain-dead easy to use. First it mostly protects your L298N so that the spikes from the motors don't easily come back to burn it out. Also having the screw posts means that you don't have to solder this into any temporary projects. So in a typical circuit you would have to use nearly every component in the module, the capacitors, the heatsink, etc. Here it is in on package. Also you can hive off 5V for use in powering things like the arduino, which is convenient in that you don't need a separate power conversion circuit.
But for a permanent project this might be clunky to glue in. My assumption is that most people are doing what I do with Arduino which is to build something cool admire our handywork, then cannibalize it to make the next project. Or we are hacking something together where tidy custom circuits aren't the rule of the day, more hotglue and ducttape.
Also in many of my robots I tend to physically separate power and motors from thinking and controlling. So I put my motors, this module, batteries, at the back and the sensors, arduino/raspberry pi, at the front. Thus I am sort of happy to have a separate module.
Where I have used fairly naked H-Bridges is when the power demands are very low and the motors fairly weak, then something as simple as a diode and a capacitor should protect the IC. This unit is fairly robust and thus can handle a good load.
And thank you very much for watching my video. I have another batch in production so if you have any requests.
Thank you so much for the video! It clearly explains what the L298N module does. Could I quickly ask, what is the benefit you get over using this L298N module as oppose to just using a L298 chip and wiring everything manually? Does this module simply offer convenience or is there something more? Again, thanks for being so informative and clear! Regards.
the ln298n controls higher current/voltage. you shouldnt be able to ffeed 12v into the motor directly from arduino with higher current. So this module is required.
Now Controll anything in adrunio via keyboard{makeAnyprojects}
ruclips.net/video/jAHLtRmgRiI/видео.html
Very nice video..helped me a lot! Thank you very much!
+jdiephaus Glad to help. Feel free to suggest any future videos.
thank u sir...it has helped me a lot
Hello, do I need to use all pins if I only want the motor to spin in one direction?
actually it's 7v-35v not 7 to 12, but I wouldn't recomend to use full 35v 24v is fine for larger motors
+Rokas Raulinaitis I have never understood why so many of theses say 12v not 35v.
+LessonStudio maybe its developers miatake. :). btw i love your videos. keep them flowing
+Rokas Raulinaitis I have a few in the pipe right now. Thanks!
hi ,gud explaination.can b use for a drone.i have been using a l293d ic but cant get enough power..
Awesome video bro! Thank you!
Hi, thank you so much for the tutorial, it really clears things up in terms of what goes where on a motor controler. Just one question, since the L298N can be powered by a 12 volt power supply can it have an output voltage of 12 volts right to a motor or is there a limited voltage it can output. Sorry if the answer is really obvious I'm new to the whole motor control and arduino world.
+TangoBravoCheesecake It can actually take in about 35v at two amps per motor.
But those numbers are the theoretical maximum. Generally you don't want to run right up against the maximum. With motors I like to stay as low as 50% of rated maximum and start getting uncomfortable if it is going to sustain anything over 80% of rated maximum.
Also there are slight losses which you can check the charts for but experimentation is usually easier. These losses mean that if you put in 15 volts that you won't quite get 15volts going to the motor; maybe 13.5? The same goes with the part that can feed back 5volts to your arduino. If you don't put in around at least 7 volts into the controller then it can't put 5volts back out.
I have never tried it but I suspect at very low voltages much below 5volts that the L298N would just not work properly.
At those low voltages there are alternatives that would probably be cheaper and work better.
If you need to go beyond the specs of this module there are other modules that pretty much work identically yet can handle far larger loads. For about $10 you can start to crack 50 amps.
The key to this module is that it generally can control most motors that people are using for homebrew robotics type projects and is really cheap for what you get.
Good luck.
Can you do a video where you can control two motors using the same parts you have currently used
Can I connect four dc motors if I want them to spin only forwards? and one at the time. I mean each OUT from the driver to one wire of the motor, and just wiring all the gnd's together.
Hey dear I love this video so much. But you have to make one more video for me, please. control DC Motors with Arduino + L298N+ Airplane controller like receiver-transmitter .....How can add? I have fs t6 2 gigahertz radio transmitter
thanks for the video but i have a problem my motors run without the the l298n driver but i connect them to the driver they don't rub anymore and yet my code is very ok what could be the problem
hi buddy awesome work on the video
Great video, how can i put a joystick for speed control?
Where should I place the capacitor? I have two dc motors .. should it by o the line from H bridge to the motor? One capacitor for each motor?
can i supply the module with 9v battery? for the DC motor to have a good speed on rotation?
+dan bon marañon The answer is: Sort of. A 9v battery won't put out much amperage. So unless the motor is very small it will be pretty disappointing. This is why most motor driven devices have a bunch of AA, or bigger, batteries which can put out more current. Also the mah available from a 9v is also pretty disappointing which is why you don't see them in things that really put some strain on a battery such as a flashlight.
For most projects what I like to do is to put a battery pack in with a handful of batteries. You can buy various sized battery packs from ebay that will allow you to put 4 AA batteries into a project in a nice compact way. I think they cost around a buck.
There is a library available for the L298N but i wonder what it really does?
If you could show us how to run the motor in very low speed using capacitor.
How do you calculate the proper-size capacitor to attach to the circuit to allow the motor to run at small PWM signals?
My motor driver l298n is burning when connecting 12v 1.3 ah lead acid battery directly..! How to fix? Will using a mt3608 dc dc step up will work? So that I can reduce the current from battery.! Please help.!
Do you know is it possible to control not speed but position (angle) with this driver from arduino? Lets say i would like to turn 10 degrees from current position clock wise or 15 counter clock wise? If so, could you do the demo please?
Thanks
The capacitor you mentioned to be used for very low rpms, where does it go? in between the motor terminals?
I have 2 motors coming out of each set of outputs of the chip (4 motors total). One side doesn't seem to accelerate as quickly as the other using the PWM. One side of the vehicle starts at the correct speed while the other side takes a while to get up to that speed. Do you know what could be causing this issue?
I connected 4 1.5v battery to motor module to control a 6v motor. When I test the power supply, it shows 5V. but when I connect to the module and checked the supply across the pins 4 and 5, it shows only 1.18V. I don't understand why this happens.
But how to control the brushless motor with L298N?.... I need to make a forward and reverse rotation of motor's rotor, please help me!(
Help, how can I synchronise two dc motors.
I am building a biped and each leg is a windscreen motor, I want to make sure the left motor does not get out of step position with the right leg.
Any ideas gratefully received.
Can we apply in this same model of connections a PID controller, changing just the code?
Can you address, this issue that usually you need some sensing to start the motor in a specific direction (I am thinking of the 3 phase coil setups in for example ex electric bikes, aka "push to start when you do not have the hall sensors). Any comment on this ?, thanks in advance
Can you just tell me that if I have a receiver, a transmitter, a L298P motor driver and an Arduino Uno and the L289P is connected to the Arduino Uno, can I connect the L298P to the reciever so that my robot works like a rc robot?
I want to connect L293D by wire to the arduino without mounting top of the arduino... how can i do this... plz plz plz give answer...
Hi there,
Great video!!! Very simple. Can you please explain how can i use the L298N to supply the arduino, using 12v on L298N? Also, i want to connect a water pump (12v), do i need to configure the speed, or if i don't write nothing on code, it assumes full speed as default?
What are the difference btw L198N and L293D?
+João Ferreira i had the same question also, whats the difference bet. L198N and L293D,. i just also want to supply the module of 9v battery to make it more fast on rotation. is it posible?
+dan bon marañon The L298N is tougher and can handle about 2A per motor, while the L293D can only handle around 600ma. Otherwise they are very similar for most purposes.
+João Ferreira The L298N is tougher and can handle about 2A per motor, while the L293D can only handle around 600ma. Otherwise they are very similar for most purposes.
Once the 12v power source is connected to the L298N module you can get 5v for the Arduino. Do do this you connect the VIN on an arduino to the 5v on the L298N module. Then you connect GND on the module to the GND on the Arduino and then it will power up.
Just make sure not to connect the 12v+ source directly to the Arduino and only to the 12v positive in.
+LessonStudio Thanks! ;)
thank you so much for the answer.. I bought a L298N motor driver yesterday.. i have both L298N and L293D tnx so much
Would this work with any other motor controller? Specifically a roboclaw?
what is the name of the wire you used to connect to ENB? Please let me know as soon as you can! I have a deadline next week. Thank you
Hello,
for a line follower robot with 02 infrared sensors and 04 DC motors
connected in L298N driver, how many amperes I need to robo do the curves correctly?
Now Controll anything in adrunio via keyboard{makeAnyprojects}
ruclips.net/video/jAHLtRmgRiI/видео.html
hi Im using this driver to control cd rom microstepper motor with arduino. motor indicates 4-9v and 500mA current. Even though the code works correctly and motor is functioning, motor is heating very much in few seconds. can you tell me what could be the reason?
thanks a lot, great explanation!
Thanks Buddy for help.
I have a question how to use mq 9 sensor detect the gas,then the dc motor moves. Do you know how to coding like that? Pls Help Me
Hello sir. I want to controlled on speed and direction of a more then 12 volts and 5 ampers D.C motor using arduino. this L298N cannot hundle this amount of volts and current .what do you thing should I do? thank you very much