Electrical – Mosfet battery switch

batteriesmosfetraspberry piswitches

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.

Best Answer

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