A tutorial on using the Arduino to control devices such as motors using PWM or pulse width modulation.
Пікірлер: 220
@Fredster99848 жыл бұрын
I want to thank you for putting together a excellent example of how to use the MOSFET. I really like the clear instructions and the way you step through these simple circuits. I'm using this to help get the kids interested in electronics, and you do a great job of explaining the steps, and the reason for the steps.
@plaije9 жыл бұрын
And suddenly it works. Thank you Dorian for including enough information to pull me all the way through a tutorial with results. This video is a great help.
@DorianMcIntire9 жыл бұрын
j. plaiss I'm glad you had a happy ending. Electronics can be very frustrating at times for both the student and instructor. It can be very difficult to help people at a distance when things don't go quite right.
@TheBmboone4 жыл бұрын
"I wonder if I can use a MOSFET and PWM to modulate the speed of a motor" I no longer wonder! What a great video, especially for 2014. Thanks! (The kids I've promised robots to will thank you!)
@Reflections20137 жыл бұрын
Thanks again Dorian for another great video. I also do allot with spreadsheets, and logic programming with IF statements - The Mosfet is actually starting to sound like a physical IF statement the more I learn about them. Unless you have done any work with spreadsheets or databases, you probably wouldn't know what I mean by saying that, but like I say, the more I learn about Mosfet's, the more they appear to be a big IF statement in a circuit board... Source - Gate - Drain or IF - THEN - ELSE. When I think of it that way, the possibilities go on and on, because you could actually use multiple Mosfet's to create (in a since) nested IF statements to create something much more complex (if that made any since at all). Steven
@nreh08 жыл бұрын
thanks! i was confused and all the other videos didn't explain step by step. But you cleared up the confusion and helped me make my first transistor motor!
@krzysztofkwiecien42457 жыл бұрын
Thank you, I'm starting out with electronics and this was really helpful, I was looking for a PWM motor controller that is easy to build and doesn't require too many components, finally got to understand what a common ground is, very good video.
@DorianMcIntire7 жыл бұрын
You are very welcome. Hope you enjoy electronics as much as I do.
@dbright0386 жыл бұрын
Dorian, this tutorial was amazing. I looked far and wide for someone to explain (step by step) how to use the Arduinio to power a high voltage item (like this). The mosfet was a little tricky to find. Had to drive 30 minutes to find it but it was worth it. Worked like a charm! Thank you. Thank you. You saved a girl's school project invention. If you've gotta PayPal, I will donate to your efforts.
@DorianMcIntire6 жыл бұрын
Always happy to hear stories like this - especially about future engineers and inventors. Thank you for your comment. I do have a Paypal account for the channel and every little bit helps. My Paypal id is dorianmc@gmail.com. Thanks.
@dbright0386 жыл бұрын
Thanks again. Do you have any demonstrations of lighting up different colored LED lights using an Arduino?
@DorianMcIntire6 жыл бұрын
Check out the following link. arduinostem.blogspot.com/ and click on "Knight Rider (Using Array)" This is a blogger site I created for projects that I share. You can use any color LEDs you like to create the "Knight-Rider" effect with the LEDs and you can change the speed by changing the delay numbers. Simply connect the components as shown on the breadboard and copy and paste the code into your Arduino. There are many different projects to choose from. Let me know what you think.
@DorianMcIntire6 жыл бұрын
Make sure you use the Chrome browser to avoid any problems with the code copy.
@dbright0386 жыл бұрын
Thanks for the link. Here is the project if you're interested. kzbin.info/www/bejne/naLbnYSVfNFoaLM
@djjjozsi4 жыл бұрын
worked like a charm :) I tried many great tutorials without a success. Thank you very much!
@Frank_The_Tank225 жыл бұрын
Great step by step video, you're a time saving badass thanks for the video, cheers!
@eriklaken10256 жыл бұрын
Thank you, and a diode is important but this shows a basic process, very good.Thank you Again.
@givenfirstnamefamilyfirstn39354 жыл бұрын
Your response to comments is wonderful, you are so helpful and generous with your time. Subscribed after my first viewing. Don’t reply!
@junding59485 жыл бұрын
Never write code completely from scatch! I strongly agree with your opinion Not only for coding,the same with designing electrical drawings & mechenical drawings Cause we are applying the technolodgy,neither reserching nor establishing general Rules
@colinmj.jalbert54367 жыл бұрын
Thanks man, you really helped me out, by far the best video ive found on this subject
@j3s0n4 жыл бұрын
A really well made tutorial! I liked how you explained every step.
@DorianMcIntire4 жыл бұрын
Glad it was helpful!
@yoursinger40148 жыл бұрын
Best video in youtube regarding motor control...it was extremely helpful for me! Thanks Dude...Thanks a lot :D
@mazdalorean10 жыл бұрын
Good stuff. I think my biggest problem with trying to keep up with the video is I don't know what the abbreviations stand for . I don't have too much of a background in electronics , but still try to follow. Thanks for sharing.
@DorianMcIntire10 жыл бұрын
Glad you liked it. I originally made this video as a set of instructions for my students and I didn't do any editing like I usually do. I'll insert some annotations to explain some of the terms and ideas in the video for future viewers Thanks for commenting..
@saavedra3588 жыл бұрын
Very nice, good explanation, is there a way to incorporate time? To have the motor spin for 10 seconds and then shut off?
@wellyntongbreton82279 жыл бұрын
Great!, Dorian........ Thank you man!.... Most of other videos are either too fast, or explained using terms nobody understands.... So I appreciated this one very much. I subscribed to your channel since I think it may help me a lot with my arduino projects. :-)
@DorianMcIntire9 жыл бұрын
Wellyntong Breton You're welcome. Glad you enjoy the videos. Thanks for commenting.
@kayaonur56574 жыл бұрын
I think you can also use the analogue signal and change gate-to-source voltage of the mosfet thus control the current
@DorianMcIntire4 жыл бұрын
Arduino Uno analog outputs actually only provide a PWM signal and cannot provide a true analog output. Additionally PWM is the most efficient way drive a motor since the MOSFET is either on or off. In a perfect situation the MOSFET would not dissipate any power itself and would only provide variable power to the motor.
@KaelinatorPVP6 жыл бұрын
Oh my goodness! I actually understood!! Thank you!
@DorianMcIntire6 жыл бұрын
Great! Thanks for commenting.
@keetor139 жыл бұрын
Great videos. I've been binge watching your stuff. A big help. Thanks for the effort you put forth to make these.
@DorianMcIntire9 жыл бұрын
Zachary Keeton Thanks. It's great to know these videos are making a difference. Comments like yours really make it worthwhile.
@keetor139 жыл бұрын
Dorian McIntire Yes a big difference. I had stalled in my electronics self-education until now, thanks to your lessons. The main huge helps from your videos were 1) the electron visualization in the circuit construction kit software (was forever banging my head against understanding how current behaves with a capacitor in parallel. Was using Yenka, but CCK was more helpful here). 2) Interfacing Arduino with larger circuits using MOSFET (opens up a whole new world). 3) Your great explanations/presentation - adding the onscreen arrows, graphics, etc. and 4) Your great demonstration of circuit analyses. THANKS A MILLION... re-invigorated me to whip out the bread boards again.
@DorianMcIntire9 жыл бұрын
Zachary Keeton Great! This kind of feedback really helps me develop new and better ways to deliver material. I really wish more viewers would provide such feedback, positive or negative, to help keep me on track. Thanks.
@syahrul92826 жыл бұрын
Thanks so much... was actually need to connect both ground to the same arduino ground... btw i was using one power source... but it seems like there were a problem... when i power up the motor the arduino was fading out... so thats why ur using two sources
@DorianMcIntire6 жыл бұрын
Yes the Arduino is incapable of running any loads that require more than about 20 ma so a separate power supply is needed. It also provide a level of protection to prevent voltage spikes from entering the Arduino.
@pedrofer6 жыл бұрын
thank you for this simple but precise and detail how to setup nmosfet ill using this way to hook a laser in a cnc machine
@mirosawh.16008 жыл бұрын
It is very nice and simple tutorial. Thanks Dorian.
@handang91658 жыл бұрын
Your video is tremendously helpful. Thank you!
@jfredricks23947 жыл бұрын
You sound like John Goodman!!!! Long live Monsters Inc!!!! Love your videos!!!
@DorianMcIntire7 жыл бұрын
Thanks on both counts really appreciate your comment.
@garymaya17674 жыл бұрын
You need a diode across the motor to take car of the back emf. You can map the pwm and adc.
@DorianMcIntire4 жыл бұрын
I'm very familiar with inductor back EMF but a flyback diode has never been necessary for any DC motor circuits I've controlled and sometimes modifies the behavior of the motor in a negative way. A diode is necessary and recommended mainly when driving relays or other pure inductor devices.
@CuddleStories4 жыл бұрын
Instead of the battery, couldn't you have some capacitors in series to create higher voltage? Then the transistor would amplify the current to the motor too. This way you could avoid an external power source.
@hamilton1857 жыл бұрын
Genius! You saved my job!
@SilverMiraii7 жыл бұрын
You could do the same with a battery a potentiometer and the motor alone, increasing resistance decreases voltage drop on the motor, led or anything for that matter, but in the case of an led, you still need a resistance such that you don't destroy the led
@DorianMcIntire7 жыл бұрын
You cannot do this with a standard potentiometer and a motor without burning out the potentiometer and wasting power. This is a common misconception for new students leaning about electricity and electronics. PWM is a very efficient way to control power since the signal is either OFF or ON and not in-between. Controlling power to high-power loads with resistors or potentiometers is a very inefficient way to control power since much of the power is converted to heat in these devices. This is why most high power amplifiers today use PWM to control power to speakers.
@SilverMiraii7 жыл бұрын
Dorian McIntire I don't get why you burn out the potentiometer, it's just a band of restive material and a knob to set the distance on that material. But in any case, in theory resistance = loss of power. since p=i*v and v=i*r then p=I*r^2, so the higher the resistance, the higher the power. And you're right, while I passed all the tests in school, I still feel like a novice who needs lots more learning. PWM does make sense tho, you don't need extra resistance, you obtain an average voltage through frequency control, it's just on and off as you said, you get the same result in voltage as an actual equivalent resistor. Quick question, I know you could do PWM with arduino for example, but that's just too much, is there such as a smaller device to get the same result ?
@DorianMcIntire7 жыл бұрын
You can do PWM with a 555 timer. See the following link for details. www.555-timer-circuits.com/motor-pwm.html This would require only a few dollars in materials. Have fun.
@SilverMiraii7 жыл бұрын
Dorian McIntire Thank you
@DorianMcIntire7 жыл бұрын
You're Welcome. Thanks for commenting.
@mikeyz87754 жыл бұрын
Im excited lol... this was perfect.
@KarolinasKrafts8 жыл бұрын
Enjoyed your video!
@درسقرآنوسنت7 жыл бұрын
Thank you just solve a big problem in my project
@RTOHIO7 жыл бұрын
Great video and much appreciated. Can you use a Mosfet to control a stepper motor, albeit in only one direction?
@DorianMcIntire7 жыл бұрын
MOSFETS are frequently used to drive stepper motors but you must create a bipolar driver to drive a bipolar stepper motor. For a bipolar motor you would need two sets of MOSFETS per phase (a set would be one P-Channel and one N-Channel) for a total of eight MOSFETS . To drive a Unipolar stepper motor you would need 4 MOSFETS.
@amitkanswal68748 жыл бұрын
Thank u,This video was very helpful
@Miata8229 жыл бұрын
Thanks! Just what I was looking for.
@DorianMcIntire9 жыл бұрын
Alberto Knox Great!
@yengamatic9 жыл бұрын
Hi and thanks for your illustrative videos. I watched this one and the "Power MOSFET Motor ontrol with Arduino" one. I am more a software engineer, although I have some electronics understanding. I plan to control a water pump, rated at 3-6v (sorry, no idea of the current it uses until I receive the pump), by means of an esp8266 (3.3v). I have watched many videos and I have two kind of doubts: 1) What kind of MOSFET should I be using? I see lots of them, with lots of numbers... I don't want to buy a 2-chanel motor driver, as I consider a waste of money given that I don't have to control the speed, although I would be a nice feature to have. 2) In many videos/schematics I've seen, there is usually a diode in the motor, also a resistor between the gate and GND, and sometimes a capacitor somewhere else. Why is your setup lacking those, or why do other people have them? Thanks and keep up the good work!
@DorianMcIntire9 жыл бұрын
+Green Magic To select a MOSFET can simply do a search on Ebay or Amazon for MOSFET and select a MOSFET with a current rating and voltage rating around twice what your device needs. A BUZ111S or IRF2807 is a good choice if your voltage is less than 50 volts. A low resistance resistor can help keep the Gate inrush currents low but is not necessary if a high current GATE driver is used. Too high a resistance will slow the MOSFET switching speed down and could cause overheating of the device. The need for Snubber Capacitors or Diodes (Google the term for more information) depends on the application. These devices prevent potential voltage spikes, from inductive loads such as motors, from possibly destroying the MOSFET. Good luck
@eastern8156 жыл бұрын
thanks man this video is very great helpful for me.
@ArcanePath3608 жыл бұрын
Nice video. I have an existing 19v DC motor that is controlled by a trimpot. I'm wondering if I can tether off the control pin of this trimpot and add a MOSFET so I can control the motor with an Arduino, but still use the trimpot in the circuit as a limiter? Thanks
@TCPPERFORMANCE17 жыл бұрын
Dorian, thanks for the video and others you have done! Great job of explaining! I am wanting to program an ATMEGA328 on an Arduino uno then move the chip to a bread board or proto type board using the pwm functions. Is this possible? And if so is it something you would be interested in doing a video tutorial on it? Thanks again for your great videos!
@DorianMcIntire7 жыл бұрын
Yes, you can move the chip to a breadboard but you will need the following: 1 bootable chip (or burn your own bootloader per the video link) www.amazon.com/gp/product/B00P5IRS9I/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1 (1) 16 Mhz crystal www.amazon.com/16-000MHz-AT49S-Quartz-Crystal-Oscillator/dp/B005MN8FPW/ref=pd_bxgy_147_img_2?_encoding=UTF8&psc=1&refRID=98RKY5HX65KRXV06FH3B (2) 22 pf capacitors www.amazon.com/uxcell-22pF-Voltage-Ceramic-Capacitors/dp/B0087ZBK4K/ref=pd_bxgy_328_img_3?_encoding=UTF8&psc=1&refRID=V4AJGW8H9JAFZYGTH7H7 The following video shows how to hook up the components to the chip and burn your own bootloader using another Arduino. Once this done the chip can stand alone. BEWARE you must add a 5 volt regulator to power the chip if you want it to stand alone. kzbin.info/www/bejne/nWqTqZVmo7OLa5I I may make my own video eventually with more explanation about the process. Dorian
@deepankarkanand46687 жыл бұрын
The explaination is awesome , but circuit and code are pretty much small for a smartphone viewer (everybody can't have a pc or laptop).Rest every thing is cool!!
@shan_singh4 жыл бұрын
i want to control speed of motor(without gears) to use in my project, how can i do it? also, doesnt connecting motor to arduino without motor driver, will damage the pins which are meant only for low current values??
@DorianMcIntire4 жыл бұрын
You control the speed, with no directional control which would require an H-Bridge, by doing exactly what I did in the video. The MOSFET transistor I used in the video allows the motor to be driven without drawing excessive current from the Arduino.
@joro86043 жыл бұрын
Well done!
@parthrupareliya6256 жыл бұрын
This is good video, But i have one question that if i want to reverse a DC motor with this method this can't be done because transistor can only run the motor.
@DorianMcIntire6 жыл бұрын
Yes, you cannot rung the motor is reverse direction without an H-Bridge drive.
@Thrive-Off-Grid5 жыл бұрын
Trying to wrap my head around your wiring. Aren't you pulsing the ground circuit of the motor? Am I understanding this correctly?
@DorianMcIntire5 жыл бұрын
Yes, we call this a sinking connection to a load. This is the easiest way to interface to a MOSFET. Using this method we create a common ground connection and can control current from one voltage source (Arduino) using a different voltage source (motor).
@kingjames-fn8ib5 жыл бұрын
thanks. but i think its dangerous to make ground common to power source ,especially if using much more powerful motors and power source
@DorianMcIntire5 жыл бұрын
It's the only way to drive a transistor and motor it is also a common practice for systems using small motors and loads. Larger, high voltage motors are typically driven using an Optical Isolator. However Optical Isolators are relatively slow devices when using PWM.
@donskanone7 жыл бұрын
Cool video! But shouldn't you also use a flyback diode?
@DorianMcIntire7 жыл бұрын
A separate fly-back diode is not necessary since it is built into the MOSFET. Most power MOSFETs, these days, have built-in diodes. The fly-back diode in the MOSFET serves the same purpose except the fly-back path is through the power supply instead of just across the motor.
@vladan_kovacevic7 жыл бұрын
+Dorian McIntire How does that actually work? When Mosfet turns of, drain voltage goes high, while source is constantly at ground, therefore diode across Mosfet never conducts? On the other hand, if H-bridge was built using Mosfets with built in diodes then it makes sense.
@DorianMcIntire7 жыл бұрын
Although the body diode in a MOSFET is used for commutation in H-Bridges it also has the properties of a zener diode and breaks down under brief high voltages. I have never experienced a MOSFET breakdown with a built-in body diode - in fact I've never experienced it with any MOSFET. Newer MOSFETs, can tolerate the voltage spikes generated when switching small DC motors. Viewers commonly recommend freewheeling diodes (its almost epidemic) for PWM but with a body diode MOSFET it is totally unnecessary. The goal of the video was to show an application of PWM and I really didn't want to complicate things with a discussion about fly back diodes.
@vikkalkat45237 жыл бұрын
Hey, thanks for sharing! I am wondering about the efficiency of using a mosfet. When no voltage is applied to the gate, there exists an infinite resistance between the source and drain, right? So, doesn't this mean that all of the power in the "second" circuit must be dissipated as heat? That is, 100% inefficiency? If we wish to have a slow motor speed, we would apply a small voltage to gate, and then does the rest of the power always get dissipated as heat? If we use a PWM signal to the gate, does this solve this issue?
@DorianMcIntire7 жыл бұрын
When a device is off and exhibits infinite resistance no current can flow so the device uses no energy. Conditions necessary for a device to use power is that both voltage across the device and current through the device must be present at the same time. The mosfet uses no power when it is off and uses very little power when it is fully on since it has current but very little voltage across it.
@NoSkillsRequired8 жыл бұрын
interesting video thanks
@mustaqdj9 жыл бұрын
what was the use of the mosfet ? the pwm voltage controls the speed right ?
@DorianMcIntire9 жыл бұрын
+mustaq rookie To control the speed of the motor up and down. The PWM pulse width controls the speed.
@alfonsocanales72108 жыл бұрын
I'm wondering the samething, I know you are controlling with PWM signal, but for what I know the Mosfet can receive analog signals to Gate to control the output voltage. am I wrong?
@quintindudragne33596 жыл бұрын
The most important part for the mosfet transistor is to allow a small amount of current to control a higher amperage circuit. If you were to try and run the motor directly off the arduino you would damage the circuit board.
@oxxomarin9 жыл бұрын
Great vid and very helpful. Do you know for how long the motor can be used non-stop from 9V battery (at lowest speed 80)? Can you suggest please what else can help make the motor run non-stop? Thank you
@DorianMcIntire9 жыл бұрын
+oxxomarin It really depends on many factors. For instance how big is the motor, is it under load and how much load is it under. Obviously If you use a wall transformer, instead of a battery, and plug it into an outlet you can run it non-stop. The question is a little confusing because I'm not sure what you really need to accomplish. Thanks for commenting.
@oxxomarin9 жыл бұрын
+Dorian McIntire Thank you for your reply. The idea is to create a rotating display stand for collectible items using Arduino board. The weight on it will be no more than 100g. Since it's a personal project, it would be nice if the motor could run throughout the day (maybe non-stop is not necessarily at this moment).
@DorianMcIntire9 жыл бұрын
+oxxomarin If everything is lightweight and well balanced you could probably run it for a day or two. Adding some power management hardware and software would help it work even longer. For instance a photocell could be added to allow it to run only when the room was darker or an PIR (Passive Infra Red) sensor could be added to allow it to run only when a person was in the room. Other things to consider are using (6) C or D cell batteries configured for 9 volts. These will allow it to run many many time longer. Wall transformers are a very cheap and easy solution and you might be able to recycle such a transformer since most people have dozens tying around from devices they bought over the year. Good Luck.
@oxxomarin9 жыл бұрын
+Dorian McIntire Thank you for the suggestions. Much appreciated
@DorianMcIntire9 жыл бұрын
+Mohit Bhasi Sorry to hear that. What MOSFET did you use?
@benmerrick90779 жыл бұрын
Dorian McIntire Would this MOSFET work? Mosfet transistors [IRF520]
@benmerrick90779 жыл бұрын
Dorian McIntire Im also using a 6/9 volt dc motor
@SaureHefePegorino8 жыл бұрын
+Ben Merrick any LOGIC LEVEL mosfet will work, just look at maximum voltage and current the mosfet can take.
@swedensy6 жыл бұрын
I recreated this with pwm generator module. Question is why mosfet disipates sooo much heat even if output power is at its lowest.
@DorianMcIntire6 жыл бұрын
You may have selected a MOSFET with a high Gate threshold voltage and cannot turn it fully on.
@dhidhi10004 жыл бұрын
are you sure this is PWM modulation? judging by your code at 9:10, it seems you just put a constant voltage value at pin 3, and hence the MOSFET is working on that constant voltage, but not actually switching on and off multiple times every second (there is not even a frequency defined anywhere)
@DorianMcIntire4 жыл бұрын
If you paid attention to the video you'll notice I started with the 'Blink' example to save typing all the code from scratch. The setup 'Blink' code is relevant to set pin 3 (A pwm pin) as an output. The loop 'Blink' code was replaced with the analogWrite code. analogWrite() actually creates a PWM signal not a true analog signal. The statement analogWrite(3, 255) statement produces the equivalent of a 5 volt signal (100% duty cycle) on pin 3. A analogWrite(3, 128) statement produces a 50% duty cycle. As I mentioned Arduinos Unos do not produce a true analog output signal they simulate analog output using PWM with a range of 0 to 255. BTW I did not remove the comments in the 'Blink' example which may have cause some confusion but the video content explained the process.
@dhidhi10004 жыл бұрын
@@DorianMcIntire I didn't know that, thank you for explaining! I see from the documentation that is generates PWM signals at 490 Hz. www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
@DorianMcIntire4 жыл бұрын
@@dhidhi1000 I guess I could have gone deeper into the explanation but the video would have been more than twice as long. I plan to cover many more Arduino videos in the future as a resource for my students. Glad you already found the Arduino reference which is very helpful when working with the device.
@untitledusername37996 жыл бұрын
jesus christ thank you so much i finally understand how to use a mosfet
@medchaouechi8427 жыл бұрын
Well done , nice video
@DorianMcIntire7 жыл бұрын
Thanks!
@swetha09984 жыл бұрын
Im going to control speed and direction of a dc series motor to drive a conveyor belt in my project...how much rpm And power is required for the motor..on what specifications should i buy a motor..plse tell me☹️
@DorianMcIntire4 жыл бұрын
There are too many variables to consider without know more about your needs. Also you must use an H-Bridge motor to make the motor move in reverse.
@benmerrick90779 жыл бұрын
Would this transistor work too?? Mosfet transistors [IRF520]
@jaycool59786 жыл бұрын
Nice but what about direction control?
@DorianMcIntire6 жыл бұрын
Direction control requires an H-Bridge.
@santoshvardhan13274 жыл бұрын
We tried in three varient speeds with one switch. I mean we are changing pwm pulse high, medium and low using switch. If we press one time motor is in high speed if press one more time motor will run medium and if we press the button one more time motor will run in low speed. But Mosfet is heating in low and medium speeds. Why❓. Please explain.
@DorianMcIntire4 жыл бұрын
Suggest you check the MOSFETs specification and make sure the Gate-Threshold Voltage (Vgs) is low enough to fully drive the MOSFET on with only 5 volts (e.g. Logic Level MOSFET). A MOSFET threshold voltage of 3 volts or less should work well. Make sure the gate capacitance of the MOSFET is also low to minimize the turn-on time. The shorter the MOSFET remains in linear mode the better. Not every power MOSFET can be driven straight from an Arduino due to the gate drive current limitation of the Arduino. You can purchase MOSFET driver chips to help with this problem.
@tamgaming98617 жыл бұрын
Thanks a lot for the tutorial - if i want to regulate the speed with an Touchdisplay - HMI - how would i have to think to realise it? So that the Arduino changes the numbers and sends it to the PWM?
@DorianMcIntire7 жыл бұрын
Setup a slider control on the screen set up to generates a number from 0 to 255. Store the number in a variable used in the PWM command. For instance: slider control variable stored in motorSpeed variable use to control speed of motor: analogWrite(9, motorSpeed)
@tamgaming98617 жыл бұрын
Thanks a lot for your answer - that helps to get an understanding what i have to looking for on tutorials - thanks !!!
@cryptedcoder56694 жыл бұрын
I'm having trouble, I have wired it all correctly and copied your code. But when I change the value let's say from 255 to 80 the speed does not change no mater what number I put
@DorianMcIntire4 жыл бұрын
Sounds like you might have a shorted transistor. Also if the motor is not loaded the circuit does require a very low number to slow the motor down.
@cryptedcoder56694 жыл бұрын
@@DorianMcIntire ye I figured it out thank you so much. I plugged the wrong wire to negative on the battery and vice versa
@Mehecanogeesir9 жыл бұрын
doesn't a mosfet require a resistor between gate and source?
@DorianMcIntire9 жыл бұрын
+Mehecanogeesir No. As long as the input signal voltage is transitioning between high and low the gate voltage will go between high and low. Pull-down resistors for MOSFET gates are only needed if the signal can only source the gate instead of sink and source the gate like an Arduino output can.
@charlesklein72324 жыл бұрын
im trying to buy your mosfet but finding it possably difficult to do. i am uneducated and so lack the knowledge to understand. you say it a mosfet 2n7000. however, on your cheat its actually a 2n7000-g does the "g" make a difference? what is its significance? i have found mosfet that are labeled with a "g" but most are labeled: "2N7000 TO92 Small Signal MOSFET 200 mAmps, 60 Volts N-Channel TO-92"
@DorianMcIntire4 жыл бұрын
Any 2N7000 will do. The letters do typically refer to a non-electronic feature. The 2N7000 is a very popular, small signal MOSFET. They are readily available on Amazon and electronic suppliers. I buy them by the hundred at Amazon.
@ahnafrafid62609 жыл бұрын
what is the model no. of your mosfet??
@mohit41649 жыл бұрын
Hey , my circuit always seems to be always complete Dorian McIntire .The mosfet doesnt seem to be acting like a switch. please help ASAP can we have a video chat or something? pls pls it is for my school project . I need to submit it in a few days
@DorianMcIntire9 жыл бұрын
Can you send me a picture of the setup? Thanks.
@sunnyshrestha3174 жыл бұрын
can u change the direction of the motor with this setup and these components ?
@DorianMcIntire4 жыл бұрын
No. Please see my answers to similar questions in the comments.
@CuddleStories5 жыл бұрын
Does this circuit amplify the current?
@DorianMcIntire5 жыл бұрын
The transistor amplifies the current produced by the Arduino output pin.
@youssefrezk67829 жыл бұрын
Is there a way to hook it up so different outputs control the motor in different directions clockwise and counterclockwise, like if it sees output 3 high rotate clockwise, if output 5 is high rotate counter clockwise
@DorianMcIntire9 жыл бұрын
+Youssef Rezk Not really. You'll need an H-bridge to drive the motor is both forward and reverse. Very small loads can be driven with one polarity or another by using two outputs and making one output high while the other is low and vice versa.
@alfonsocanales72108 жыл бұрын
so, If I send 5 volts to the gate am I going to have maximum speed possible? I can't give 12 volts? I'm kinda confused
@DorianMcIntire8 жыл бұрын
PWM control has nothing to do with gate drive voltage although you must exceed the threshold voltage of the MOSFET. PWM is about controller duty cycle or time on versus time off.
@oguzhan23938 жыл бұрын
can't he gives 5v voltage to the dc motor? I wanna give 2.5 amper and 1.2 voltage to heat a spring same thing to to dc motor. Does it work?
@piegp945 жыл бұрын
Hi, does the circuit works if i change the frecuency above 60 KHz?
@DorianMcIntire5 жыл бұрын
The default frequency for the Arduino is 490 Hz. Although you can raise it by manipulating the settings for the processor you cannot change it to 10 Khz. When PWM frequencies are too high the motor inductance becomes a big problem.
@YaswanthKumar88886 жыл бұрын
Hi, can we do the same functioning using a relay instead of mosfet please explain...
@DorianMcIntire6 жыл бұрын
You can only turn the motor on and off using a relay. You cannot control the speed.
@YaswanthKumar88886 жыл бұрын
@@DorianMcIntire thank you for the clarification
@Monyet96lookout17 жыл бұрын
Does this work if i were to change the motor to a Water Pumping Electric Micro Pump Motor?
@DorianMcIntire7 жыл бұрын
Any small motor will work fine as long it does not draw more than an amp of current.
@djjjozsi4 жыл бұрын
Could you please suggest a way to make 5V DC outputs from a 24 V DC power supply ? I see only horrible tutorials on YT. Thank you.
@DorianMcIntire4 жыл бұрын
It really depends on how much current you need for your application. If you need 1 amp, for instance, and try to use a 7805 regulator IC in linear mode, the IC would need to dissipate 95 watts of power which would destroy the IC! You really need to use a switching regulator for high currents and such regulators can be fairly complicated. Unless you just really want to build something, instead of buy, I would recommend a pre-built switching regulator such as the one available at the following link: www.ebay.com/itm/3-CUI-Inc-V-infinity-Switch-Mode-Switching-Regulator-7805-DC-DC-Buck-Converter-/263591638141. Three of these for $12.95 is a very good deal.
@djjjozsi4 жыл бұрын
@@DorianMcIntire Thank you Dorian, helped a lot. I will try this soon. 😀😀
@ThunderWindz7 жыл бұрын
so a mosfert is just a mini relay ?
@DorianMcIntire7 жыл бұрын
A MOSFET can act like a relay - among other things - but with no moving parts, very little energy required to operate it and the ability to switch in nanoseconds.
@rcalihan38779 жыл бұрын
Thank you very much
@DorianMcIntire9 жыл бұрын
Rc Alihan You're welcome. Thanks for watching and commenting.
@jumbo9996144 жыл бұрын
I have only 2N7000 (without G). Can i use it?
@DorianMcIntire4 жыл бұрын
Any 2N7000 will work fine. The current limit for a 2N7000 is only about 0.2 amp so you will not be able to run a large motor.
@nikhilmurarka10707 жыл бұрын
what is the command to vary duty cycle automatically?
@DorianMcIntire7 жыл бұрын
I'm not sure what you what to know. The code is shown and explained in the video at 6:51.
@abdullahakhtar98647 жыл бұрын
my motor starts running before i connect arduino to computer..arduino also on with battery.it can cause arduino to burn..please suggest the solution
@DorianMcIntire7 жыл бұрын
Make sure the mosfet is an N-Channel mosfet and is not an enhancement-mode mosfet. Check to see if a 1K pulldown resistor on the gate solves the problem.
@DorianMcIntire7 жыл бұрын
Correction IS an enhancement-mode mosfet.
@abdullahakhtar98647 жыл бұрын
THANK YOU
@virajpadwal8846 жыл бұрын
how to change the direction of motor ?
@DorianMcIntire6 жыл бұрын
You can't change the direction with this setup. You must use an H-Bridge which uses 4 transistors to switch the motor polarity. It far better to buy an H-Bridge than build one.
@p0intblank5977 жыл бұрын
thanks you helped me make my obstace avoding robo
@DorianMcIntire7 жыл бұрын
Great! Happy I was able to help.
@jarhead21599 жыл бұрын
Ok please help quickly, I have a circuit set up this exact way, same 9v battery, a 12v motor, an IRLB3034PBF mosfet, and a simple code using digital signals that turns it on for three seconds and turns it off for three seconds and loops that. However, when I hook it up, the motor turns full speed for three seconds, then just lowers to a little bit slower speed for three seconds. Is there any reason why thats happening? Please respond asap as I am using it for a physics project!
@DorianMcIntire9 жыл бұрын
JarHead21 Which code are you using to control the motor? Are you using the blink command to turn the motor on and off? Did you declare the output pin as an output? Have you looked at the following video: kzbin.info/www/bejne/gqvbpqWlZb9le9k The code in the linked video makes the motor move faster and then slower?
@jarhead21599 жыл бұрын
Dorian McIntire This is my code: int switchpin = 9; void setup() { // put your setup code here, to run once: pinMode(switchpin, OUTPUT); digitalWrite(switchpin, LOW); } void loop() { // put your main code here, to run repeatedly: digitalWrite(switchpin, LOW); delay(3000); digitalWrite(switchpin, HIGH); delay(3000); } I've watched the video you included several times as well, setting it up the same way, getting the exact same results.
@DorianMcIntire9 жыл бұрын
JarHead21 The MOSFET you're using is actually an electrical monster. One potential problem with this MOSFET is that the input capacitance is huge. Try increasing the first delay to 8000 (8 seconds) and leave the second delay time at 3000 (3 seconds). If the MOSFET actually turns off or slows down much more then the Arduino is probably having a problem sinking the gate current needed to turn off the MOSFET. Try using a lower current MOSFET (around 10 Amps) to see if this solves the problem.
@DorianMcIntire9 жыл бұрын
Dorian McIntire Also see if you can turn the MOSFET ON and OFF by touching the gate wire Ground , to turn it off and then +9V to turn it back on. If this works then the output pin is probably having trouble with the MOSFET specifications.
@DorianMcIntire9 жыл бұрын
Dorian McIntire One more thing to try is hooking the MOSFET to another output pin but make sure you change the code.
@akhilalle55736 жыл бұрын
Sir i can use for dc motor ratings 24v 12A 250w.plz clear my doubt
@DorianMcIntire6 жыл бұрын
You may have trouble finding a MOSFET with the Transconductance rating you will need and low Gate threshold rating (logic level, a few volts below 5 volts) for such a large amount of drain current. If you find such a MOSFET make sure you install a free-wheeling diode between the motor terminals. Google the term "freewheeling diode" for more details.
@akhilalle55736 жыл бұрын
Thank you sir,12a is the rated current of the motor,our project is on automatic wheel chair so we required constant low speed but high torque. so how we can do this in simple way.plz suggest any idea
@DorianMcIntire6 жыл бұрын
All I can do is refer you to some online resources for high-current motor control. My video was primarily about basic motor control using PWM and the Arduino. Quite a bit of work is required to create a high current motor driver and I would use a pre-fabricated H-Bridge for such a task. Below are some references. www.mouser.com/applications/industrial-motor-control-mosfets/ chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/ww1.microchip.com/downloads/en/DeviceDoc/00000896M.pdf
@akhilalle55736 жыл бұрын
Dorian McIntire thank you sir
@lastbench68846 жыл бұрын
Sir when I connect source to gnd motor stops any solution
@DorianMcIntire6 жыл бұрын
I don't know what to tell you if I can't see what you've done. As I often must tell my students - things do not not work properly when they not connected properly. Make sure your connections are correct, make sure you have the proper pin-out information for your MOSFET, make sure you are using a MOSFET and not a BJT, make sure your motor does not draw more current than the MOSFET can handle, make sure your motor does not draw more current than your power supply can provide, etc.
@supernova65535 жыл бұрын
how would you do bi-directional movement?
@DorianMcIntire5 жыл бұрын
You can't do it with a single transistor, look up the term 'H-Bridge' for more information.
@supernova65535 жыл бұрын
@@DorianMcIntire Yes I know. How do battery powered drills change direction? Also an h-bridge?
@DorianMcIntire5 жыл бұрын
Yes. H-Bridges are readily available in many compact packages and can handle a considerable amount of current.
6 жыл бұрын
What maximum voltage and amperage am i able to control with arduino pwm ?
@DorianMcIntire6 жыл бұрын
5V and 50ma without a transistor. With the right transistor - no limit.
6 жыл бұрын
I wanted to connect the Peltier 12706 12v 60 watts 3 amp and control voltage with arduino so I can connect for example with mosfet LRF 530 or IRFZ44 N for example, or a more powerful transistor
@DorianMcIntire6 жыл бұрын
The IRFZ44 should be fine with plenty of overhead.
6 жыл бұрын
Dorian McIntire thank you🙋
@almirbajsini6 жыл бұрын
Can i use IRFZ44N
@DorianMcIntire6 жыл бұрын
Yes, most any power, N-Channel MOSFET will work.
@AlwinThomasz2p7 жыл бұрын
Could you please tell me how to generate 20khz pwm signal using Arduino (code), I wanna control MOSFET in my buck converter
@DorianMcIntire7 жыл бұрын
To do this you must change the PWM frequency register division ratio but this is not a trivial thing to do. The division depends on the type of Arduino. Are you using an Uno?
@AlwinThomasz2p7 жыл бұрын
Arduino UNO
@DorianMcIntire7 жыл бұрын
It can be done with bit-banging but I recommend the PWM library mentioned in the link below: forum.arduino.cc/index.php?topic=117425.0 github.com/jurs/arduino-pwm-frequency-library Keep in mind that if you change the PWM frequency some of the timing functions on the Arduino such as Millis() and Micro() may not work properly.
@MarkMaslowPoet8 жыл бұрын
aren't most small voltage 2 wire electrical motors capable of rotating in both directions? Do you have an example of where you can use an arduino to control a motor in both directions? The project I have in mind would require to turn the motor n turns clockwise, hold it for m seconds (hours?) and then turn the motor n turns counter-clockwise.
@DorianMcIntire8 жыл бұрын
+Mark Maslow All DC motors can be reversed by reversing the polarity to the motor. Reversing the polarity to a motor using a controller however is not a simple thing and requires 4 switches in a configuration called an H-Bridge.
@mohit41649 жыл бұрын
Well I guess. Used a wrong mosfet and blew up my arduino :(
@abdullahakhtar98647 жыл бұрын
si can i use B0343 mosfet
@DorianMcIntire7 жыл бұрын
I'm not sure. I can't find any data on such a MOSFET.
@kaspariito5 жыл бұрын
thats a nice one. thank you for the tutorial! :))
@hiennghiem15888 жыл бұрын
Hi thanh you
@troudikhaled86408 жыл бұрын
i need your help,i want the code, please?
@DorianMcIntire8 жыл бұрын
+troudi khaled The code is displayed in the video. It is simply a modified version of the Blink program in the Arduino example programs.
@hammadkhan20044 жыл бұрын
Programming code?
@DorianMcIntire4 жыл бұрын
Look at the video at the following address: kzbin.info/www/bejne/imq9oZyoas2cmtk. As I mentioned in the video the code is a variation of Blink.
@charlesklein72324 жыл бұрын
THE "G" MEANS ITS A -GREEN- "ROHS" LEAD FREE! CONSEQUENTLY IT HAS NO! MEANING! zoomed in using 65 inch 4k and read the paper. otherwise i would have tracked down the paper. apology's!
@zedd817 жыл бұрын
Is it possible to use the same 9v battery to power the arduino?
@DorianMcIntire7 жыл бұрын
Only if the 9v positive is connected to Vin NOT 5V. The negative lead is connected to GND
@potbot8873 жыл бұрын
Can I use a 3.7 V battery to run it, instead of 9V? My motor needs 0.8A.
@DorianMcIntire3 жыл бұрын
Yes, you can replace the 9V battery with any voltage that will work with your motor. You must, however, provide a voltage to the Arduino Arduino that is compatible with the controller.