Uninterruptible Power Supplies (UPS) With Raspberry Pi 4 Model B | PiJuice HAT

Updated 20 February 2023

Now I'm not talking about a delivery service - I'm talking about an Uninterruptable Power Supply for your Raspberry Pi 4.

So if your Raspberry Pi project needs to be powered all the time relying solely on the mains power system may leave you in strife. Dropouts and surges can be regular occurrences depending on your location and these often last a couple of hours. Any power fluctuation can be harmful to your Raspberry Pi and a power outage will shut down your Raspberry Pi instantly. This means it will not shut down safely which results in any information being written to the SD becoming lost and increasing the potential for corrupting all of the information on your SD Card.

So to alleviate any stress and avoid putting your putting trust in electrical providers get your hands on an Uninterruptible Power Supply (UPS) Hat such as the PiJuice HAT (Hardware Attached Ontop) or the UPS HAT for Raspberry PI Zero. For more on what a HAT is check out this guide. So this guide will go through the creation of an Uninterruptible Power Supply for a Raspberry Pi 4 Model B, below is the contents of this guide.

- What a UPS Does

- Projects Where UPS are Invaluable

- Components for a PiJuice UPS With Raspberry Pi 4 Model B

- How to Install a PiJuice UPS Hat to a Raspberry Pi 4 Model B

- Demonstration of It Working

- Install PiJuice Software to Rasberry Pi OS

- UPS HATs for Raspberry Pi Micro-Processors

- Even Fits in an ONESIE Case

If you happen to be holding a Raspberry Pi board and not quite sure what it is? Then check out this guide Raspberry Pi Generations to identify it. Every Raspberry Pi Board has a UPS HAT that can work for it, you just need to find the right one. Check below for a list of a number of UPS HAT boards for Raspberry Pi Boards.

As always if you have any questions, queries or things to add please let us know your thoughts!


What a UPS Does

Simply a UPS (Uninterruptible Power Supply) is a type of continual power system.

Blackout A UPS ensures that if a power interruption occurs with the main supply (interruption = blackout), a battery or another power source will jump in, take over the role of the mains supply and continue normal operation of the device without the system ever losing power. Often UPS is seen as the emergency power method. When the mains are repaired the UPS is then recharged ready for the next calamity.

This guide focuses on UPS that directly attach to the Raspberry Pi, however, it is worth noting that all kinds of infrastructure and large data repositories have huge UPS systems. They operate in exactly the same way as what we will create here just on a much more massive scale. For example, the worlds largest UPS is a 46 Megawatt Battery Electric Storage System (BESS) located in Fairbanks Alaska. This will provide power for the entire city and nearby rural communities during outages. Absolutely awesome and necessary precaution for their cold winters. Also, as of 2021 the UPS market size is over 11 Billion US Dollars.

Bringing it back to our Raspberry Pi microprocessor world, in a situation where something is written on the SD card at the moment of power interruption, it is possible that the image will become corrupt and thus unusable. Each time a Raspberry Pi is not shut down properly, you risk corrupting the SD card. The equivalent would be pulling the power cord out of your desktop computer to shut it down. However, if a UPS is present, you will have more than enough time to save the file and finish what you were doing. UPS also helps protect hardware from power surges.

Also, if you are not around when the blackout occurs a UPS HAT such as PiJuice has settings that you can alter so that when the voltage dips too low, it automatically saves files properly and then safely shutdowns the system via internal software. This will avoid any data loss or SD card corruption. Also if your SD Card has been corrupted do not lose all hope here is a tutorial for you


Projects Where UPS are Invaluable

In many applications, it is important that the Pi continues to be powered in the event of a power outage and for these a UPS will help ensure the integrity and effectiveness of the project.

Raspberry Pi 4 Model B projects that involve data collections, scripts that do not automatically restart on boot, a Media Looping Monster, streaming from the web, a web server or a Pi-Hole add blocker would all benefit greatly by incorporating a UPS. 

Furthermore, UPS HATs are the perfect tools to increase portability to your projects. Remote projects like a remote camera system, Weather Station, Compact Robot, Portable Pocket Pi, DIY portable Game Console, Point and shoot camera can all be made simpler using a UPS Hat. Most UPS HATs present a great method to monitor the batteries voltage, power, current, and remaining capacity which is perfect for portable projects.


Components for a PiJuice UPS With Raspberry Pi 4 Model B

This is a great set-up because it is so very easy. This system will work plug in play without any extra software being installed to the system. Below is a list of what you will need.

- Raspberry Pi 4 Model B (Worth noting PiJuice UPS HAT will work heaps of other Raspberry Boards as well)
- PiJuice UPS HAT With Included Screws
- SD Card with Raspberry PI OS
- Micro-HDMI to HDMI Cord and Monitor
- Power Supply either USB-C or Micro-USB (PiJuice has this to allow power to the system. If you use this port you will need to press the Power button to turn on the Raspberry Pi as it will not power up immediately)
- Keyboard and Mouse

Components Required for This Build


How to Install a PiJuice UPS Hat to a Raspberry Pi 4 Model B

A very simple installation that will work as soon as everything is connected. Make sure to line all the GPIO Pins up and press the two boards together. The Stand-offs come pre-assembled with the PiJuice the only thing to watch for is to take out the tiny slip of plastic separating the battery from the connectors and to also to use the four nylon screws supplied for the bottom of the board. See below for an image demonstrating this process and pointing out the tiny slip of plastic that you should remove.

Connecting the Two boards together.

 
Once this is done you have succeeded in creating your UPS Raspberry Pi 4 Model B Board. Literally that easy. So plugin that SD card with Raspberry PI OS (Link here to a tutorial on how to do just this), mouse and keyboard, monitor and Power. Then press the button indicated in the picture below and you will be welcomed by that familiar Angkor Wat background. 

Plugged in and Functioning


Demonstration of It Working

Below you can see an image of the system staying on when connected via USB-C, Micro-USB and even when there is nothing plugged in at all (emulating a Blackout). The battery life for a PiJuice is for 4-6 Hours in this scenario when it is not connected to the mains. As soon as it comes back it will start charging and continue supplying energy to the Raspberry Pi. Very nifty! Especially considering no software or code has been installed to the set up. Those Brits working at PiJuice have got it figured out.

All the different ways of giving and interrupting power


Install PiJuice Software to Raspberry Pi OS

So as you can see PiJuice works straight out of the box, proper Plug and Play, but to get all the bells and whistle it is definitely worthwhile installing the software packages that those Brits created for it. Bells and whistle include - Better power management settings, automatic safe shutdown, automatic turn on and turn off at pre-set times (thanks to the internal clock inside it), wake and sleep cycles on a schedule, settings to connect different specification batteries and heaps more. Check out this page to learn heaps of details on these settings.

So set up everything like below and turn the system on (you can also add mains power from a USB-C or micro-USB am just showing off what you can do).

Set Up for Settings install 

Then once the booting sequence is over you will be welcome with the Raspberry Pi OS and the familiar Angkor Wat background. This you can see in the image below as well as an arrow pointing to the internet connection button. Click this button and follow through the prompts to connect to the internet by following through the prompts.

Internet Button 

Once you have connected to the internet we will open up the Raspberry Terminal using the black icon in the top left corner of the screen. Below you can see what it looks like when you open this window and there is a big arrow pointing to the icon which was clicked with the mouse.

Open up the Raspberry Pi Terminal 

Once this is open we will type the following into the console. After each line of code, press enter on your keyboard to run it. This can be seen occurring in the image below on the left, make sure to type the spacebars too.

sudo apt-get install pijuice-gui

Then once that is complete, like the image below on the right, safely restart the system using the Raspberry button on the top left (the Top Toolbar Menu) and selecting Log Off on the dropdown menu.

Sudo Command being run successfully

 

Then after a reboot, you will see a new Icon. Find it by clicking on that top-left Raspberry (the Top Toolbar Menu) and holding your mouse over Preferences. An image of this can see below. Definitely worth an explore.

Location of New Settings

  
Clicking on this will open up a fantastic world of settings to adjust your UPS PiJuice Raspberry Pi 4 to your exact desire, definitely worth an explore. See below for this.

Setting Window for UPS


UPS HATs for Raspberry Pi Micro-Processors

Below are some UPS HATS worth considering and comparing when putting onto Raspberry Pis. The below image is these boards as well starting with the PiJuice HAT, then the Raspberry PI UPS HAT and finally the UPS HAT for Raspberry Pi Zero.

Nice Stylish Looking Hats

PiJuice HAT

- Cream of the Crop

- Real-Time Clock (RTC)

-  Auto Shutdown when running Raspbian

- RGB Indicator Lights

- Can Connect much larger LiPo or Lithium-Ion Batteries (making the system last for over a day)

Raspberry Pi UPS HAT

- 5 LED Battery Indicator lights 

UPS HAT for Raspberry Pi Zero

- If you're using a Raspberry Pi Zero you will need to solder a header unless you bought the WH version.

- 5 LED Battery Indicator lights

- Won't work for other Raspberry Pi Types


Even Fits in an Onesie Case

If you made it this far, big congratulations. Check out how stylish the whole set up is in my 3D Printed Onesie Case HAT Version. Very psyched about it and means you can get out there and 3D print your own case.

Onesie Case Hat with Raspberry Pi 4 Model B and A PiJuice HAT

 

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.