0

How can the presence of a 5V output from a USB charger be detected using a Raspberry Pi?

Scenario: My Raspberry Pi is powered by a (USB) powerbank which is continuously being charged by a dual-port (USB) wall-charger plugged into the mains [this setup serves as a mini-UPS for the Pi].
One port of that wall charger supplies the powerbank, while the other is unused.

Problem: I would like to detect when the mains supply is off, using the Pi.

Potential solution: Since one of the 5V outputs on the wall-charger are unused, maybe I can interface that to the GPIO pins on the Pi to let it know when the mains is off.
I know that the Pi's GPIO runs off 3.3V logic, so I assume a simple voltage-divider like this will be required.
Are there additional precautions that need to be taken? Any other suggestions to achieve the same goal?

Any help would be appreciated.

Islay
  • 113
  • 4

1 Answers1

1

A simple voltage divider will "work". But how much do you trust your charger, and how much do you value your Pi?

A capacitor in parallel with either resistor helps to the stabilize the sensed voltage, which protects from short voltage spikes. (A capacitor across the upper resistor will in fact INCREASE the transient voltage - if you must do this connect to Ground.)

For longer surges, a Zener diode can give extra protection. But to prevent it from frying as well, you will need a fuse. I.e. if your Zener limits the input to 5.6V and can dissipate 1W, your fuse should be rated at 178 mA.

Milliways
  • 62,573
  • 32
  • 113
  • 225
MSalters
  • 171
  • 5