I'm attempting to get the simplest Arduino sketch to demonstrate the function of a P-Channel MOSFET (IRF9640PBF) shutting down the Arduino Uno. It's not working. Why? Here are the instructions I found as a result of searching the phrase "Shutting Down Arduino with MOSFET":
" Channel MOSFET Setup* : Connect the Drain of the P-channel MOSFET to the power supply (Vin) of the Arduino. Connect the Source to the Vcc (5V) of the Arduino. The Gate is connected to a digital output pin of the Arduino through a pull-up resistor. When the digital output pin is LOW, the MOSFET turns off, cutting power to the Arduino. When the pin is HIGH, the MOSFET stays on, and the Arduino remains powered."*
The Arduino Uno is connected to my laptop via USB. I'm expecting the "On" green power LED to turn off indicating no power to the Arduino. Is that the right expectation?
It's always helpful so show us a schematic of what you built so we don't have to draw it or try to visualize it...
Don't believe everything you read.
There are "good reasons" that N-channel MOSFETs are more-often used.
A P-MOSFET can the turned-on by pulling the gate low while the source remains high (the gate negative relative to the source). If you are trying to switch the voltage on the source, you may be able to understand why it's not working... If the source could go low you no longer have any Vgs.
You also need a "logic level" MOSFET so it can be turned-on with only 5V Vgs.
Thank you for the prompt reply. Pardon my ignorance as I have these questions:
Per advice on this forum to save batteries, I was advised a P-CHANNEL MOSFET was the way to go. You are suggesting the N-CHANNEL so I'll lok into that option.
Isn't that what digitalWrite(7, LOW); does?
Can you please be more specific? Based on the code in the original post, what should I change?
Mostly likely, incorrect circuit and/or incorrect choice of MOSFET (the IRF9640PBF is not a logic level MOSFET, and requires Vgs = -10V to be fully turned on).
Post a schematic diagram, with pins, parts and connections clearly labeled. Hand drawn is fine.
There are many ways to skin a cat... I wanted to keep the MOSFET usage question as simple as possible which is why I posted the code in the original post. It was simple. But some context may be appropriate ...
I am lighting a 5v LED using 2 18650 batteries in series. The code turns the LED off at 6.2v but the battery ends up destroyed because it continues to loose voltage. The simplest an best solution to this use case was the recommendation to use a P-Channel MOSFET. I have been trying to get it to work in it's absolute simplest form which triggered the original question.
I am thankful for the replies but I would like to understand why the original code and connection description is not working. I understand the use of a schematic, but the code and connection description is so simple (and I don't know how) that it doesn't seem that a schematic would be necessary
For Q1 to be off Dn must be high. Dn cannot be high when Q1 is off because there's no power to the Uno to make it high. You might respond that R1 makes the gate high, but that won't work because R1 will be connected to the Uno's 5V power connection via Dn's protection diodes. This will attempt to power the Uno, but probably won't supply enough current so the gate will be low and Q1 will turn on, powering the Uno.
You cannot do this with 1 transistor of any kind, you need 2.
Right, forgot about the path through the diodes.
Actually it does work (just tried it) not sure why but it does violate my rule of having a powered device connected to an unpowered Uno.
No, it might go flat, but it won't be destroyed... unless... you forgot to either use batteries with over-discharge protection circuits built-in (most 18650 don't, but you can find them) or an external over-discharge protection circuit.
Li-ion batteries should be treated seriously and with respect, or... fires and explosions. Not a joke.
See post #5. If you haven't heard yet about logic level MOSFETs, do some research to learn how MOSFETs work, and what gate, source and drain voltage differences mean for their action. A useful search phrase is "P-MOSFET high side switch schematic".
There is not enough information in your minimal text description of the circuit to determine if there are other problems.