I am trying to power a Rpi project with a battery. Most of it is working fine but I would like to have a switch that allows me to disconnect the Pi from the battery because even when shutdown it draws some power. I have a mechanical switch to do that but to prevent any data corruption, I would like to bypass the switch as long as the GPIO 3.3V is up. So if anybody unlatches the switch by mistake when the Pi is on, it has no effect. Once the Pi shuts down safely and the GPIO is pulled down, the MOSFET should stop conducing and the switch position is effective again. My current circuit looks lie that (load : 12V to 5V converter + Rpi): enter image description here

The problem is that my MOSFET never shuts down. I think that's because once the switch is open, there is no common ground anymore and V_GS is always greater than the threshold.

My question is: Is it possible to do that with a MOSFET and if so, how could I set a common ground without having current flow closing the circuit? Would a diode do the trick?

Thanks in advance.


1 Answer 1


Consider using a high-side switching arrangement made from two transistors: -

enter image description here

When the MCU disables the N channel MOSFET the positive supply is dosconnected hence the logic control line from the MCU has nowhere to go except to 0 volts. Make R1 fairly low to guarantee a decent pull-down (=< 10 kohm).

  • \$\begingroup\$ Thank you for your answer. Just to make sure I understand correctly, let my summarize. - My switch would go over the P-channel MOSFET, connecting its D ad S. - When my logic is ON --> Q1 is ON --> V_GS2 < 0 and Q2 is ON, allowing current to flow into my MCU. - When Q1 is OFF --> V_GS2 is disconnected from the ground and is equal to 12V - RI --> Q2 is OFF and no current flows Is that right? I guess the value of R2 should be chosen so that V_GS2 is enough to shut Q2 OFF while still limiting current ? \$\endgroup\$ Jun 5, 2018 at 7:03
  • \$\begingroup\$ Yes, your analysis is correct. Sorry I forgot to mention the switch but you figured it. R2 can be circa 10 kohm. If you decide to power it from a supply higher than (maybe) 18 volts there will be some modification to prevent excessive gate source voltages on the PMOS. Choose the NMOS such that it readily turns on with a logic level of 3.3 volts. \$\endgroup\$
    – Andy aka
    Jun 5, 2018 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.