Arduino Motor Interfacing using MOSFET and PWM

Sdílet
Vložit
  • čas přidán 9. 06. 2014
  • A tutorial on using the Arduino to control devices such as motors using PWM or pulse width modulation.
  • Věda a technologie

Komentáře • 220

  • @Fredster9984
    @Fredster9984 Před 8 lety +2

    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.

  • @plaije
    @plaije Před 9 lety +2

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      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.

  • @VaderDarth512
    @VaderDarth512 Před 8 lety +1

    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!

  • @colinmj.jalbert5436
    @colinmj.jalbert5436 Před 6 lety +2

    Thanks man, you really helped me out, by far the best video ive found on this subject

  • @yoursinger4014
    @yoursinger4014 Před 8 lety +4

    Best video in youtube regarding motor control...it was extremely helpful for me! Thanks Dude...Thanks a lot :D

  • @krzysztofkwiecien4245
    @krzysztofkwiecien4245 Před 7 lety

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety +1

      You are very welcome. Hope you enjoy electronics as much as I do.

  • @djjjozsi
    @djjjozsi Před 4 lety +1

    worked like a charm :) I tried many great tutorials without a success. Thank you very much!

  • @Frank_The_Tank22
    @Frank_The_Tank22 Před 5 lety +5

    Great step by step video, you're a time saving badass thanks for the video, cheers!

  • @Reflections2013
    @Reflections2013 Před 7 lety +1

    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

  • @j3s0n
    @j3s0n Před 4 lety

    A really well made tutorial! I liked how you explained every step.

  • @TheBmboone
    @TheBmboone Před 4 lety +2

    "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!)

  • @wellyntongbreton8227
    @wellyntongbreton8227 Před 9 lety

    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. :-)

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      Wellyntong Breton You're welcome. Glad you enjoy the videos. Thanks for commenting.

  • @eriklaken1025
    @eriklaken1025 Před 5 lety +1

    Thank you, and a diode is important but this shows a basic process, very good.Thank you Again.

  • @givenfirstnamefamilyfirstn3935

    Your response to comments is wonderful, you are so helpful and generous with your time. Subscribed after my first viewing. Don’t reply!

  • @handang9165
    @handang9165 Před 8 lety

    Your video is tremendously helpful. Thank you!

  • @mirosawh.1600
    @mirosawh.1600 Před 8 lety

    It is very nice and simple tutorial. Thanks Dorian.

  • @hamilton185
    @hamilton185 Před 7 lety

    Genius! You saved my job!

  • @KaelinatorPVP
    @KaelinatorPVP Před 6 lety +1

    Oh my goodness! I actually understood!! Thank you!

  • @KarolinasKrafts
    @KarolinasKrafts Před 8 lety +1

    Enjoyed your video!

  • @dbright038
    @dbright038 Před 6 lety +1

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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.

    • @dbright038
      @dbright038 Před 6 lety

      Thanks again. Do you have any demonstrations of lighting up different colored LED lights using an Arduino?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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.

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      Make sure you use the Chrome browser to avoid any problems with the code copy.

    • @dbright038
      @dbright038 Před 6 lety

      Thanks for the link. Here is the project if you're interested.
      czcams.com/video/gqxlQ_Gl52Q/video.html

  • @mikeyz8775
    @mikeyz8775 Před 4 lety +1

    Im excited lol... this was perfect.

  • @amitkanswal6874
    @amitkanswal6874 Před 7 lety +1

    Thank u,This video was very helpful

  • @eastern815
    @eastern815 Před 5 lety

    thanks man this video is very great helpful for me.

  • @pedrofer
    @pedrofer Před 6 lety

    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

  • @user-yo1pe4xb8y
    @user-yo1pe4xb8y Před 6 lety

    Thank you just solve a big problem in my project

  • @jfredricks2394
    @jfredricks2394 Před 7 lety

    You sound like John Goodman!!!! Long live Monsters Inc!!!! Love your videos!!!

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      Thanks on both counts really appreciate your comment.

  • @Miata822
    @Miata822 Před 9 lety

    Thanks! Just what I was looking for.

  • @mazdalorean
    @mazdalorean Před 10 lety

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 10 lety

      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..

  • @saavedra358
    @saavedra358 Před 8 lety +1

    Very nice, good explanation, is there a way to incorporate time? To have the motor spin for 10 seconds and then shut off?

  • @keetor13
    @keetor13 Před 9 lety

    Great videos. I've been binge watching your stuff. A big help. Thanks for the effort you put forth to make these.

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety +1

      Zachary Keeton Thanks. It's great to know these videos are making a difference. Comments like yours really make it worthwhile.

    • @keetor13
      @keetor13 Před 9 lety

      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.

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      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.

  • @medchaouechi842
    @medchaouechi842 Před 6 lety

    Well done , nice video

  • @joro8604
    @joro8604 Před 3 lety

    Well done!

  • @junding5948
    @junding5948 Před 5 lety +2

    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

  • @syahrul9282
    @syahrul9282 Před 5 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety

      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.

  • @ArcanePath360
    @ArcanePath360 Před 8 lety

    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

  • @TCPPERFORMANCE1
    @TCPPERFORMANCE1 Před 7 lety

    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!

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      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.
      czcams.com/video/g90xb0nNX50/video.html
      I may make my own video eventually with more explanation about the process.
      Dorian

  • @kayaonur5657
    @kayaonur5657 Před 3 lety

    I think you can also use the analogue signal and change gate-to-source voltage of the mosfet thus control the current

    • @DorianMcIntire
      @DorianMcIntire  Před 3 lety

      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.

  • @RTOHIO
    @RTOHIO Před 7 lety

    Great video and much appreciated. Can you use a Mosfet to control a stepper motor, albeit in only one direction?

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety +1

      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.

  • @yengamatic
    @yengamatic Před 8 lety

    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!

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety +1

      +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

  • @NoSkillsRequired
    @NoSkillsRequired Před 8 lety

    interesting video thanks

  • @garymaya1767
    @garymaya1767 Před 4 lety

    You need a diode across the motor to take car of the back emf. You can map the pwm and adc.

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      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.

  • @vikkalkat4523
    @vikkalkat4523 Před 6 lety

    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?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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.

  • @rcalihan3877
    @rcalihan3877 Před 9 lety

    Thank you very much

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      Rc Alihan You're welcome. Thanks for watching and commenting.

  • @SilverMiraii
    @SilverMiraii Před 7 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety +1

      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.

    • @SilverMiraii
      @SilverMiraii Před 7 lety +1

      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 ?

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety +1

      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.

    • @SilverMiraii
      @SilverMiraii Před 7 lety

      Dorian McIntire Thank you

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      You're Welcome. Thanks for commenting.

  • @parthrupareliya625
    @parthrupareliya625 Před 5 lety

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety +1

      Yes, you cannot rung the motor is reverse direction without an H-Bridge drive.

  • @Thrive-Off-Grid
    @Thrive-Off-Grid Před 5 lety

    Trying to wrap my head around your wiring. Aren't you pulsing the ground circuit of the motor? Am I understanding this correctly?

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety +2

      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).

  • @tamgaming9861
    @tamgaming9861 Před 7 lety

    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?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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)

    • @tamgaming9861
      @tamgaming9861 Před 6 lety

      Thanks a lot for your answer - that helps to get an understanding what i have to looking for on tutorials - thanks !!!

  • @shan_singh
    @shan_singh Před 4 lety +1

    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??

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety +3

      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.

  • @oxxomarin
    @oxxomarin Před 8 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety

      +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.

    • @oxxomarin
      @oxxomarin Před 8 lety

      +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).

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety +1

      +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.

    • @oxxomarin
      @oxxomarin Před 8 lety

      +Dorian McIntire Thank you for the suggestions. Much appreciated

  • @DorianMcIntire
    @DorianMcIntire  Před 9 lety

    +Mohit Bhasi Sorry to hear that. What MOSFET did you use?

    • @benmerrick9077
      @benmerrick9077 Před 9 lety

      Dorian McIntire Would this MOSFET work? Mosfet transistors [IRF520]

    • @benmerrick9077
      @benmerrick9077 Před 9 lety

      Dorian McIntire Im also using a 6/9 volt dc motor

    • @SaureHefePegorino
      @SaureHefePegorino Před 8 lety

      +Ben Merrick any LOGIC LEVEL mosfet will work, just look at maximum voltage and current the mosfet can take.

  • @mustaqdj
    @mustaqdj Před 8 lety +2

    what was the use of the mosfet ? the pwm voltage controls the speed right ?

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety

      +mustaq rookie To control the speed of the motor up and down. The PWM pulse width controls the speed.

    • @alfonsocanales7210
      @alfonsocanales7210 Před 7 lety

      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?

    • @quintindudragne3359
      @quintindudragne3359 Před 5 lety

      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.

  • @swedensy
    @swedensy Před 5 lety

    I recreated this with pwm generator module.
    Question is why mosfet disipates sooo much heat even if output power is at its lowest.

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety

      You may have selected a MOSFET with a high Gate threshold voltage and cannot turn it fully on.

  • @CuddleStories
    @CuddleStories Před 4 lety

    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.

  • @youssefrezk6782
    @youssefrezk6782 Před 8 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety

      +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.

  • @sunnyshrestha317
    @sunnyshrestha317 Před 3 lety

    can u change the direction of the motor with this setup and these components ?

    • @DorianMcIntire
      @DorianMcIntire  Před 3 lety +1

      No. Please see my answers to similar questions in the comments.

  • @dhidhi1000
    @dhidhi1000 Před 4 lety

    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)

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety +3

      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.

    • @dhidhi1000
      @dhidhi1000 Před 4 lety

      @@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/

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety +2

      @@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.

  • @deepankarkanand4668
    @deepankarkanand4668 Před 7 lety

    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!!

  • @Monyet96lookout1
    @Monyet96lookout1 Před 7 lety

    Does this work if i were to change the motor to a Water Pumping Electric Micro Pump Motor?

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      Any small motor will work fine as long it does not draw more than an amp of current.

  • @donskanone
    @donskanone Před 7 lety

    Cool video! But shouldn't you also use a flyback diode?

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety +1

      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_kovacevic
      @vladan_kovacevic Před 7 lety

      +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.

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety +1

      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.

  • @benmerrick9077
    @benmerrick9077 Před 9 lety

    Would this transistor work too?? Mosfet transistors [IRF520]

  • @swetha0998
    @swetha0998 Před 4 lety

    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☹️

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      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.

  • @charlesklein7232
    @charlesklein7232 Před 4 lety

    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"

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      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.

  • @djjjozsi
    @djjjozsi Před 4 lety

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety +1

      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.

    • @djjjozsi
      @djjjozsi Před 4 lety

      @@DorianMcIntire Thank you Dorian, helped a lot. I will try this soon. 😀😀

  • @santoshvardhan1327
    @santoshvardhan1327 Před 4 lety

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      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.

  • @p0intblank597
    @p0intblank597 Před 6 lety

    thanks you helped me make my obstace avoding robo

  • @zedd81
    @zedd81 Před 6 lety

    Is it possible to use the same 9v battery to power the arduino?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      Only if the 9v positive is connected to Vin NOT 5V. The negative lead is connected to GND

  • @untitledusername3799
    @untitledusername3799 Před 6 lety

    jesus christ thank you so much
    i finally understand how to use a mosfet

  • @piegp94
    @piegp94 Před 5 lety

    Hi, does the circuit works if i change the frecuency above 60 KHz?

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety

      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.

  • @mohit4164
    @mohit4164 Před 9 lety

    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

  • @hiennghiem1588
    @hiennghiem1588 Před 8 lety

    Hi thanh you

  • @cryptedcoder5669
    @cryptedcoder5669 Před 4 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      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.

    • @cryptedcoder5669
      @cryptedcoder5669 Před 4 lety

      @@DorianMcIntire ye I figured it out thank you so much. I plugged the wrong wire to negative on the battery and vice versa

  • @ahnafrafid6260
    @ahnafrafid6260 Před 8 lety

    what is the model no. of your mosfet??

  • @alfonsocanales7210
    @alfonsocanales7210 Před 7 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      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.

    • @oguzhan2393
      @oguzhan2393 Před 7 lety +1

      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?

  • @CuddleStories
    @CuddleStories Před 5 lety

    Does this circuit amplify the current?

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety +1

      The transistor amplifies the current produced by the Arduino output pin.

  • @kingjames-fn8ib
    @kingjames-fn8ib Před 5 lety

    thanks. but i think its dangerous to make ground common to power source ,especially if using much more powerful motors and power source

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety

      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.

  • @Mehecanogeesir
    @Mehecanogeesir Před 8 lety

    doesn't a mosfet require a resistor between gate and source?

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety

      +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.

  • @kaspariito
    @kaspariito Před 4 lety

    thats a nice one. thank you for the tutorial! :))

  • @jarhead2159
    @jarhead2159 Před 9 lety

    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!

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      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:
      czcams.com/video/Lzxuro0Z2Ew/video.html
      The code in the linked video makes the motor move faster and then slower?

    • @jarhead2159
      @jarhead2159 Před 9 lety

      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.

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      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.

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      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.

    • @DorianMcIntire
      @DorianMcIntire  Před 9 lety

      Dorian McIntire One more thing to try is hooking the MOSFET to another output pin but make sure you change the code.

  • @YaswanthKumar8888
    @YaswanthKumar8888 Před 5 lety

    Hi, can we do the same functioning using a relay instead of mosfet please explain...

    • @DorianMcIntire
      @DorianMcIntire  Před 5 lety

      You can only turn the motor on and off using a relay. You cannot control the speed.

    • @YaswanthKumar8888
      @YaswanthKumar8888 Před 5 lety

      @@DorianMcIntire thank you for the clarification

  • @jumbo999614
    @jumbo999614 Před 4 lety

    I have only 2N7000 (without G). Can i use it?

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety +1

      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.

  • @jaycool5978
    @jaycool5978 Před 5 lety

    Nice but what about direction control?

  • @nikhilmurarka1070
    @nikhilmurarka1070 Před 6 lety

    what is the command to vary duty cycle automatically?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      I'm not sure what you what to know. The code is shown and explained in the video at 6:51.

  • @ThunderWindz
    @ThunderWindz Před 6 lety

    so a mosfert is just a mini relay ?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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.

  • @lastbench6884
    @lastbench6884 Před 6 lety

    Sir when I connect source to gnd motor stops any solution

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety +2

      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.

  •  Před 6 lety

    What maximum voltage and amperage am i able to control with arduino pwm ?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety +1

      5V and 50ma without a transistor. With the right transistor - no limit.

    •  Před 6 lety

      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

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety +1

      The IRFZ44 should be fine with plenty of overhead.

    •  Před 6 lety +1

      Dorian McIntire thank you🙋

  • @abdullahakhtar9864
    @abdullahakhtar9864 Před 7 lety

    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

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      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.

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      Correction IS an enhancement-mode mosfet.

    • @abdullahakhtar9864
      @abdullahakhtar9864 Před 7 lety

      THANK YOU

  • @akhilalle5573
    @akhilalle5573 Před 6 lety

    Sir i can use for dc motor ratings 24v 12A 250w.plz clear my doubt

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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.

    • @akhilalle5573
      @akhilalle5573 Před 6 lety

      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

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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

    • @akhilalle5573
      @akhilalle5573 Před 6 lety

      Dorian McIntire thank you sir

  • @virajpadwal884
    @virajpadwal884 Před 6 lety

    how to change the direction of motor ?

    • @DorianMcIntire
      @DorianMcIntire  Před 6 lety

      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.

  • @supernova6553
    @supernova6553 Před 4 lety

    how would you do bi-directional movement?

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      You can't do it with a single transistor, look up the term 'H-Bridge' for more information.

    • @supernova6553
      @supernova6553 Před 4 lety

      @@DorianMcIntire Yes I know. How do battery powered drills change direction? Also an h-bridge?

    • @DorianMcIntire
      @DorianMcIntire  Před 4 lety

      Yes. H-Bridges are readily available in many compact packages and can handle a considerable amount of current.

  • @abdullahakhtar9864
    @abdullahakhtar9864 Před 7 lety

    si can i use B0343 mosfet

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      I'm not sure. I can't find any data on such a MOSFET.

  • @MarkMaslowPoet
    @MarkMaslowPoet Před 8 lety

    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.

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety +2

      +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.

  • @almirbajsini
    @almirbajsini Před 5 lety

    Can i use IRFZ44N

  • @AlwinThomasz2p
    @AlwinThomasz2p Před 7 lety

    Could you please tell me how to generate 20khz pwm signal using Arduino (code), I wanna control MOSFET in my buck converter

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      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?

    • @AlwinThomasz2p
      @AlwinThomasz2p Před 7 lety

      Arduino UNO

    • @DorianMcIntire
      @DorianMcIntire  Před 7 lety

      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.

  • @troudikhaled8640
    @troudikhaled8640 Před 8 lety

    i need your help,i want the code, please?

    • @DorianMcIntire
      @DorianMcIntire  Před 8 lety

      +troudi khaled The code is displayed in the video. It is simply a modified version of the Blink program in the Arduino example programs.

  • @mohit4164
    @mohit4164 Před 9 lety

    Well I guess. Used a wrong mosfet and blew up my arduino :(

  • @charlesklein7232
    @charlesklein7232 Před 4 lety

    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!

  • @hammadkhan2004
    @hammadkhan2004 Před 3 lety

    Programming code?

    • @DorianMcIntire
      @DorianMcIntire  Před 3 lety

      Look at the video at the following address: czcams.com/video/T9Zpir5hidw/video.html. As I mentioned in the video the code is a variation of Blink.

  • @potbot887
    @potbot887 Před 3 lety

    Can I use a 3.7 V battery to run it, instead of 9V? My motor needs 0.8A.

    • @DorianMcIntire
      @DorianMcIntire  Před 3 lety

      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.

    • @potbot887
      @potbot887 Před 3 lety

      @@DorianMcIntire Thanks Dorian