2
\$\begingroup\$

I have a Raspberry Pi Zero which I want to be able to power on/off via code, so I made this circuit:

Schematic

simulate this circuit – Schematic created using CircuitLab

I would like to avoid powering the Raspberry Pi directly through the GPIO pins, so I chopped a micro USB cable up and connected its 5 V to my power supply (later on it will be a battery, but for now is a phone charger). The rest of my circuit is also powered through the same power supply. The signal to the gate is supplied from another microcontroller which also operates at 5 V. I added an LED just to aid in troubleshooting.

When I apply the 5 V signal at the gate the LED lights up, then I plug in the micro-USB in the Raspberry Pi's PWR slot and the LED turns off. Needless to say, the Raspberry Pi is not powering up. If I leave it plugged in, after about 5 - 10 seconds the LED flashes really quickly, and if I unplug the Raspberry Pi the LED glows back up after the same time period.

I measured the supply voltage in the circuit while the Raspberry Pi is plugged in and it stays at 5 V. I also measured the voltage at the gate which is 5 V without the Raspberry Pi plugged and drops to 0 V (20 mV to 150 mV, I don't know if that's an issue with my multimeter or something) as soon as I plug it in.

The Raspberry Pi's ground is connected to the circuit ground only through the MOSFET, although there are I²C and SPI connections to other devices, which I wasn't sure would work and was something I was hoping to test, short of knowing I wouldn't even be able to power the Raspberry Pi on. I'm mentioning that because I'm trying to be as exhaustive as possible to aid anyone who's willing to help me out.

\$\endgroup\$
10
  • \$\begingroup\$ Is the 5V on R2 coming from V1? It should stay at 5V throughout. Meanwhile, switching low side (ground) for power breaks ground or always connected, does not work. \$\endgroup\$
    – jay
    Aug 29, 2021 at 19:09
  • \$\begingroup\$ @jay yes, everything is powered from a single supply. \$\endgroup\$
    – php_nub_qq
    Aug 29, 2021 at 19:10
  • 3
    \$\begingroup\$ Switching GND is not a great way to control power to downstream stuff. Although you may get this to work, it's sort of going off-road. You would be way better off IMO using a P-Channel FET and switching the high side VCC. Do you need more details? \$\endgroup\$
    – Randy Nuss
    Aug 29, 2021 at 19:17
  • 1
    \$\begingroup\$ Exactly, I see now, " gate goes to zero". Possibility is, assuming the grounds are solid: R2 >> R1, micro-usb-gnd <-> through some other circuitry <-> to ground" That will pull the gate down through the M1 body diode. You may try a resistor in place of pi. Meantime, Once you switch ground off, the control unit lose reference (gnd) with pi, leak through high-side and signal. If they get connected on ground, the switch does not work at all, or intermittent (AC/cap coupling), Do not switch the ground. \$\endgroup\$
    – jay
    Aug 29, 2021 at 19:21
  • 1
    \$\begingroup\$ @user253751 I agree 100 % with your comment. In this case there was mention of other busses and complexities not fully explained which is why I was merely trying to steer OP away from GND switching. There are plenty of low RDs ON P-channel MOSFETs available so losses should not be a concern using a high side switch. But as you say, GND switching is a perfectly valid way to switch a well understood load. \$\endgroup\$
    – Randy Nuss
    Aug 30, 2021 at 12:27

3 Answers 3

6
\$\begingroup\$

I was trying to understand what your circuit does, but I couldn't. I get what you're trying to achieve tho.

First of all, you need to connect ground of supply to ground of pi. Basically, whatever you connect, grounds must be connected directly so that all other voltages are relative to it (since voltage in its own is a relative thing and "relative to ground" is just the default interpretation of it).

Second of all, you need a single p-channel mosfet as a high side switch.

The circuit looks like this: enter image description here

Where R is your 10k/20k/100k; you also have a tiny resistor along the gate control, so put it there too; Load is your Pi. Also, notice that the pullup R is powered from the same micro usb's 5V.

Found another picture of identical circuit (+5V is your micro usb 5V, grounds connected together as always; ignore the flyback diode, it's protection from voltage spikes for inductive loads, irrelevant for pi):

enter image description here

And you can power the LED diode from before or after the MOSFET; if you power it from 5V after the MOSFET, it will be on/off indicator, if it's before the mosfet, it will be always on whenever the cable itself is powered.

EDIT: if you want to control high voltage rail with low voltage logic, you will have to use 2 mosfets. Here is a standard circuit you can find in any phone or laptop that does exactly that (n-channel controls the gate of p-channel without connecting your 5V to 12V directly; where you see "5V" here, should be 12V, and GPIO is, well, your GPIO, can be 5V or 3.3V or anything as long as N-channel mosfet can be operated):

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ I couldn't understand exactly why it's not turning on but okay, I'm going to try high side switching. Just a quick question: if supply voltage is 12v I would not be able to directly sink it as shown in your schematics, right? \$\endgroup\$
    – php_nub_qq
    Aug 29, 2021 at 20:53
  • \$\begingroup\$ And another quick question, why do I need a pull up resistor, isn't my pin going to be configured as output and provide the 5v (HIGH) signal? \$\endgroup\$
    – php_nub_qq
    Aug 29, 2021 at 20:59
  • 2
    \$\begingroup\$ As for pullup, I'll make a little addition, you might still wanna have one, as it sets the default state for the line and prevents it from floating during startup or just if your GPIO that is supposed to control it is not set to output (yet). A good practice to set some default state. It barely consumes any power, but if you're aiming at microamps, even 100k should work just fine \$\endgroup\$
    – Ilya
    Aug 29, 2021 at 21:50
  • 1
    \$\begingroup\$ I just wired it and it works perfectly. I got an IRF9540 and it's not even slightly warming up, which is awesome. The uC pin is not sinking any current, right? Should I take this into account when calculating the sink current across the entire chip? \$\endgroup\$
    – php_nub_qq
    Aug 30, 2021 at 14:14
  • 1
    \$\begingroup\$ technically speaking, whatever is sunk/sourced has to go through your pullup or pulldown resistor, which is probably not less than 10k, which means it's well under half a milliamp or less, you can safely ignore it for these calculations. If you have a pullup, you sink when output low, and whenever you have a pulldown, you source when you output high (since resistor connects two points with different voltage, therefore, there must be current) \$\endgroup\$
    – Ilya
    Aug 30, 2021 at 14:18
2
\$\begingroup\$

When there are many shared grounds with IO cables, power and peripherals, you need a high side switch with more capacity than your load.

This can be single chip or the inverse of your design.

\$\endgroup\$
0
\$\begingroup\$

I think there is a discrepancy between the schematic and the actual circuit you have built, or your MOSFET is defective. The LED switching off when you connect the Pi suggests that there is a 3+V voltage drop on an open MOSFET, which is pretty much impossible.

I also measured the voltage at the gate which is 5V without the Pi plugged and drops to 0V (20mV~150mV, I don't know if that's an issue with my meter or something) as soon as I plug it in.

Here you have it - this cannot happen with your schematic, yet you measure it. If you don't provide 5V at the gate, your MOSFET closes and the Pi is not getting powered.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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