No video

P-Channel MOSFET as a Switch. Turn ON a 12V Motor with Arduino. (Step-By-Step Guide)

This is a tutorial about using a P-Channel Enchantment Type MOSFET as a switch to turn ON and OFF a 12V Motor.
UPDATE:
You should also add a 100-ohm resistor between the Arduino pin and the Gate terminal of the MOSFET. The MOSFET has a small capacitance that starts to charge/discharge when you switch the Arduino pin. This creates a short current spike that can be bad for the Arduino pin. Especially if you plan to do high-frequency switching.
Diagrams and code:
circuitjournal...
I am using an IRF9540N, but you can use some other logic level P-Channel Enchantment Type MOSFET.
Buy from AliExpress.com:
IRF9540N: s.click.aliexp...
Disclosure: Bear in mind that some of the links in this post are affiliate links and if you go through them to make a purchase I will earn a commission. Keep in mind that I link these companies and their products because of their quality and not because of the commission I receive from your purchases. The decision is yours, and whether or not you decide to buy something is completely up to you.
Music from KZread library.

Пікірлер: 83

  • @leynardvillagracia6036
    @leynardvillagracia6036Ай бұрын

    AFTER 4 YEARS OF UPLOADING THIS YOU ARE STILL HELPING!!

  • @marcov9581
    @marcov95812 жыл бұрын

    Connecting the Arduino 5V to the 12V supply really threw me off at first. But I realize you are basically using that as the Reference instead of letting Ground be the common reference point. This way when the arduino output is Low (0V from the Arduino perspective) it is -5V on the Gate with respect to the Source. When Arduino output is HIGH (5V from Arduino perspective) then the Mosfet sees 0V at the gate with respect to the Source. You went over this at ~55 seconds on the Video, but seeing 5V connected to 12V throws me off until I remember voltage would be relative and depend on the common reference point which doesn't Have to be 0V/Ground. We're so used to connecting Grounds to make everything relative to 0V Ground, it seems backwards to leave grounds disconnected for circuits to act relative to the High Side instead.

  • @alejandroperez5368

    @alejandroperez5368

    Жыл бұрын

    Yes, it's a ground-shaking moment for us noobs. Thanks for commenting

  • @michalaugustyniak6449

    @michalaugustyniak6449

    Жыл бұрын

    How to solve it if you have a common ground ? Add another diode between Arduino 5v and the S to block current from the battery ?

  • @denizsogutlu2070
    @denizsogutlu20707 ай бұрын

    Thanks Indrek for an amazing explanation. You helped me to solve my 48hrs challenge with correct Mosfet wiring! It's very difficult to simplify and explain stuff like this, really appreciate it!

  • @shabbee
    @shabbee Жыл бұрын

    If you connect the 12v to the arduino VIN pin, my understanding is that the regulator will provide 5v to the Atmel device. At that point you should be OK to connect the grounds?? This is a question rather than advice. I would also recommend using a NPN transistor to to drive the MOSFET gate, with the collector biased at 12v via 10k resistor, the emitter connected to ground, and the base going to the arduino via a 10k resistor.

  • @gregg2597able
    @gregg2597able3 ай бұрын

    very good, your the first that I can understand what is going on with these p and n mosfet's 👍

  • @greggpierce4077
    @greggpierce40773 ай бұрын

    I added 1 component to the circuit and could do away with the Arduino, exactly what I was looking to do! Thanks again Indrek

  • @JacobStevenson
    @JacobStevenson Жыл бұрын

    Could you use a photocoupler (opto-isolator) like PC817 to drive the MOSFET and eliminate the problem with sharing grounds?

  • @muflah

    @muflah

    Жыл бұрын

    I generally suggest not only using an optocoupler but using a power transistor as well. May cost a bit more but I've not found these low rated transistors to be very reliable with motors.

  • @caffeinatedinsanity2324
    @caffeinatedinsanity23244 жыл бұрын

    That's a good video. Also thanks for the warning part :) I recently saw that you can avoid that power supply problem by controlling the P channel mosfet with another transistor (like an NPN or an N channel mosfet). That way you have two isolated circuits

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Hey! Thank you for the feedback! Yes, with another mosfet/transistor it is possible to fix ground connection problem.

  • @elliot1784

    @elliot1784

    4 жыл бұрын

    @@IndrekLAny good resource for this 2 mosfet approach?, thanks. great video!

  • @elliot1784

    @elliot1784

    4 жыл бұрын

    Could you provide where you saw this, hoping to implement the 2 mosfet method. thanks!

  • @hardcoregaming4118

    @hardcoregaming4118

    2 жыл бұрын

    @@IndrekL bro you deserve a 100millions years of electronics and our world thankyou I'm from India

  • @salahuddintarar6539

    @salahuddintarar6539

    9 ай бұрын

    @@IndrekL AS the same Inductive load (Motor) You used in case of N -channel MOSFET ,then why you did not use flyback diode in that case (N-Channel MOSFET )?

  • @HS-hz4fx
    @HS-hz4fx2 ай бұрын

    lets say te power supply for motor is 60 volts, would this circut still works ?

  • @fredd8881
    @fredd88813 жыл бұрын

    Can we use analogWrite 0-255 ? In P channel mosfet . I thought that use negative to work in gate

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    Yes, the P-channel Mosfet is controlled with negative voltage on the Gate relative to the Source. That's why it is connected to the 5V instead of GND. If it is connected like that, you can use analogWrite with it.

  • @dogeeatsveggies
    @dogeeatsveggies3 жыл бұрын

    its basically the same with the N-channel, but works differently. thank you!

  • @RichardKuivila1947

    @RichardKuivila1947

    Жыл бұрын

    "Same" "But Works" "Different" .... ? ?

  • @rehmanazhar6517

    @rehmanazhar6517

    5 ай бұрын

    @@RichardKuivila1947 😂

  • @brunoperezmedellin7000
    @brunoperezmedellin7000 Жыл бұрын

    Your video is really comprehensive and helped me getting started with MOSFET driving, however i have a doubt about Arduino and it's ground, in case i needed to add sensors or anything that needs a ground with the configuration shown on the video would burn the Arduino? Even if the Arduino was powered with a different source to the motor?

  • @bigmac9712
    @bigmac97129 ай бұрын

    If my motor runs with 5v then I can use the same power supply for the arduino and the mosfet/motor right?

  • @juntendo6104
    @juntendo61043 жыл бұрын

    thanks so much! very simple to understand and solved my problem

  • @ljmeng
    @ljmeng3 жыл бұрын

    I like it. It gives all details.

  • @cuf_
    @cuf_2 жыл бұрын

    Thank you so much helped me out man! Btw you sound like an estonian. Am i right? Im from est.

  • @awaazmatroko5972
    @awaazmatroko597211 ай бұрын

    Hi, nice video, Q: is there MOSFET as a switch, when gate has 0v it switches on, need for 12v ups router

  • @charleyandsarah
    @charleyandsarah3 жыл бұрын

    Good info, thanks, I had only seen people talk about the n channel. Any way to isolate the GND for a single power source? I need to power an arduino off a 12v truck, was planning to use a 5v stepdown converter to power arduino, but I need to PWM the 12v signal to control some hydraulic valves

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    But why can't you use an N channel MOSFET on the ground side of the 12V load? It would make things so much easier. As far as I know all the step down converters expect to share the Ground. So if you step it down to 5V it will be relative to the negative output of the battery.

  • @charleyandsarah

    @charleyandsarah

    3 жыл бұрын

    @@IndrekL I'm controlling hydraulic valves with onboard electronic actuators. They call for a fixed GND and 12V supply with a variable voltage signal wire to control direction and amplitude, with 6V being neutral, and over 6v is one direction, under 6v is the opposite direction. I have potentiometers setup to work it fine, but I want to use an arduino so I can make a wireless control

  • @muhammadbilal2000
    @muhammadbilal20002 жыл бұрын

    Thanks for the simple video. I am still thinking that when the gate is given 0 volt then how Vgs is -5 volt?

  • @alejandroperez5368

    @alejandroperez5368

    Жыл бұрын

    Because you have a +5V cable coming from the Arduino to the transistor's source pin. You apply voltages with two cables, not just one. And it's -5V with respect to the Arduino's ground signal, not the motor power supply.

  • @FreddieMare
    @FreddieMare Жыл бұрын

    How to use MOSFET as a normaly close Switch?

  • @yassindahmen203
    @yassindahmen2033 жыл бұрын

    thank you everything is well explained. However i have a question about the fly back diode what are its specifications ?

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    Hey! I used a 1N4007

  • @happycrayon7621
    @happycrayon76214 жыл бұрын

    How come you have so low subscriber. Gonna stay to climb up the ladder to millions.

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Thanks! The sub count is ramping up slowly. I have to work on my delivery (improving my accent and thing like that).

  • @Learnelectronics738
    @Learnelectronics7383 жыл бұрын

    Hello brother Ilike your video thank you very much

  • @ozkantuzemen
    @ozkantuzemen3 жыл бұрын

    Hi, if I want to use depletion type mosfet for this project, which component you suggest?

  • @shivamdeshpande1959
    @shivamdeshpande19594 жыл бұрын

    Thanks for the very nice video and clear cut explanation. I am looking for the P channel (D-S) MOSFET for one of my project and its part number is Si2309CDS by Vishay Siliconix. I am not getting exactly what the D-S MOSFET is and how it is different from a normal P channel MOSFET. Can you please help me with this

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Hey! I am guessing that the "D-S" is referring to Drain and Source. As in "the current is flowing through the Drain and the Source". I tried to google it but didn't find any significance of that marking.

  • @shivamdeshpande1959

    @shivamdeshpande1959

    4 жыл бұрын

    Okay thank you 👍 And thanks for the video, it was really helpful

  • @phuonganh6445
    @phuonganh64456 ай бұрын

    dùng nguồn khác cũng như không

  • @Creative_Electronics
    @Creative_Electronics4 жыл бұрын

    Good Explaining!! ;)

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Thanks!

  • @netrapatil2169
    @netrapatil21694 жыл бұрын

    brother..I want to use a push button to switch a motor ON and off..With mosfet..Can i connect gate to a switch and pther to source with resistor

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Hey! Yes you can replace the Arduino with a simple switch. How high voltage does the motor need? If you need to turn on a 60V motor, but the maximum gate-source voltage for the MOSFET is 20V then you should use a separate lower voltage source to turn the MOSFET on. If the Motor is 12V then you probably can just connect the switch to the power supply.

  • @orides5976
    @orides5976 Жыл бұрын

    Are there any driver chip for P Mosfet?

  • @StefanoZamprogno
    @StefanoZamprogno3 жыл бұрын

    Great video thanks! does it work also for 3.3v signal from eg ESP8266 ?

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    It denepnds on the MOSFET. If you find a logic level MOSFET that fully switches ON below 3.3V then you can. The one I am using switches fully ON at around 4V (according to the datasheet). So you could not use exactly the same one I was using. If it is not fully switched on, then the MOSFET will get hot.

  • @41_ahwaszargar73
    @41_ahwaszargar733 жыл бұрын

    The video is misleading when you say connecting 12 V to a 5v from arduino should actually send 7 v inside the arduino leading to frying of arduino .Also Tysm for the information of potentially frying up of arduino and I really loved the fact you used the concept of Vgs Rather than saying give Vg negative using a npn transistor

  • @muhammedfatihsaruhan7532

    @muhammedfatihsaruhan7532

    2 жыл бұрын

    it is not actually . i thought the same at first. but arduino ground is not connected to the ground of power supply . he uses separate power supply for arduino

  • @gholiamirza7102
    @gholiamirza71024 жыл бұрын

    Nice discribed. Thank you.

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Thank you for the feedback!

  • @sunilkumar-ls2yb
    @sunilkumar-ls2yb4 жыл бұрын

    Bro can you explain Why you connected 12 volt to power arduino 5v pin pin

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Because a P-Channel MOSFET is a "high side switch" and must be connected to the VCC side of the circuit. To achieve this I need to pull Arduino 5V and the positive side of the 12V power source to the same level (note that the grounds are NOT connected). An N-Channel MOSFET is actually a bit simpler. Then you connect the grounds and it is easier to understand.

  • @sunilkumar-ls2yb

    @sunilkumar-ls2yb

    4 жыл бұрын

    @@IndrekL thanks broo.. It was really helpfull

  • @biasedbit

    @biasedbit

    3 жыл бұрын

    @@IndrekL thank you for the great tutorial! I've applied this to my project and it worked out great! 🙌 But I confess I'm still a bit confused by this step -- joining the 12V and 5V. I'm very new to this type of thing, would you mind helping me understand what's going on here (is the 12V side pushing current to the 5V side, are the voltages adding up/being subtracted?) and what you call this kind of merging of two different voltages without a common ground? Thank you!

  • @melkerper
    @melkerper4 жыл бұрын

    Good video!

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Thanks!

  • @CURIOSIDADEOUCRIATIVIDADE
    @CURIOSIDADEOUCRIATIVIDADE3 жыл бұрын

    what is the model of the channel p mosfet used in the video?

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    I used a IRF9540N

  • @CURIOSIDADEOUCRIATIVIDADE

    @CURIOSIDADEOUCRIATIVIDADE

    3 жыл бұрын

    @@IndrekL ok obrigado

  • @faizmajeed409
    @faizmajeed4093 жыл бұрын

    You use 12volt battery and how many amperes?

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    Hey! I didn't use a battery. I used a power source that is plugged into the wall. I don't remember exactly, it was probably somewhere between 0.5 and 1 amper.

  • @faizmajeed409

    @faizmajeed409

    3 жыл бұрын

    How many volt that the mosfet need to on the gate?

  • @IndrekL

    @IndrekL

    3 жыл бұрын

    @@faizmajeed409 The Vgs(th) = -4V. According to the datasheet, the optimal for ON position is -10V, but it didn't get hot at all with Vgs = -5V and sub 1A load.

  • @faizmajeed409

    @faizmajeed409

    3 жыл бұрын

    Okay bro thanks👍

  • @make6689
    @make66894 жыл бұрын

    How much current does the motor consume?

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    Hey! I don't remember exactly. It might have been somewhere around 1A

  • @BegginersGuidetoCode

    @BegginersGuidetoCode

    3 жыл бұрын

    12V @ 0.1A

  • @gaurabpokharel6373
    @gaurabpokharel63732 жыл бұрын

    There is no negetaive 5 v in Arduino , its 0 v that turns on mosfet , because you are turning on and off it worked

  • @IndrekL

    @IndrekL

    2 жыл бұрын

    The voltage is always relative. If you use the Arduino's 5V as 0V from the perspective of the MOSFET then Arduino's GND is -5V.

  • @exessd7051
    @exessd7051 Жыл бұрын

    12V into arduino 5v output ??? what the hell !

  • @matteogamer2606
    @matteogamer26062 жыл бұрын

    the diode

  • @ConspiracytardHunter420
    @ConspiracytardHunter4204 жыл бұрын

    my adafruit esp32 feather died, i guess i did something wrong, rip im broke, so much for this robotics bs, back to reddit

  • @jonathanvanbuskirk5326
    @jonathanvanbuskirk53264 жыл бұрын

    This is sending 5v to a 12v motor

  • @IndrekL

    @IndrekL

    4 жыл бұрын

    No, it is not. The only place to get 5V out of this circuit is between the Arduino 5V pin and Arduino GND. But Arduino GND is not even connected to the motor.

  • @traptown7507
    @traptown75074 жыл бұрын

    Indrek

  • @Nobody-hs9cl
    @Nobody-hs9cl Жыл бұрын

    "P-Channel MOSFET as a Switch. Turn ON a 12V Motor with Arduino. (Step-By-Step Guide)" ??? Regrettably you DO NOT explain how to turn on a 12 V motor with Arfuino and a P-Channel Mosfet in this Video. Rather, you are just warning that this will damage the Arduino. Pitiable!

  • @tattoome229
    @tattoome2292 жыл бұрын

    hi Indrek what's your email or FB I have a few question ?

Келесі