HOW TO: Arduino control of DC, Stepper, and servo motors
HTML-код
- Опубликовано: 11 сен 2024
- How to arduino control various motors using L293D, L298N, a motor shield, or a MOSFET.
A basic explanation of how to control three of the main types of electric motors using various easy methods of control. Included are a variety of DC, servo, stepper motors including a drill motor. They are powered by various battery sources including a NiMH and a LIPO battery pack.
I don't go into much detail about the inner workings or theory, just what you need to know to make things move.
Very, very well done.
You answered my "what would happen if" questions throughout!
Thanks for your time-- excellent video!
Thank you thank you thank you, man some people can not teach a thing. But you on the other hand you have talent .
All of a sudden the lights are turning on in my head - this is a VERY nice tutorial - thanks.
Brilliant video. Very comprehensive.
excellent tutorial for beginners!!! thank you.
My problems with the transistors is that the step signals to motor generates hi frequency em noise, maybe giga hertz, that travels through the power line back to the controller board into the gyro. Lump capacitors, including tantalum packs, have cut off frequency below giga hertz, and their reactions to giga hertz noise is not defined in their spec. The helicopter crashes when the gyro is thrown out of operation by those noise.
Maybe that is why the commercial grade Electronic Speed Controllers sell. But I don't know what big secrets they have other than having the capacitors as surface mounts and smoothing out the step signals at the source.
Thanks for the video, found it very helpful
What would happen if I replace a stepper with a servo while using the stepper library ? would it work?
I pulled apart a couple old printers for stepper motors i found at goodwill and they all used dc motors except for one... What's great is its the same one you are using in your video although i can find a spec sheet for it because my has particular labeling. Do you happen to know the proper voltage and power rating for it? Thanks!
Thanks man, great job
I am interested in that last motor control you showed, can that be run off an arduino to run a large dc motor?
Dude im having trouble with the servo,when i upload the code, my comp gets crazy and starts to ignore my arduino uno,and then it recognice it again,the only thing the servo does its to get the initial position
nice video!
can u show me how to control two motors on each axis of a joystick? for ex: y axis forward and backward of motor a. and X axis forward and backward motor B, plz i rly need a code for this a help on making it for exo skeleton project
best video I've seen about motors and arduino but for my project the motor I want to use. Uses 7amps with out a load and up to 40 amps with a load but you where using the L298N with a pretty big motor for me the voltage is right but the amps are not would you happen to know what bridge driver I would use
how do we tell how many steps a stepper motor has?
Hello dear sir , thank you for your great tutorial! I want to ask about a switching mosfet. I have had a situation that I've needed to connect a resistor between logic to ground (2 pins of the transistor) because it didn't switched off when the logic were low ,I heard it involved with some "electrostatic dissipation" ?.. any way could you explain about that a little and most import tell when it happens and when not because it didnet happend with all my circuits ?
thank you in advance
You prolly dont give a shit but does any of you know a way to get back into an Instagram account??
I stupidly lost the password. I would appreciate any assistance you can offer me
@Christian Samir instablaster =)
@Jon Terrence thanks for your reply. I got to the site through google and I'm waiting for the hacking stuff now.
I see it takes quite some time so I will reply here later when my account password hopefully is recovered.
@Jon Terrence it worked and I now got access to my account again. I am so happy:D
Thank you so much you saved my account :D
@Christian Samir Glad I could help xD
Great video !! can i control a synchronous AC motor (48v) with this shield ?
do you have a code ? can I request the code itself
Another awesome vid especially for rookies like me. Thanks for sharing your valuable time with us. Question..can I have a Nano and the Uno R3 installed on one computer without any conflicts?
+Jorge Washington Thanks! Not a problem. They will simply show up as different oddly named ports. If you are especially unlucky on windows they will even periodically swap ports.
The simple "cure" for this is to just make sure that when you are sending code to the device to watch the TX/RX lights to make sure that it is going to the correct one.
There are ways to nail them down so they don't dance around if it becomes a problem.
+LessonStudio Got it. Thanks.
Hi. When you were using a Mosfet with the very first motor (DC) I didn' t see any diode protection against Inductive Spiking or Back EMF. How did you not damage your Fet or the Nano? Is it because you carefully looked at the Fet's datasheet and operating range? I hope you dont think its a stupid question. Just a newbie trying to learn? Thanks in advance.
+Jorge Washington Good catch. I think that I mentioned it that I had dumbed down that circuit quite a bit and left out the protective bits to keep it simple. You are correct that you minimally need a diode as motors just don't play well with many solid state bits.
As to how it survived is a combination of luck, only doing that for the short video, and that my experience is that electronics are perfectly robust until you must depend upon them. That is when your motor will fry something.
As for a careful examination of the specsheet, no that MOSFET was massive overkill as I was out of my favourite logic level MOSFETS (FQP30N06L) so it wasn't even a good choice.
I really thought about that issue if someone replicates my design and then suffers the nearly inevitable consequences. Then I thought that by keeping it simple and most people are probably using small motors, the video would be more valuable by showing it at its most elemental. The counter argument is a very easy, "Would one more diode have put that many people off?"
I shakily stand by my decision as in any time I work on something electronic or when I am programming something new in software, I love to break things down to their most basic; even more basic than would be sensible in a normal deployment. Then I build upon the basic until I have something robust and functional.
I also have another video where I recommend just using motor control modules. They really take care of all the hard bits such as not frying things.
+LessonStudio Thanks for the info. You are absolutely right imo of keeping it very simple especially for folks like me. I have a year of formal Electronics School (a long long time ago) but never worked in the field. Im just getting back to it as a hobby only since im pushing 60 y.o. lol and im using the Arduino for fun and motivation. BTW I was really impressed by the way that mosfet handled that drill motor and didn't even get hot. Once again I want to thank you for this fairly comprehensive tutorial/exposure on dc motors and for sharing your valuable time with me.
+Jorge Washington With things like MOSFETs my simple way of doing things is to over do the MOSFET as they are very cheap. Where I find they get hot with fairly reasonable loads is when you switch them on and off very quickly. I usually only pull the math out when I know that I am approaching the limits.
Using my IR thermometer, I check against my own rule of thumb which is to never let a MOSFET go over 100 degrees C. If it does, then I get more heat sinking, more airflow, rethink my circuit, or a bigger MOSFET. Yet MOSFETS can handle much more than that. Once in a blue moon I have to let it tough it out and climb closer to its theoretical limits.
Your long ago Electronics School would probably have been much more analog; that is a cool area that I have largely neglected. In fact with things like super cheap micro controllers I even tend to ignore great swaths of older style digital technology such as flip flops and whatnot. It is just so much easier for me to code great gobs of what otherwise would have to be circuitry.
+LessonStudio Good rule of thumbs that Im going to borrow from you. Yes it was mostly Analog with a brief course in Digital Electronics that covered the Flip Flops that you mention and things like Karnaugh Mapping etc etc. Outstanding course but its been so so long ago that I have forgotten most of it. So basically Im starting from scratch but it doesn't matter because Im having fun . Something to do after my retirement. Thanks to persons like you and RUclips its all coming back to me.
please use the correct mosfet pin names gate, drain and source, it helps beginner's
should do a video on controlling dc gear motors with a pot on it and control it like a servo, basically a DIY servo
+Frank Lopez Interestingly enough I have been working on a PID video. My goal with all these videos is to keep it as simple as possible so what you describe would very much fit with that. PID on the surface is very simple and complex just under the surface. What I am trying to figure out is how to pretty much hide the complex so that it just works.
The cool thing with PID when it goes wrong is that it acts like it is alive. Thus this might be my first video with outtakes.
LessonStudio actually IF your going to do a DIY servo video PID is NOT what you need to implement , what you need is a PD algorithm, you have a FB ? i got some videos on there that you might find interesting
+Frank Lopez Correct, I would probably go with an opamp based circuit for a DIY servo; but the PID part of the video would be all about feedback between motors and the things they move. So servos with pots, other digital encoders, and PID for wobbly balancing arm thing-a-ma-bobs.
Then this can lead into something like the classic balancing on two wheels thing where it gets its feedback from a gyro.
In the above video I show how a stepper motor can "lose" track of the steps if you force it to skip a step or more. Thus some kind of feedback is required for many motor operations.
One challenge that I was first doing the math on is to see if it is possible to balance a two wheeled thing using ultrasonic sensors as feedback. The question becomes if the PID math can handle the fairly poor data that comes out of a ultra sonic sensor. The idea is to show that movement data from a motor can be measured in a zillion different ways.
well i can tell you that i seen balancing bots using ultra sonic ping, but your right it does come down to code and threshold values and map functions imu always help asure any doubts by the system, but im not about thos little stupid bots im more on the humanoid life size androids and pd or pid controllers or algorithms using basic trig "cosines ....ect" to work out IK for walking and finger displacements
+Frank Lopez Cool. Two legged walking without big flat feet is something that I really want to take a crack at someday. That would be my foray into humanoid.
Am I right in thinking that a MOSFET is all ON or all OFF unlike a power transistor that can vary it's output?
John Michael Stock transistor and midget are both the same thing except that a midget is use for higher power applications while a transistor is used for smaller ones
Midget? WTF? LOLOL.. That hilarious auto correct issue aside, I thought MOSFETS were more binary in output? I've also got "Power Transistors" that go up to 400v and 35A same as MOSFETS?
Lol my bad lol yes my phone screen is cracked so I did not want to cut myself swiping lol
You are just looking at it as input output but when you use these passive components in a circuit really you change the game, you see you can use midget mainly because you are dealing with highly power systems where the Amps are up there and you can use it as a on off switch but using other passive components like a pot you can limit the flow of electrons, same goes for transistors except that you can use it just like a mosfet in the sense that use used life binary but add code to just make it go on and off, in a H bridge ic you can find they coffee made it off mosfet as well as transistor both n type and p type and sometimes you will also find h bridges that use both mosfet and transistor in a very unique setup giving you the best of both worlds so you see they are both the same, don't look at it as only binary or analogue it all depends on your setup.
Ok thanks. I'll look out for those binary midgets lol
Lol I'm dead lol
where to get servo motors
HI I have question about L298N heatsink getting hot.
I use 12Vol dc motor from drill, Arduio Mega2560 R3, L298N and expertPower 12v 7ah Rechargeable Sealed Lead Acid Battery and connect and code the same as you. I run it about 30 sec the heatsink L298N is getting very hot. can anyone please help me why?
+seyha seyha I put multimeter in series and the current is up to 3A. maybe is that what make the L298N is getting hot right? do anyone know what good dc driver will work?
+seyha seyha The L298N is rated for around 2A, so that it is surviving is lucky.
The question is do you need an H-Bridge to make the motor go both ways, or do you just need to make it turn one way?
+LessonStudio thanks for help I need it turn both way. I m making robot lawnmower. this is my first experiment. any idea for help please?
+seyha seyha If you google ebay for "5A H-bridge" pretty much any of the square shaped ones would be fine. They operate nearly identically to the L298N module in this video. If your limit is 3A then 5A should leave you some margin.
Thanks so much I found few H-Bridge that can take up to 10A on amazon. I will give it try again :)
What mosfet are you using? Thanks
+musicfuse In the video I used an IRF540N which is not a logic level MOSFET. The key problem with it not being logic level is that to really open it up requires something more like 10v. Normally I have a supply FQP30N06L
MOSFETs which are my goto logic level MOSFETs that can control quite a bit of power. 60V 32A with around 70Watts of dissipation.
So for a smaller motor like this the IRF540N is fine.
A few factoids: when a MOSFET has an L at the end it is usually an indication that it is logic level. And what I mean by logic level is that they will be happy with a gate voltage in the 3.3 -5V range. If you do what I did and put 5v into the IRF540N it really won't work as you push the amperage you are controlling too high.
Hi. Nice video!
What is the last controller called? The one who can take 50 amps or so.
It doesn't really have a name; it is just a generic mosfet based pwm motor controller. There are many like it.
hi, I'm new to the Arduino. do you use the analog or digital pins for the servo? strange that I cant get something so simple to work right away!
boowonder888 that would depend on your servo obvious really
is there any way I can contact you regarding a big project?
+Ee vert Yes, no problem. Just email me at donovan@ (the LS name above) .com
Sounds interesting.
model of this dc motor please
Hello, it's a great video. I am totally new to Arduino, i just saw a couple of videos, I am amazed!
Now I have a small project, requesting your help. I want to run a DC Motor with Arduino, I would like to set a spesific speed to run at a spesific amount of time. (Ex Run motor at 300 RPM for 3 minutes, 700 RPM for the next 5 minutes) The motor is 24V 13 amps. I would like to make a couple of programmes like this that i want to switch between with buttons and start it. What do I need for this project except motor and power supply? I would very much appreciate your help!
Murat çakır what you just explain it's called pseudo coding, and it sounds to me like you actually know what you want so your question seen redundant, what you are actually allying for is for someone to do your work. You might want to try scratch ide for Arduino since it sounds like you need to brush up on your programming skills
Hello Jai, I never asked someone to do my work. If you read again, you will see that I am asking about the equipment, not the code.
i did read your comment and okay maybe i got off the wrong foot with the whole code but like i said your Q is vague i mean you asked this a month ago or so so im just giving it a crack really for no reason other then to narrow down the help, figure this guy is busy so i figure ill help him by helping out some of his viewers we all here to learn from one another and all i got from your comment is that you know what you want so im not sure what are you really asking for? you just named off everything in your setup from buttons to power supply volt and amps so you might want to clarify your Q a bit man i be glad to help anyone but you gotta be clear
Hi! How can I use arduino to control a solenoid valve? It would be a great help. Thanks! :) great video!
Raheemah Gomez la mima forma que el use el motor dc no hay diferencia
Use original Arduino people! The money goes to the good purpose of open-hardware.
+mrMirzam The Uno in the video is Italian made. The Nanos are not. I use Nanos where disposable is the key.
Good info poor presentation. Review your video production techniques. I can't see the Arduino code, but get a great view of your desktop. Get a copy of Camtasia Studio and make a real vid!
+Harrzack Bump your resolution up to HD and the text is crisp as can be. Also when the code is more complex than this I usually put it all up on Github.