To build a reliable raspberry pi battery backup for a Raspberry Pi 5 (peak 25W, average 15W continuous load) that lasts 12 hours, you need a 12.8V 20Ah LiFePO4 battery paired with a 90% efficient 12V-to-5V 6A buck converter. While off-the-shelf UPS HATs offer plug-and-play convenience for short outages, custom LiFePO4 (Lithium Iron Phosphate) packs provide the cycle life and thermal stability required for remote, off-grid, or critical edge-computing deployments.
The Anatomy of a Raspberry Pi Battery Backup System
A robust DC-coupled backup system avoids the massive efficiency losses of converting DC battery power to AC, only to step it back down to 5V DC via the Pi’s official power supply. Instead, we use a direct DC-DC architecture.
System Block Description: Source to Load
- Primary Source: AC Mains (via a 14.6V DC power supply) or a Solar Panel array (via an MPPT charge controller).
- Energy Storage: 4S (4-series) LiFePO4 battery pack (12.8V nominal, 14.6V fully charged).
- Protection & Management: A 4S BMS (Battery Management System) handling cell balancing, over-current, and short-circuit protection.
- Voltage Regulation: A high-efficiency synchronous buck converter (e.g., Pololu D24V60F5) stepping 12.8V down to 5.1V.
- Load: Raspberry Pi 5 USB-C PD input.
Series vs. Parallel: Consequences for Voltage and Ah
When building or specifying a battery pack, the physical arrangement of the cells dictates your DC-DC converter topology:
- Series (S): Increases voltage, keeps Amp-hours (Ah) identical. A 4S LiFePO4 pack yields 12.8V nominal at the Ah rating of a single cell. This is ideal because stepping 12.8V down to 5V via a buck converter operates at >90% efficiency.
- Parallel (P): Keeps voltage identical, multiplies Ah. A 4P pack yields 3.2V nominal. Stepping 3.2V up to 5V requires a boost converter, which suffers from high inrush currents, lower efficiency (~80%), and severe voltage sag under the Pi 5’s 5A peak transient loads.
Rule of thumb: Always design the battery pack voltage to be higher than the Pi’s 5V requirement, then buck it down. Never rely on boosting from a single-cell (1S) 3.7V Li-ion pack for a Pi 5.
Charge/Discharge Limits: C-Rates and Depth of Discharge
LiFePO4 chemistry is forgiving, but pushing it to absolute limits destroys cycle life. For a 20Ah pack:
- Charge C-Rate: Standard is 0.5C (10A charge current). Charging at 1C (20A) generates excess heat and degrades the cathode.
- Discharge C-Rate: Standard is 1C (20A). The Pi 5 draws a maximum of 5A at 5V (25W). On the 12.8V side of the buck converter, assuming 90% efficiency, the battery supplies roughly 2.1A. This is a mere 0.1C discharge rate for a 20Ah pack, meaning the battery will run exceptionally cool and last for thousands of cycles.
- Depth of Discharge (DoD): While LiFePO4 can physically discharge to 2.5V per cell (100% DoD), limiting the BMS low-voltage cutoff to 2.8V per cell (80% DoD) doubles the calendar life of the pack.
Sizing Math: From Load Watts to Battery Amp-Hours
Sizing a battery is not as simple as dividing watt-hours by voltage. You must account for converter efficiency, DoD limits, and Peukert’s Law.
The Calculation (Target: 12 Hours Runtime)
- Base Load Energy: 15W (average Pi 5 load with USB peripherals and WiFi) × 12 hours = 180Wh.
- Converter Efficiency Penalty: A quality synchronous buck converter operates at ~90% efficiency under this load. 180Wh / 0.90 = 200Wh required from the battery.
- Depth of Discharge (DoD) Penalty: To ensure a 10-year lifespan, we restrict DoD to 80%. 200Wh / 0.80 = 250Wh total required battery capacity.
- Amp-Hour Conversion: 250Wh / 12.8V (nominal pack voltage) = 19.53Ah.
Selection: You would purchase or build a 12.8V 20Ah LiFePO4 battery.
Why Peukert’s Law Matters (and Why Lead-Acid Fails Here)
Peukert’s Law describes how a battery’s effective capacity drops as the discharge current increases. The formula is $t = H (C / I)^k$, where $k$ is the Peukert exponent.
- Sealed Lead Acid (SLA): Has a $k$ value of ~1.3. If you pull high transient currents (like a Pi 5 booting up and spinning a mechanical hard drive), an SLA battery’s usable capacity plummets. Furthermore, SLA batteries suffer from severe voltage sag, often tripping the Pi’s brownout detection before the battery is actually empty.
- LiFePO4: Has a $k$ value of ~1.05. The effective capacity remains virtually flat regardless of the C-rate, making it the only viable chemistry for compact, high-reliability embedded backups.
Inverter and Charger Sizing
If you are using an AC-coupled setup (e.g., a standard 120V AC UPS feeding the Pi’s official 27W USB-C power supply), your inverter/charger must be sized for the peak load, not the average. The Pi 5 can transiently pull 5A (25W). Add 20% overhead for the AC power supply’s own inefficiency and inrush current. Your UPS must be rated for at least 40W continuous / 60VA. However, cheap modified-sine-wave UPS units often output dirty power that causes the Pi’s official power supply to reject the voltage via its internal I2C PMIC check, resulting in boot loops. Always use a pure sine wave UPS or, preferably, the DC-coupled method described above.
Hardware Selection: UPS HATs vs. Custom LiFePO4 Packs
Choosing between an integrated HAT and a custom pack depends on your deployment environment and maintenance tolerance.
| Criteria | Integrated UPS HAT (e.g., Geekworm X1202, PiJuice) | Custom 12V LiFePO4 + Buck Converter |
|---|---|---|
| Max Runtime | 1-4 hours (limited by 18650 cell physical space on HAT) | 12-72+ hours (scalable via external battery sizing) |
| Chemistry | Typically Li-ion (NMC) 18650s | LiFePO4 (Prismatic or Cylindrical) |
| Thermal Risk | Moderate (Li-ion thermal runaway if BMS fails) | Very Low (LiFePO4 is chemically stable) |
| I2C Integration | Built-in (pre-configured shutdown scripts) | Requires external I2C ADC (e.g., ADS1115) to read voltage |
| Best Use Case | Desktop dev, short grid flickers, portable projects | Remote weather stations, off-grid gateways, telecom racks |
⚠️ Lithium Fire-Safety & Cell Matching Callout
If you are building a custom pack using raw Li-ion (NMC) or LiPo cells, never parallel mismatched cells. Cells with differing internal resistances or state-of-charge (SoC) levels will cross-charge each other at uncontrolled currents, leading to thermal runaway and venting fires. Always use a BMS with active cell balancing. For embedded systems left unattended in enclosures, LiFePO4 is strongly recommended over Li-ion due to its oxygen-rich olivine structure, which prevents the cascading thermal runaway characteristic of NMC chemistries. Always house raw cells in fire-retardant enclosures and fuse the main positive lead within 2 inches of the terminal.
Frequently Asked Questions
How long will a 10000mAh power bank run a Raspberry Pi 5?
A standard 10,000mAh USB power bank operates at a nominal 3.7V, yielding 37Wh of total energy. However, the internal boost converter stepping 3.7V up to 5V for the USB output is typically only 80% efficient. This leaves ~29.6Wh of usable energy. If your Raspberry Pi 5 draws an average of 15W (including peripherals), the power bank will last approximately 1.9 hours (29.6Wh / 15W). If the Pi is idling at 3W, it will last roughly 9.8 hours. Note that many cheap power banks will auto-shutoff if the Pi’s current draw drops below 50mA during sleep states, killing your backup.
Can I use a standard 18650 lithium-ion pack for a Pi UPS?
Yes, but with strict caveats. A 2S or 3S 18650 NMC pack can work, but NMC cells degrade rapidly if held at 100% State of Charge (SoC) in a float-charge scenario (which is exactly what a UPS does). If you must use 18650 Li-ion, configure your charge controller to terminate charging at 4.0V per cell (roughly 80% SoC) rather than the maximum 4.2V. This sacrifices 20% of your capacity but will triple the calendar life of the cells in a continuous float-charge environment. For true set-and-forget reliability, switch to LiFePO4, which tolerates continuous float charging at 13.8V without degradation.
What is the safest way to shut down a Pi when battery voltage drops?
Hard-cutting power when the battery hits the BMS low-voltage cutoff will corrupt the Pi’s SD card and filesystem. You must implement a graceful I2C shutdown trigger. If using a commercial UPS HAT, install the vendor’s I2C daemon (e.g., x1202.sh). If using a custom pack, wire an ADS1115 16-bit ADC to the Pi’s I2C bus to monitor the battery voltage via a voltage divider. Write a Python script running as a systemd service that polls the ADC every 10 seconds. When the voltage drops below your 20% DoD threshold (e.g., 12.2V for a 4S LiFePO4), the script executes sudo shutdown -h now. This ensures the filesystem is unmounted cleanly before the BMS physically disconnects the load.






