Low Battery Detection

A project log for guerillaClock

Community Based Solution for a Municipal Problem

klinstifenklinstifen 04/07/2018 at 20:511 Comment

After a few unexpected shutdowns, due to low battery power, that resulted in SD card corruption (specifically Git cache corruption) I decided to take advantage of the LBO pin on the PowerBoost 1000c.

The LBO pin will go to 0V when the battery voltage drops below 3.2V.  We can utilize a GPIO pin on the Raspberry Pi Zero W to monitor the LBO pin state and then initiate a system shutdown when the LBO pin goes low. 

I selected GPIO pin 21 simply because it was at the end of the bonnet and out of the way.

Adding a male pin to the PowerBoost 1000c and a female jumper cable to the bonnet allows for easy disassembly if components need to be replaced.

To configure pin 21, we need but a few lines of code at the beginning of the script

#LBO shutdown PIN
PIN = 21
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

And finally, at the end of the main loop we check the current state of the LBO pin and shutdown the system if necessary.

#Check for low power
if not GPIO.input(PIN):
  logger.debug("Low Battery Power Detected.  Shutting down...")
  os.system("sudo shutdown -h now")


karla wrote 07/19/2019 at 18:20 point

Hello! Did this code actually work for you? And what pin is the enable pin wired to?

  Are you sure? yes | no