UPS HAT for Raspberry Pi
Battery backup HAT keeping a Pi running through power loss.
Wiring & code for
UPS HAT practical reference
An uninterruptible power supply HAT that seamlessly switches a Raspberry Pi to battery power during outages, common in always-on home servers. It sits between the main power source and the Pi's power input, continuously trickle-charging an onboard Li-ion/LiPo battery while mains power is present, and instantly switching over to battery when power is lost — keeping projects like home automation hubs, network-attached storage, or security camera servers running through brief outages, or at least allowing a graceful shutdown before the battery depletes.
Key specifications
- Form factor: Raspberry Pi HAT — mounts directly on the 40-pin GPIO header, matching standard Pi board dimensions
- Input power: 5 V via micro-USB or USB-C, or direct DC barrel input depending on model
- Output power: Regulated 5V to the Raspberry Pi via the GPIO header pins (bypassing the Pi's own USB power input)
- Battery: Single or dual-cell Li-ion/LiPo (18650 cells are common), charge-managed onboard
- Switchover behavior: Automatic, near-instantaneous switch to battery power on mains loss with no reboot of the Pi
- Monitoring: Many models expose battery voltage/percentage over I2C so software running on the Pi can log status or trigger a graceful shutdown before battery depletion
- Backup runtime: Model and battery-capacity dependent, commonly tens of minutes to a few hours depending on Pi model and attached peripherals
Pinout and connection notes
Because most UPS HATs deliver power through the GPIO header rather than the Pi's normal USB/barrel power input, they typically require running the Pi's official low-voltage warning to be disabled or reconfigured, and it's worth checking whether the specific HAT model leaves the rest of the 40-pin header accessible for stacking other HATs. Battery status is usually read over I2C so a background script can trigger a clean shutdown before the battery is fully drained.
- 40-pin GPIO header (pass-through): Mounts on and passes through the Pi's GPIO header, supplying regulated 5V power while typically leaving GPIO pins available for other HATs/wires
- Battery terminals: Connection points for the onboard Li-ion/LiPo cell(s), usually via a JST connector or solder pads
- Power input (micro-USB/USB-C/barrel): Main 5V power input from the wall adapter
- I2C (SDA/SCL, via GPIO pass-through): Used by many UPS HATs to report battery voltage/capacity to software running on the Pi
Integration checklist
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.
Troubleshooting and reproducibility
Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.