Raspberry Pi UPS: Best Backup Power Solutions and Setup Guide
April 23th, 2025

A UPS (Uninterruptible Power Supply) is a backup power system that provides electricity to a device when the main power source fails. It typically includes a rechargeable battery and circuitry that ensures a smooth transition from the main power to backup without interruption.
Raspberry Pi devices, especially when used for critical or continuous tasks (like servers, sensors, or automation hubs), lack built-in power loss protection.
Why Use a UPS with Raspberry Pi?
✔ Prevents Data Corruption:
Sudden power loss can interrupt file system operations and cause SD card corruption, leading to system instability or boot failures.
✔ Ensures Safe Shutdown:
A UPS allows your Raspberry Pi to safely shut down or trigger recovery actions when battery levels get low, protecting both hardware and software.
✔ Maintains Uptime in Remote or Critical Deployments:
If your Pi is part of a remote sensor setup, NAS, weather station, or smart home system, a UPS ensures it continues running even during power outages, maintaining data logging, network access, or automation functions.
✔ Supports System Monitoring & Recovery:
Advanced UPS systems let you monitor battery status and automate actions like logging events, sending alerts, or restarting after power is restored.
✔ Ideal for Headless or Portable Projects:
For Raspberry Pi setups without a display or keyboard (headless), a UPS provides peace of mind, ensuring system integrity in mobile or off-grid environments.
Types of Raspberry Pi UPS
There are several types of UPS options available for the Raspberry Pi, each with its own advantages depending on your use case, budget, and technical comfort level.
HATs (Hardware Attached on Top)
HAT-style UPS boards are specifically designed to sit on top of the Raspberry Pi, connecting directly to the GPIO header. These are compact, efficient, and integrate well with Pi cases and stackable setups. Popular models like the PiPower 3, PiJuice HAT, Waveshare UPS HAT, and Geekworm X728/X750 offer features such as battery level monitoring, safe shutdown via I2C or GPIO, and real-time clock (RTC) modules. They are ideal for embedded systems, headless servers, or IoT devices that require tight integration and space-saving design.

External USB UPS Power Banks
These are the simplest to use and require no GPIO or software configuration. You plug a USB power bank with pass-through charging (also called “UPS mode”) into your Raspberry Pi, and it keeps the Pi powered during outages while charging when power is available. Although not as feature-rich as HATs, they’re great for portable setups, quick prototypes, or where shutdown automation isn't critical. Make sure to choose a power bank with fast switch-over times and sufficient output (at least 5V 2.5A for most Pi models).

Custom DIY Solutions
For advanced users, building a custom UPS offers maximum flexibility. This might involve combining a lithium battery pack with a Battery Management System (BMS), a boost/buck converter, and possibly a microcontroller (like an Arduino or ESP32) to monitor voltage and trigger GPIO-based shutdowns. This setup allows for creative designs, larger battery capacities, or even solar-powered Raspberry Pi systems. While powerful, DIY UPS systems require a strong understanding of electronics and power safety.
Key Features to Look For in a Raspberry Pi UPS

When choosing a UPS for your Raspberry Pi, it's important to look for features that ensure both reliable power backup and system safety. A quality UPS should provide seamless battery backup with automatic switching from main power to battery during outages. It should support safe shutdown capabilities, allowing the Pi to power off gracefully when the battery reaches critical levels. Monitoring features are essential as well; a good UPS offers real-time data on battery status, voltage, and charge levels—either via GPIO, I2C, or USB. Integrated rechargeable batteries, such as Li-ion or LiFePO4, offer a compact and efficient power source, with built-in protection circuits to prevent overcharging or deep discharge. Some models also include OLED displays, RTC (real-time clocks), or even programmable power schedules. Compatibility with Raspberry Pi cases and stacking with other HATs can also make a big difference in more complex setups. Lastly, look for software support, whether that’s through vendor-provided tools or community-maintained scripts, to ensure you can configure and manage your UPS effectively.
Installation and Setup Raspberry Pi UPS HAT

Hardware Installation
Enabling I2C/GPIO Communication
Begin by powering off your Raspberry Pi and disconnecting any power sources. If you’re using a UPS HAT (such as PiJuice or Waveshare), carefully align it with the GPIO header and press it down gently but firmly. Make sure the pins are correctly seated to avoid electrical faults.
If your UPS uses external connections (via USB or dedicated power cables), connect the input from your power supply to the UPS board and the output from the UPS to the Pi’s power port (usually USB-C or micro USB depending on your model).
Next, connect the battery (Li-ion or LiFePO4) to the UPS module as per the manufacturer’s instructions. Some HATs come with pre-soldered battery connectors or JST ports for easy setup. Be sure to use only supported batteries to avoid overvoltage or thermal risks.
Many UPS modules communicate with the Pi via I2C or GPIO pins. This step is essential for monitoring battery status and triggering safe shutdowns.
1. Boot up your Raspberry Pi and open a terminal.
2. Launch the Raspberry Pi configuration tool:
sudo raspi-config
3. Navigate to: Interface Options → I2C → Enable
Do the same for SPI or Serial if your UPS uses those interfaces.

2. Once Ollama is installed, download a compatible DeepSeek model:
ollama pull deepseek-r1:1.5b
This command fetches the 1.5 billion parameter version of DeepSeek-R1, which requires approximately 1.8GB of storage.

4. Exit and reboot the system to apply changes.
To verify that I2C is enabled and your UPS is detected, run:
sudo apt install -y i2c-tools
i2cdetect -y 1
You should see an address (like 0x14 or 0x36) corresponding to the UPS. If no address appears, double-check connections and power status.
For GPIO-based shutdown signals, ensure your shutdown script is set up to monitor the correct pin using Python, Bash, or a systemd service. Some HATs provide preconfigured scripts for this purpose.
Battery Monitoring and Management
CLI tools: Many UPS modules expose their data via I2C, which you can query using i2c-tools, upower, or custom Python scripts.For example:
i2cget -y 1 0x36 0x02
This command (with the appropriate I2C address) can return voltage or charge state, depending on the UPS.

GUI tools: For models like PiJuice, a graphical interface is available to monitor battery stats, configure shutdown thresholds, and view logs. These are useful for users running desktop environments on their Raspberry Pi.

Web Dashboard with Node-RED + MQTT + HomeAssistant (Visual Option)
Step 1: With Node-RED we can collect UPS data from I2C or GPIO.
Step 2: Send this data to an MQTT broker (local or cloud like HiveMQ, Mosquitto).
Step 3: Use HomeAssistant (on another server or the same Pi) to visualize battery voltage, charge %, and power events.
Example: https://github.com/dalehumby/PiJuice-MQTT

Scheduled Testing for Raspberry Pi UPS
Regular testing of your UPS setup ensures that it will perform as expected when a real power outage occurs. Scheduled testing helps you identify issues early—like failing batteries, weak connections, or misconfigured shutdown scripts—before they become critical.
What is Scheduled Testing?
It’s a planned, automated (or manual) process to simulate a power outage or evaluate battery behavior on a recurring basis. This includes:
• Testing the Pi's ability to switch to battery power
• Verifying that safe shutdown scripts trigger correctly
• Measuring battery discharge and charge times
• Logging system behavior during transitions
Best Practices for Scheduling Tests
1. Frequency: Test once a month or after major updates to the UPS setup.
2. Manual Testing: Unplug the power adapter and monitor how long the battery lasts. Observe if the system gracefully shuts down and boots back up when power is restored.
3. Automated Logging:
The cron job system should run a logging process at intervals of X minutes to retrieve voltage and current charge information.
Monitoring battery deterioration requires a comparison of test results accumulated over multiple time intervals.
Example: Simple Test Logger (Cron-Based)
Create a script battery_test.sh:
#!/bin/bash
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
voltage=$(i2cget -y 1 0x36 0x02 w)
voltage_swapped=$(( (voltage & 0xFF) << 8 | (voltage >> 8) ))
voltage_v=$(echo "scale=3; $voltage_swapped * 78.125 / 1000000" | bc)
echo "$timestamp, $voltage_v V" >> /home/pi/battery_log.csv
Make it executable:
chmod +x battery_test.sh
Schedule it with cron:
crontab -e
Add this line to log every 10 minutes:
*/10 * * * /home/pi/battery_test.sh
Use Cases and Application Examples

Best Practices for UPS Maintenance
Keep your UPS firmware and associated software or scripts up to date
Manufacturers often release updates that improve battery management, fix bugs, or add features. Regular updates ensure compatibility and stability.
Test the UPS periodically by simulating a power outage
Disconnect the main power to verify that the Raspberry Pi switches to battery and can perform a safe shutdown. This helps you confirm that the UPS is functioning as expected.
Monitor battery health regularly using available tools or scripts
Keep an eye on charge levels, voltage, and temperature. Over time, rechargeable batteries degrade, so replace them when capacity drops significantly.
Avoid exposing your UPS and battery to high temperatures.
Place your Raspberry Pi in a well-ventilated area, especially if it's enclosed in a case with other HATs or electronics.
Adjust the battery level sensor calibration if your UPS contains this feature.
This ensures accurate readings and helps trigger safe shutdowns at the right time.
Use high-quality batteries and compatible power adapters.
Cheap or mismatched components can lead to unstable operation or safety risks.
Schedule regular maintenance checks.
Include physical inspection of connectors, cleaning of contacts if necessary, and ensuring the system still aligns with your power backup needs.
Troubleshooting Common Issues
Raspberry Pi Shuts Down Unexpectedly
This usually indicates the battery is depleted, not charging, or the Pi is drawing more power than the UPS can supply. Check the power adapter rating—ensure it’s at least 5V 3A for Pi 4/5. Also verify that the battery is connected, charged, and not damaged or too old to hold a charge.
UPS Doesn’t Switch to Battery Power
If the Pi shuts off immediately when unplugged from mains power, the UPS might not be switching correctly. Inspect the battery connection and try powering the UPS directly from the battery to verify functionality. Some cheaper boards lack fast switch-over capability and may briefly cut power.
Battery Not Charging
If the battery stays at low charge even while plugged in, check the onboard charging circuit. Ensure no physical damage to connectors or charging components. Try a different USB-C/micro USB cable, and confirm the battery is within its expected voltage range (typically 3.7–4.2V for Li-ion).
Battery Drains Too Quickly
This could be due to peripherals (external drives, displays, etc.) pulling too much current. Try removing accessories and measuring battery runtime again. Also consider whether the battery capacity is sufficient for your setup—smaller packs won’t last long under high loads.
No Battery Monitoring Data
If i2cdetect shows no address or tools return errors, check:
• That I2C is enabled (sudo raspi-config)
• That the UPS is properly seated on the GPIO header
• Whether other I2C devices are conflicting
For GPIO-based status LEDs or shutdown triggers, ensure you’re monitoring the correct pins and that your script is active and executable.
UPS or Battery Overheating
If the UPS becomes hot to the touch or the battery swells, disconnect immediately. This may indicate overcharging, poor thermal dissipation, or a short circuit. Always use batteries and power supplies recommended by the UPS manufacturer.
Safe Shutdown Not Triggering
If your Pi keeps running until it loses power completely, verify:
• The shutdown script is running at startup (systemd, rc.local, or a cron @reboot job)
• The correct I2C values or GPIO pins are being monitored
• The threshold voltage for shutdown is configured properly
You can test the shutdown logic manually by simulating a critical condition.
Conclusion
Whether you're building a home automation hub, deploying a remote sensor, or simply running a headless Raspberry Pi server, adding a reliable UPS solution is essential for long-term stability and data protection. From HAT-based modules to simple USB power banks and DIY configurations, there’s a UPS option to suit every project and skill level. With proper installation, safe shutdown scripting, and regular battery monitoring, your Raspberry Pi can remain resilient even in the face of unexpected power outages. Investing in a UPS is not just about uptime—it’s about safeguarding the integrity of everything your Pi powers.