I have a (maybe trivial) problem.

I want to power a Raspberry Pi (more specific a SteroPi) with a power bank. The power bank has the feature, that its output is always on. So even if I plug in a charger, the output will stay on. For my project, I need the Raspberry Pi to shut down when the power bank is charging, and power on if the charging cable gets disconnected ("Airpods like"). I know there are power banks that have that feature, but I have not found any that fits the size I need (need one with the size of 2x 18650 batteries). Also, it is very difficult to search for this specific feature, as simply no manufacturer points that feature out in it's description. (If anybody knows a power bank with this form factor and functionality, please tell me :D)

What I tried till now:

I connected the 5V pin to a GPIO through a voltage divider and polled that with a script on the raspberry pi to shut it down (sudo shutdown -h now) if 5V are present. This is working great, but the Raspberry Pi gets into something like a "bootloop": The power bank seems to cut the power off for a short time when the raspberry pi is off but turns back on immediately after that, that restarts the pi, but the pi is powering down again because the 5V are present on the charging port. And so on, and so on...

So my next idea is to hard cut the power of the Raspberry Pi if the power bank is charging, so it has no chance to reboot. For that, I need a simple circuit (maybe something with a transistor/MOSFET) that is directly controlled by the 5V charger pin (cuts power if 5V are present and turns it back on if the 5V are gone). Does anybody have an idea, how such a circuit could look like, or has the other approach?

Solved the first problem by switching the micro USB cable from the power adapter to the power bank. Now there isn't a bootloop anymore. Also, I replaced my script that polls the pin by modifying the /boot/config.conf like M. Rostami mentioned in the comments. This is a much easier and cleaner solution. Thanks!

  • 3
    this appears to be an XY problem ... why do you need to do this?
    – jsotola
    Jan 9, 2020 at 17:30
  • 2
    For the part before the problem that you said, another idea is that you can change the boot state on /boot/config.conf.However, this link would be helpful. raspberrypi.org/forums/viewtopic.php?t=175161#p1117946
    – M. Rostami
    Jan 9, 2020 at 22:37
  • 1
    Okey, I soved the first problem. It was the cable from the charger to the powerbank, that leads to the bootloop! I changed it and it workes like a charm. And thanks to @M.Rostami. I switched from my originally created script that runs in the background to the /boot/config.conf solution. This is much simpler! And @jsotola: I want to shut down my raspberry pi while charging, to faster charge the battery, and to generally save power
    – fshero
    Jan 10, 2020 at 10:55
  • Gladly. Please add this new information to the question as an "UPDATE".
    – M. Rostami
    Jan 10, 2020 at 11:27

1 Answer 1


You can use a high side switch with a mosfet and control it with the power bank's charge input, just like you wrote.

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.