I'd like to create a backup power solution for my Raspberry Pi, and I'd like a notification to come up that the Raspberry Pi is running on this backup power. This notification has to tell me that something happened and I'm running out of time.

Can I detect power coming in through GPIO rather than USB?

  • What will happen if you have power on GPIO and USB? Hmmm. N0thing?
    – Piotr Kula
    Sep 20 '12 at 11:54

As far as I know, you can't.

But by using some very simple electronics you can. The most simple and straight forward option is to use 2 GPIO pins as input (one for each power supply).

Connect both power supplies (besides to their normal connection to actually supply the power) through some resistors (for safety and voltage level adjustment!!) to these GPIO pins.

In the software you just read both pins. If both are '1' (so 5V or 3.3V), both power supplies are working fine. If one these input pins is a '0', the connected power supply is switched off and you can take appropriate action in your software.

More variations are available, on this very basic version, that only use one GPIO input pin, but the needed external electronic components will become slightly more complex.

Note: Supplying power over the GPIO has some risks because the solid state fuse is by-passed, so at least you will need to use some shortage protection in the alternative power supply connection.

This little schematic below should do the job, you'll need two of these (one for each power supply)

A little schematic for the detection if a power supply is working

Before connecting these to your Raspberry Pi, measure the output voltages for the Raspberry and for the GPIO pins, the 1N4001 diodes normally have a voltage drop of around 0.7V but this diode being an general purpose diode they are not very precise. The voltage for the Pi should not exceed 5V and for the GPIO pin should not exceed the 3.3V.

By changing this schematic and using a voltage regulator LM317 (and giving it the correct resistor values on the ADJ pin , you can connect an 'off the shelf' power supply again), but this requires more components. This 'off the shelf' power supply can be 7.5V or 9V.

Different version using LM317

The LM317 needs 2 capacitors that are not in this schematic, please check the datasheet of the LM317 for these.

  • Yes, I'm still a little unclear. Do I use 2 GPIO pins as ground? Can you post the schematic if it's much trouble?
    – User7391
    Sep 20 '12 at 4:59
  • 1
    Both GPIOs will read the same value unless you isolate the two power supplies with diodes. The additional voltage drop of the diodes might cause reliability problems Sep 20 '12 at 5:02
  • I'll create some little schematic later today, but gnibbler is right, some diodes are needed so we must compensate for the voltage drop, meaning that you cannot use 'of the shelf' USB power supplies anymore.
    – ikku
    Sep 20 '12 at 12:54
  • Excellent schematics. I'm curious, what program did you use to make them?
    – User7391
    Sep 20 '12 at 18:45
  • These were done using gEDA, just for this time, normally I use KiCad.
    – ikku
    Sep 20 '12 at 19:52

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.