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
AFTER 4 YEARS OF UPLOADING THIS YOU ARE STILL HELPING!!
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
Жыл бұрын
Yes, it's a ground-shaking moment for us noobs. Thanks for commenting
@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 ?
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!
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.
very good, your the first that I can understand what is going on with these p and n mosfet's 👍
I added 1 component to the circuit and could do away with the Arduino, exactly what I was looking to do! Thanks again Indrek
Could you use a photocoupler (opto-isolator) like PC817 to drive the MOSFET and eliminate the problem with sharing grounds?
@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.
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
4 жыл бұрын
Hey! Thank you for the feedback! Yes, with another mosfet/transistor it is possible to fix ground connection problem.
@elliot1784
4 жыл бұрын
@@IndrekLAny good resource for this 2 mosfet approach?, thanks. great video!
@elliot1784
4 жыл бұрын
Could you provide where you saw this, hoping to implement the 2 mosfet method. thanks!
@hardcoregaming4118
2 жыл бұрын
@@IndrekL bro you deserve a 100millions years of electronics and our world thankyou I'm from India
@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 )?
lets say te power supply for motor is 60 volts, would this circut still works ?
Can we use analogWrite 0-255 ? In P channel mosfet . I thought that use negative to work in gate
@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.
its basically the same with the N-channel, but works differently. thank you!
@RichardKuivila1947
Жыл бұрын
"Same" "But Works" "Different" .... ? ?
@rehmanazhar6517
5 ай бұрын
@@RichardKuivila1947 😂
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?
If my motor runs with 5v then I can use the same power supply for the arduino and the mosfet/motor right?
thanks so much! very simple to understand and solved my problem
I like it. It gives all details.
Thank you so much helped me out man! Btw you sound like an estonian. Am i right? Im from est.
Hi, nice video, Q: is there MOSFET as a switch, when gate has 0v it switches on, need for 12v ups router
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
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
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
Thanks for the simple video. I am still thinking that when the gate is given 0 volt then how Vgs is -5 volt?
@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.
How to use MOSFET as a normaly close Switch?
thank you everything is well explained. However i have a question about the fly back diode what are its specifications ?
@IndrekL
3 жыл бұрын
Hey! I used a 1N4007
How come you have so low subscriber. Gonna stay to climb up the ladder to millions.
@IndrekL
4 жыл бұрын
Thanks! The sub count is ramping up slowly. I have to work on my delivery (improving my accent and thing like that).
Hello brother Ilike your video thank you very much
Hi, if I want to use depletion type mosfet for this project, which component you suggest?
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
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
4 жыл бұрын
Okay thank you 👍 And thanks for the video, it was really helpful
dùng nguồn khác cũng như không
Good Explaining!! ;)
@IndrekL
4 жыл бұрын
Thanks!
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
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.
Are there any driver chip for P Mosfet?
Great video thanks! does it work also for 3.3v signal from eg ESP8266 ?
@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.
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
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
Nice discribed. Thank you.
@IndrekL
4 жыл бұрын
Thank you for the feedback!
Bro can you explain Why you connected 12 volt to power arduino 5v pin pin
@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
4 жыл бұрын
@@IndrekL thanks broo.. It was really helpfull
@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!
Good video!
@IndrekL
4 жыл бұрын
Thanks!
what is the model of the channel p mosfet used in the video?
@IndrekL
3 жыл бұрын
I used a IRF9540N
@CURIOSIDADEOUCRIATIVIDADE
3 жыл бұрын
@@IndrekL ok obrigado
You use 12volt battery and how many amperes?
@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
3 жыл бұрын
How many volt that the mosfet need to on the gate?
@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
3 жыл бұрын
Okay bro thanks👍
How much current does the motor consume?
@IndrekL
4 жыл бұрын
Hey! I don't remember exactly. It might have been somewhere around 1A
@BegginersGuidetoCode
3 жыл бұрын
12V @ 0.1A
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
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.
12V into arduino 5v output ??? what the hell !
the diode
my adafruit esp32 feather died, i guess i did something wrong, rip im broke, so much for this robotics bs, back to reddit
This is sending 5v to a 12v motor
@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.
Indrek
"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!
hi Indrek what's your email or FB I have a few question ?