Show by Label

Thursday, September 17, 2026

Investigation of a DIY UPS for all Raspberry Pi models

 The Investigation and Prototype


This project will first investigate the possibilities for a DIY UPS system for all Raspberry Pi models, at least that is the goal for the design.

When this investigation is successful, I will design a PCB for it in a later Blog post.

Why do I do this?

Well, I have a pretty long history of building a number of UPS versions for my Pi projects, starting with an elaborate version for my wireless thermostat that was running on the first version of the Pi, now many years ago (2015). That post is on my Blog, search for "UPS". Since then, I designed a number of other attempts to basically protect the SD card in the Pi from power outages or glitches.

My friend Bud designed two very nice UPS systems, in 2018 and 2019, using the HAT module layout, that could use 14500 and 18650 Li-Ion cells. He used a dedicated chip to handle the Pi power and charging (for the Pi Model 3 at the time), and used a micro-controller to keep things "under control". The latest version of that design worked for years for me, and at least two of them in Bud's applications, but recently the one I used developed an issue.

Here is Bud's posting of the latest design with all the details : 
https://hackaday.io/project/162653-u1liupsrpi

It turned out that the IMR cell that I used for several years got bad while in the application, but the UPS also showed an issue that I wanted to investigate. During that process, I successfully managed to create some magic smoke and blew a hole in the main chip, the LTC4040. Replacing that chip has it's challenges due to the footprint, and getting just a single one would cost me way too much, and I still would not know if there are other bad parts on the board.

I abandoned that resque project as being too costly, cumbersome and risky.

Although I do not have an immidiate need for a UPS, I kept thinking about it and the challenges. Bud designed a very nice UPS, much better than even commercially available products, but we were surprised that only very few Makers build one. It's not the lack of visibility because several projetcs we did together, he himself or myself had a lot of success with Makers, so that could not be the reason. 

Putting myself in their shoes, I realized that there are two obstacles preventing more global use. 

  • First the LTC4040. It's not widely available, and not cheap. The other challenge is the package, a 24-Lead 4mm × 5mm QFN that makes it a challenge for most Makers to solder.
  • Second is the controller, a PIC16F18323. The package is OK, but the programming is not. You need to have a programmer and a socket for the chip. Bud published the Microchip MLAB information and the flow-chart, but you have to program the chip yourself.
So, while thinking about another DIY version that is sturdy, reliable and easy to build, I started to piece a few things together that will potentially eliminate some of the challenges that plague most UPS systems for applications like the Pi.

There are actually three rather difficult to overcome challenges:
  • There are many Pi models and they all have peculiar differences for this application, in addition to OS or firmware/ROM/EEPROM related changes at just about every new version. The Pi's are all different in several aspects when dealing with the powerdown and power-up processes and that makes the restart a bit of a challenge. There are a myriad of postings on the official Raspberry Pi Forum from users and Makers that struggle with this. (sadly, this constant changing of the landscape has forced me to avoid the Pi as much as possible, and I now only use it when I have no other solution)
  • The later models, like the Model 4 and 5 consume a lot of power, especially when you use a number of USB adapters. The current requirement can quickly get up to 5A and more.
  • You need access to the GPIO connector. 
    • You can use it to supply power to the Pi, rather than using the standard USB power input connector. 
    • But you have to use the GPIO connector to tell the Pi that power has dropped in order to let it gracefully terminate running processes and start the powerdown sequence. (only the Pi Model 5 can communicate over the USB power cable connection)

With the advent of newer Pi models and ways to protect or even circumvent the SD card, the UPS functionality is a bit less important on that part, but if you have applications that do not tolerate a sudden power loss or power glitch, you still need protection.

The UPS goals for this project

Rather than keeping the Pi alive for a very long time, the focus will be on riding out power glitches and to provide a controlled power down and restart when power returns. Most of us live in countries where the main power is very reliable and stable, so the focus is not so much on a long loss of power, but a graceful termination of a running one. With this design you could potentially cover long periods of a power loss, but the battery will most likely have to be very different (12V car battery?) and this is not covered with this project.

The powerdown process will be under control of the Pi itself so you are free to do what's needed to cleanly terminate your processes and then execute the powerdown.

The UPS function only needs to supply power to the Pi for a few minutes. Three minutes should be enough to do what's needed, so there will be enough remaining capacity in the cells to go through another cycle that happends before the cells are fully recharged again.

The switching from main power to the battery power should be automatic and instantenous without glitches. 

To make the design simple, I'm planning to use a normal (Raspberry Pi recommended/certified) 5.1V power-brick to supply power to the Pi. It should have at least 2.5A capacity, more if you need that for Model 4 or 5 and if you use USB adapters. It can be the same one you are already using. Another power-brick with 12 or 15V with up to 2A will be dedicated to charging the cells. Another topology will use only one beefy 12 or 15V power brick to supply everything, see details below.

To avoid the issues with Boost regulators that will convert a single Li-Ion cell (between 4.2 and 3.0V) to the 5V the Pi needs, I elected to use two cells in series. That configuration only needs a simple Buck regulator to regulate the cell voltage from between say 8 and 6V down to the 5V the Pi needs. 

The charger function will be one that can handle a 2S (2 cells in Series) configuration with all the protection needed for Li-Ion cells. An active and simple balancer circuit willl be used to keep both cells happy and at the same voltage level. This is important because the cells will normally be off-duty with only an occasional use. 

To supply power to the charger, I'm planning to use a 12V or 15V wall-wart that many of us have from other devices, most likely a drawer full of them, like I do. They typically have the capability to deliver 2A, which is plenty for the re-chargeing of the cells.

So why two wall-warts? Seems a bit daft at a first glance, but it avoids either a high power Buck regulator to bring the 12 or 15V down to the 5V for the Pi, and that 24x7 so it needs to be very reliable and provisions need to be made for the developed temperature generation. 

The other option is to use a single beefy 12 or 15V powerbrick. If you add both current requirements, you're getting into a territory of 5 Amps plus, where wall-warts with that amount of power are pretty rare. However, in that topology the Buck convertor sits after the diode-OR and reduces the incoming 12 or 15V to 5V for the Pi, but does the same for the cell voltage. The Pi sees no difference and is not very sensitive for normal Buck/Boost regulator high frequency switching noise.

To switch between the mains voltage and the cell provided voltage, I will be using two so called active Ideal Diodes in an OR configuration. This will ensure that the main 5V going into the Pi will not have a significant voltage drop and nothing will get hot.

The two Li-Ion cells I'm planning to use can be 14500 or 18650 IMR cells that feature a very high discharge current. I'm planning to use two 14500 IMR cells, but will also test the 18650 cells that will have more oompf for high current applications.

In this design there is no required micro-controller, although I will plan to have the possibility to add an ESP32 for overal measurements and reporting. 

I'm also planning to add an ADC so voltages and currents can be measured and logged if wanted, but this is optional and not required.

With the above building blocks, we can provide the Pi with power when the mains drops away and will use the Pi itself to initiate a powerdown all by itself. 

The trick for all these UPS solutions is to wake-up the Pi when power returns. This is where in most UPS designs a micro-controller is used, but we won't have one. A clever state-machine circuit will keep an eye on the power loss and will turn-off the Buck regulator output when the Pi is made powerless after a powerdown. (note that several Pi models are still alive a bit after a powerdown or being halted) 

The state-machine process will allow the Pi to start normally when main power returns, and will need to avoid interruptions when power comes back too soon. Yes, you can use the features newer Pi models have, but these features are not available on the older model Pi's. Allowing the Pi to startup when power has been removed completely before is reliable for all current models.


The Prototyping phase


When I had this rough design done, mostly in my head, I looked for the modules that would allow me to build the system and test it out.

I could find everything I needed on Amazon, for reasonably low prices and with a fast delivery.
Here are the building blocks:


Li-ION 2S Charger Module:



This is actually a solar panel based charger with an MPPT feature that I won't need, but it's easily disabled. The input is the 12 or 15V from the wall-wart, and the output goes to the two cells in series, as if it was only one cell.

The specifications are:
Model: CN-3795-2A.
Input voltage: DC 6,5-24 V.
Output current : max. 2 A
Output voltage range: adjustable from 2,4 V to 20 V.
Can be sued for : 1 to 5 lithium-ion cells in series.
Charging modes: constant current / constant voltage plus MPPT.
DC-DC-efficiency: ca. 85%
Module size: 20 x 35 mm.


The 2S Balancer Circuit:




The output from the Balancer Circuit goes to the plus of the top cell, the middle to the connection between both cells,  and to the bottom of the second cell. That's it. It simply balances the voltage of both cells to within 30mV and uses a 10mA charge to reduce a higher voltage cell.


The Buck Convertor:

This regulator will be used to reduce the cell voltage down to the 5V the Pi needs.

I have  number of this little boards, several that use the LM2598S. It has an EN pin (pin5) that can be easily lifted from the PCB so we can switch it off (albeit with some special considerations)
The LM2598S even has a softstart/EN input. The EN signal input will be used to switch off the 5V supply to the Pi when the Pi has been through the Powerdown process, so it will make the Pi truly powerless. This is an important pre-requisite for the clean restart of all the Pi models when power returns.

This above one is the one I will use during the prototyping phase, but not in the final desig. Please keep that in mind. If you need to buy one, get one of these until I can give you a better alternative.


There are also many other Buck regulator boards that use the XL6009E1 chip. 



However, the XL6009 E1 is a Buck and Buck-Boost regulator, and that poses issues, including some serious ones for this circuit. The EN input is active high and that also can cause a serious issue. 
Don't use these regulator modules!


Here is one that uses the XL4015, but this chip has no EN pin and therefore cannot be used in this configuration.



The key specifications for these regulators are:

Input voltage: 4-38VDC
Output voltage: 1,25-36 VDC adjustable
Output current: 0-5A (stay below 3 to keep heat down).

Depending on the selected Power Path architecture, more below, we will have to select a higher power circuit with at least 5A up to 10A for the PCB design, we'll get to that later.


The Ideal Diode Switch



This circuit uses N-Fet's (very low RDS-on) and the LM74700 controller. It is ground based (many other boards are not and that gives a problem) The LM747001 has an EN (enable pin) that I need to bring out for this board, so the Pi can switch-off the battery supply when it has reached the powerdown status. To use an N-FET in this circuit the LM74700 has a built-in charge pump.

Specifications:
Input voltage: 5-30V  (another spec says 0-50V; that's not correct)
Current: up to 10A

These Ideal Diode boards will need a minimum input voltage to let the LM74700 function, typically 4V is OK. We'll find that out when we're testing.

The create the diode OR circuit, the inputs are connected to either the main 5V or the cell generated 5V, and the outputs from both boards are then connected together and go to the Pi power input.


The above parts are all on order and will arrive shortly.


The Li-Ion High Current Discharge Cells

I used EFEST IMR 14500 650mAh cells before and still have two that have now lost their maximum capacity, but they are still usefull for testing purposes. They can provide up to a whopping 9.75A discharge. 



The newer Vapce IMR cells are 1250mAh and have a maximum contineous discharge capability of 3A.

With power requirements from 5A upwards we cannot use the 2S configuration for the Vapce cells, but we'll address that later.


Dual Battery Holders

I have ordered battery holders for both 18650 and 14500 cells with smd soldering lugs.


The Powerdown State-Machine Circuit

This is a circuit made from discrete parts that will drive the EN signal from the Buck regulator after the Pi has Powered down to switch off the Buck voltage regulator and provide a clean power-up when the main voltage returns. The State-Machine also has to take care of situations where the power returns while the Pi is still in the shutdown period. This is a key requirement for the clean startup procedure for all Pi models.



The Power Path

As mentioned earlier, there are two approaches possible, depending on what you have and want.

The first one is called Paul's concept for now. In this concept, the normal 5V for the Pi is not affected at all, the standard (recommended/certified?) Pi wall-wart you already have can still be used. The voltage drop over the ideal diode is so small that we don't need to worry about that.
You will most likely have a number of 12 or 15V wall-warts lying around that can be used for the cell string. A minimum current of 2A will recharge the cells pretty fast.


The second, more simple approach is what my friend Bud recommended and that is to use only one beefy 12 or 15V wall-wart, and use the Buck regulator for both power sources. This allows you to precisely set the voltage for the Pi, and it will never see a voltage supply difference. This will dictate a larger 12 or 15V wall-wart because it has to supply the Pi in addition to the recharge current. For a Pi model 4 or 5 with additional USB devices, this current can be in exess of 5A.



When I have the modules wired-up, I will do some testing and show the results here.

Stay tuned, I'm only beginning...




If you like what you see, please support me by buying me some Java: https://www.buymeacoffee.com/M9ouLVXBdw

For those that already did, thank you!



No comments: