Running a Pi Zero on Battery: Power Options, Runtime and Saving Tips
The Pi Zero family uses less power than any other Linux-capable Raspberry Pi, which is why it appears in so many portable projects: wildlife cameras, handheld gadgets, field data loggers and wearable devices. Running from a battery, however, raises questions a wall adapter never does. How long will it last? How do you avoid SD card corruption when the battery runs flat? Which settings actually reduce consumption?
This tutorial covers the practical answers: the common battery arrangements, how to measure current and calculate runtime properly, the config.txt and system settings that cut power, and a safe shutdown button plus a low-battery shutdown script.
Measure, Then Calculate Runtime
Published consumption figures vary with OS version, Wi-Fi activity and attached hardware, so measure your own setup. Put an inexpensive USB power meter between the supply and the Zero, then note the current while idle and while your program does its real work. Battery capacity is quoted at the cell voltage, so convert to energy before dividing.
Battery energy (Wh) = capacity (Ah) x nominal cell voltage (V) Usable energy (Wh) = battery energy x boost efficiency Load power (W) = 5 V x measured current (A) Runtime (h) = usable energy / load power Example with values you measured yourself: 2000 mAh cell, 3.7 V nominal -> 2.0 x 3.7 = 7.4 Wh boost converter efficiency 85 % -> 7.4 x 0.85 = 6.29 Wh meter shows 0.20 A at 5 V -> 1.0 W runtime -> 6.29 / 1.0 = about 6.3 h
A common mistake is dividing 2000 mAh by 200 mA and expecting 10 hours. That ignores the voltage conversion from 3.7 V to 5 V and the converter losses, and overestimates runtime considerably. Also derate the result for an ageing cell and for cold weather.
Settings That Reduce Power Use
Disable every block of hardware your project does not use. Add the lines below to /boot/firmware/config.txt and reboot, then measure again so you know what each change was worth on your board.
# Turn off the activity LED (Pi Zero family: the LED is active-low)
dtparam=act_led_trigger=none
dtparam=act_led_activelow=on
# Disable Bluetooth if unused
dtoverlay=disable-bt
# Disable Wi-Fi if the device logs locally and never needs a network
# dtoverlay=disable-wifi
# Change the existing dtparam=audio=on line to off if no audio is used
dtparam=audio=off
# Do not probe for a camera if none is fitted
camera_auto_detect=0
- Fewer cores on the Zero 2 W: adding
maxcpus=1to the single line in/boot/firmware/cmdline.txtlimits Linux to one core, lowering peak current for light workloads. - Stop unused services: for example
sudo systemctl disable --now bluetoothand any service you installed for testing. - Avoid busy loops: use event callbacks,
time.sleep()and systemd timers so the CPU stays idle most of the time. - Group network activity: collect readings locally and send them in batches rather than keeping a connection constantly busy.
- Remove USB devices: hubs and adapters on the OTG port draw power even when idle.
- Wi-Fi power management: check with
iw wlan0 get power_save. Turning it on saves power but can delay incoming connections.
Linux on the Zero cannot enter a deep sleep that draws microamps, the way a microcontroller can. For devices that only need to work for a minute every hour, a much bigger saving comes from cutting power completely with an external timer board, such as one based on the TPL5110, that switches the Zero on and cuts the supply when it receives a done signal. The gpio-poweroff overlay can drive a GPIO pin high once Linux has fully halted, which is a convenient source for that signal.
Safe Shutdown Button and Low-Battery Shutdown
Cutting power while Linux is writing can corrupt the SD card. A built-in overlay turns a button on GPIO3 into a shutdown button, and the same button wakes the board from the halted state. Add dtoverlay=gpio-shutdown to config.txt and connect a push button between physical pin 5 (GPIO3) and pin 6 (GND). GPIO3 is also the I2C clock line, so if you use I2C, choose another pin with dtoverlay=gpio-shutdown,gpio_pin=21; only GPIO3 can wake the board.
Many charger-boost modules have a low-battery output that goes low when the cell is nearly empty. The script below, run as root from a systemd service, shuts the Zero down cleanly when that happens. Make sure the signal never exceeds 3.3 V before connecting it to a GPIO.
#!/usr/bin/env python3
"""Watch a low-battery signal and shut down safely. Run as root via systemd."""
import subprocess
from signal import pause
from gpiozero import DigitalInputDevice
# GPIO26 (physical pin 37). pull_up=True: the pin reads 'active' when the
# open-drain low-battery output pulls it to GND. bounce_time ignores glitches.
low_batt = DigitalInputDevice(26, pull_up=True, bounce_time=2)
def shutdown():
print('Low battery detected, shutting down')
subprocess.run(['shutdown', '-h', 'now'])
low_batt.when_activated = shutdown
if low_batt.is_active: # battery already low at boot
shutdown()
pause()
Common Problems
- Random reboots on battery: voltage dips under load. Run
vcgencmd get_throttled; bit 0 set means under-voltage now, bit 16 means it happened since boot. Use a stronger boost module and short, thick cables. - Power bank turns off after a while: the load is below its auto-off threshold. Use a bank with an always-on mode or a dedicated LiPo module.
- Corrupted SD card after the battery died: add the low-battery shutdown, and consider the read-only filesystem described in this series.
Summary
Battery-powering a Pi Zero comes down to a proper 5 V boost supply, runtime calculated from measured current with voltage conversion and losses included, disabling unused hardware in config.txt, and always shutting down cleanly. For very long life with occasional work, switch the Zero off completely between jobs with an external timer.