How to add a UPS to your Raspberry Pi projects (and do it on the cheap)

Raspberry Pi fitted with a UPS

Raspberry Pi fitted with a UPS

Adrian Kingsley-Hughes/ZDNET

The Raspberry Pi needs little introduction. This single-board computer has become an essential tool for tinkerers, tech enthusiasts, and programmers.

But what happens when the power goes out?

Also: The best portable power stations you can buy

I had a project where I needed a Raspberry Pi to run 24/7/365 with as high a level of uptime as possible. While power cuts are rare in my neck of the woods, they can happen. I needed to make my Pi resistant to such outages. I needed a UPS — short for uninterruptible power supply — a battery backup mechanism that kicks in when the power goes out.

Here's the UPS I opted for: a Waveshare UPS HAT (B)

Waveshare UPS HAT (B) kit

ZDNET RECOMMENDS

Waveshare UPS HAT (B) kit

The UPS HAT allows you to use two 18650 rechargeable batteries as a backup power supply for your Raspberry Pi. No soldering is required and you can still use the GPIO pins on the top of the Pi.

Waveshare UPS HAT (B) specs

  • Compatible with Raspberry Pi 3, 3B+, and 4B
  • Supports real-time monitoring of the battery voltage, current, power, and remaining capacity
  • Multi-battery protection circuits offering overcharge/discharge protection, over current protection, short circuit protection, and reverse protection
  • Onboard 5V regulator allowing for up to 5A continuous output
  • 5V USB output
  • Battery warning indicators
  • Includes development resources and manual
  • Requires 2x 18650 batteries (not included) 

Also: Finding Raspberry Pi: Where to buy the latest model and its alternatives

Note: I've also used the GeeekPi UPS HAT, which offers similar functionality but uses micro USB, which charges at a slower rate than the Waveshare board at a similar price.

The Waveshare UPS HAT (B) fits onto the bottom of the Raspberry Pi. 

OK, got all the bits, so I'm ready to go.

All the bits I needed to fit a UPS

All the bits I needed to fit a UPS

Adrian Kingsley-Hughes/ZDNET

And I'm not going to be put off by the typo on the battery charger!

Typo on charger reads "Batter charger"

Adrian Kingsley-Hughes/ZDNET

The HAT connects to the Raspberry Pi using pogo pins that press onto the underside of the GPIO pins.

Pogo pins connect the HAT to the Raspberry Pi

Pogo pins connect the HAT to the Raspberry Pi

Adrian Kingsley-Hughes/ZDNET

OK, here are the assembly instructions.

Big spacers go on the battery side, shorter ones on the side that will face the Raspberry Pi.

Four flat-headed screws attach the Raspberry Pi to the HAT.

Notice how the pogo pins fit against the underside of the GPIO pins. The advantage? Not only is no soldering required, but you can still use the GPIO pins on the top of the Pi.

It's a lot easier to tighten the screws if you have a magnetized screwdriver. I used a magnetizer/demagnetizer to make my screwdriver tip magnetic. 

Making my screwdriver bit magnetic makes fitting the screws a lot easier!

Making my screwdriver bit magnetic makes fitting the screws a lot easier!

Adrian Kingsley-Hughes/ZDNET

Tighten the screws holding the HAT down a little bit at a time, don't just crank down on one screw then go to another because that will misalign the pogo pins.

When done, check the alignment of the pogo pins against the GPIO pins.

Check the alignment of the pogo pins against the GPIO pins

Adrian Kingsley-Hughes/ZDNET

Make sure to get the polarity right.

I used the domed screws to hold the cover in place. This prevents metal bits from falling into the battery compartment and possibly shorting things out.

Don't want to use HAT? Here's another way

OK, while a HAT is the most convenient and reliable way to set up a UPS for a Raspberry Pi, there is another option: use a power bank.

You can use the power bank to power the Raspberry Pi, and connect the power bank to a charger to keep it topped up.

Also: These are my 3 must-have Raspberry Pi accessories

Unfortunately, you can't use just any power bank. The power bank has to support a feature called pass-through charging. This is the feature that allows the power bank to be simultaneously charged while charging a device.

Not all power banks support this, but power banks from Zendure, Goal Zero, Omni, and Renology support this feature, and offer much greater backup capacity than two 18650 rechargeable batteries can provide.

Also: The 5 best portable power banks: Keep your devices juiced on the go

Another alternative is to use a power station, from makers such as Jackery or Bluetti. All power stations I've tested support pass-through charging.

Source