What happens to a Raspberry Pi when the power runs out? I was looking at ways to keep my Raspberry Pi running even if the power goes out, and using a UPS seemed like a good option. But the question came up as to whether a UPS was suitable for a Raspberry Pi, and whether or not I could use a power bank as an alternative. I put together this guide to help anyone in a similar situation figure that out.
A Raspberry Pi can be connected to a conventional UPS. The Raspberry Pi can be configured to receive a command from the UPS to shutdown gracefully in the event the UPS loses power. This allows the Raspberry Pi to save data and prepare itself in the event the UPS power runs out.
A conventional UPS is one that can power any electronic device in your house. These typically cost $145 to $230 and can provide backup power for 30 to 60 minutes. Many conventional UPS models come with a USB port that is used to send commands to a computer (including a Raspberry Pi) about the state of the power and remaining battery in the device.
Some UPS alternatives I’ve seen include a power bank configured as a UPS (needs a pass through function, and typically costs around $30 to $50), and a UPS hat specifically designed for Raspberry Pi (starts at approximately $20, but batteries are an additional purchase). I’ve included more details on these below.
In this guide I’ve looked at:
- Which UPS can be used to power a Raspberry Pi
- Can a power bank be used as a UPS (yes, but only some models)
- What happens to the Raspberry Pi when the power comes back on
- Which projects should use a UPS
Which UPS can be used to power a Raspberry Pi
Any UPS designed to work with household electronics can be used with a Raspberry Pi. If your UPS is designed to work with your home computer, router, WiFi, or other home electronics then it will work with Raspberry pi.
The Raspberry Pi typically connects to the UPS in the same way it connects to a wall socket – using a USB power supply, such as a phone charger (this is what I use). If the UPS has a USB socket for charging phones, the Raspberry Pi can be connected to this socket (note that many UPS models provide a USB port for sending data about the UPS status, I generally wouldn’t recommend using this one for powering the Raspberry Pi as it might not constantly supply power in the event of an outage).
The table below lists some of the UPS models for use with Raspberry Pi, along with an estimate of how long it can power a Raspberry Pi once the source supply has failed:
|Model||Backup Time (R Pi est.)||Cost (approx.)|
|APC UPS 1500VA||60 minutes||$160|
|CyberPower 1350VA||30 minutes||$230|
|Tripp Lite 900VA||50 minutes||$145|
The backup time in the table above is estimated based on how efficient the UPS is, and how much power the Raspberry Pi draws. I reckon you could squeeze more time out of it, particularly if you weren’t running many peripherals or hats from your Pi, particularly for the CyberPower. The above links are for Walmart, and these are affiliate links.
If you’re interested in how much power a Raspberry Pi typically uses, check out the experiment I conducted here: chipwired.com/raspberry-pi-power-use – given how little power it uses I was surprised the recommended UPS backup times were so low (I’d guess this is A) UPS suppliers being conservative with their estimates, and B) inefficiencies in the UPS supply).
Can I use a power bank as a UPS for my Raspberry Pi?
A power bank can only be used as an Uninterruptible Power Supply (UPS) for a Raspberry Pi if it supports simultaneous charging and discharging. This means that the power bank can (safely) be connected to a power source while simultaneously powering the Raspberry Pi – in this case it will work as a UPS for the Raspberry Pi.
Many power banks recommend you do NOT charge the power bank while it is being used to power something else, for safety reasons. I’ve often seen power banks with circuitry inside designed to prevent discharge of the battery while it’s being charged.
Even if you are able to charge and discharge at the same time, this should only be done if the manufacturer of the power bank says it’s ok. This consumer product safety website says that excessive heat generated from charging and discharging can be a safety hazard.
If you need a power bank to be used as a UPS, look for one that has a pass through circuit, or mentions specifically that it can be used for charging and discharging simultaneously.
A UPS hat can also be used to supply uninterruptible power to a Raspberry Pi. These are typically a rechargeable battery circuit with this pass through function designed to supply a Raspberry Pi with power from the batteries in the event the source is disrupted. As it’s a Raspberry Pi hat, it can communicate with the Raspberry Pi to command it to turn off in the event the batteries are getting low.
Some examples of UPS hats and power banks are in the table below:
|Anker PowerCore Fusion (power bank)||$30|
|Raspberry Pi UPS hat (from DFRobot) (battery sold separately)||$16|
|Pi UPS (from Pi Supply) (battery sold separately)||$25|
Power banks DO NOT guarantee uninterruptible power like a UPS does. In my experience, the power supply from a power bank is fine, but it’s not a guarantee that your Raspberry Pi won’t lose power (see below for projects where it’s not important, and how you can configure your Raspberry Pi to start working again once it’s turned on). The power bank link goes to Walmart and is an affiliate link.
Does the Raspberry Pi turn back on after power is restored?
A Raspberry Pi will turn on as soon as power is connected. If the Raspberry Pi has been setup in a headless configuration, it will resume running whichever apps it is programmed to as soon as power is restored and the operating system has finished booting.
As soon as the UPS has enough power to output its standard voltage, it will provide that to the Raspberry Pi which will turn on and boot the operating system again. Once the operating system has started, the Pi can (if configured to do so) resume running whichever application was running before the power went out.
This is typically part of a headless configuration – the Raspberry Pi is configured to start doing something without the need of a keyboard, mouse, monitor, or human input.
To setup a headless configuration:
- Follow this guide to setup a headless configuration with Raspberry Pi OS
- Install and configure the program(s) that you want to run once the Raspberry Pi has booted
- Follow this guide to setup cron such that the program runs automatically when the Raspberry Pi is booted
Do I need a UPS for Raspberry Pi
Raspberry Pi projects that will benefit from a UPS are those that you want to have high availability. This means that you want the Raspberry Pi to be running a service at any time you want to use it.
Examples of Raspberry Pi projects where a UPS would be helpful include:
- As a network router
- Collecting data
- Remote control for another device
In these projects, input for the Raspberry Pi can occur at any time and you don’t want the Raspberry Pi to be powered off and unable to receive that input.
If using your Raspberry Pi as a router on your network, it may be important to connect other networking hardware to a UPS as well – particularly the modem and any other similar equipment. It wouldn’t be very useful if the Raspberry Pi were still alive but all the other network hardware wasn’t available for the end-devices to use (note that this will drain your UPS faster).
Data collection projects often involve setting the Raspberry Pi to run remotely, without any involvement from you. This can include connecting it to sensors, to a camera, or to download information from the internet while unattended. IN this last case, remember to connect the router and modem to the UPS as well.
Remote control projects are another type where you set the Raspberry Pi up to do something without you being physically near it. In this case, the Pi is controlling something where you don’t want to be near it while it works – I’ve seen this used in farming projects in particular where there might be a long distance between you and the Pi (and the power connection is unreliable!).
Interested in how to monitor your Raspberry Pi remotely to see whether it’s still running? Check out the guide I wrote here: chipwired.com/monitor-raspberry-pi
If you want to find out more about the sorts of data collection work that a Raspberry Pi can do, I also wrote an article on that here: chipwired.com/collect-data-with-raspberry-pi
Chris is enthusiastic about moving energy around and having it power useful electronics (like a Raspberry Pi!)