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 10A for a loaded system.
- 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)
- You need access the the 3V3 raiol to sense the end of the powerdown to know when to turn off the power.
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 period with the 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 12V with up to 2A will be dedicated to charging the cells. Another topology will use only one beefy 12V 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 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-charging of the cells. This will also be sufficient for the complete UPS when used with Pi Model 2 variations.
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 12Vpowerbrick. If you add both current requirements, you're getting into a territory of 5 Amps plus, where wall-warts in your drawer with that amount of power are getting rare. However, in that topology the Buck convertor sits after the diode-OR and reduces the incoming 12V 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 Efest 14500 IMR cells that can discharge up to 9A, 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 maybe later, I will plan to have the possibility to add an ESP32 for overal measurements and reporting.
I'm also later 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 tell the Pi itself to initiate a powerdown all by itself. We use a Watchdog to keep en eye on that process.
The shutdown process is easy to create, the real 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 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.
Because the controller chip is so tiny and without leads you can probe, I already decided to create a simple discrete version that does the same.
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.
The above one is the one I will use during the prototyping phase, but not in the final design. 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 typical key specifications for these regulators are:
Input voltage: 4-38VDC
Output voltage: 1,25-36 VDC adjustable
Output current: 0-5A (but 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.
On the two modules that I got because they claim support for 10A, they use MOSFETS that are an absolute overkill, and have avery large package to boot. The HYGO15N10NS1A feature 100V and a whopping 360A. Rest assured, I will use more common smaller ones in the PCB design.
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 nice side-effect of using the LM74700 controller is that it has reverse polarity protection, very nice when you need to use the 10A option.
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. I ordered two fresh ones for this design.
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 the beating hart of the UPS and is a circuit made from discrete parts that will turn off the two versions of the Buck regulator after the Pi has Powered down. This will 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. There is also protection for cells that are depleted too much, and there is a watchdog to cut-in when the cells are too low.
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 12V 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 12V 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 12V 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 all the way up to 10A.
Because I had to wait for some critical parts, I captured the complete design in KiCad, and used my Google IA friend in a browser to help out when I had questions. I typically do my research on an iPad and when done, transfer the info to my Linux laptop where I do the heavy lifting. I had to go back and forth to share the pdf versions of the KiCad schematics for the agen to use, but now that the conceptual design is done, I can continue on my laptop.
Here are the various schematics of the complete conceptual(!) design. Keep in mind that we will most likely run into Mr. Murphy and that things will change. I will keep the diagrams up-to-date while I'm progressing, so keep en eye out for changes.
I asked the Google AI agent to create a summary of the conceptual Design:
🎯 Project Master Documentation: 2S Li-ion/IMR DIY-UPS
Target Platform: Raspberry Pi all models (2, 3, 4, and 5) (High-Current Deliverability)
Design Philosophy: Fully Surface-Mount (SMD) custom PCB using globally obtainable, hand-solderable footprints with external leads (SOIC-8, SOP-8, SOT-23, SSOP-10, PDFN56). Completely avoids difficult leadless QFN/DFN profiles.
1. System Specifications & Topology
🔋 Battery & Input Profiles
- Cell Configuration: 2S (2 Series) High-Capacity Efest IMR Lithium-Ion Cells.
- Voltage Profile: Max float voltage is capped via trimmer between 7.8V and 8.4V total (3.9V to 4.2V per cell) to optimize health and lifespan.
- Hardware Under-Voltage Lockout (UVLO): Set sharply to a 5.6V cutoff floor under load.
- Mains Input: 12V DC Wall Adapter via a 5.08mm pitch heavy-duty screw terminal or barrel jack connector.
🔌 Dual-Buck Power Output Profile
The system uses a modular Split-Buck Architecture configured via a 3-pin selector jumper (JP1) to handle the heavy current requirements of the Raspberry Pi 5:
- On-PCB Integrated Buck (Up to 5A): Driven by an onboard Diodes Inc.
AP64500 circuit. - Off-PCB External Buck Module (Up to 10A): A heavy-duty, high-power external converter (e.g.,
XL4016) controlled via a custom feedback (FB) pin hijacking loop.
- Physical Interface: Solder lugs or 5.08mm screw terminals outputting to a short, heavy-gauge (16/18 AWG) stranded cable terminated in a USB-C pigtail to eliminate high-current cable voltage sag.
2. Comprehensive Input Power & Reverse Protection Stage
To
safe-keep the system against reversed polarity wall adapters,
protection is split across its individual branches to eliminate
unnecessary power losses:
🛡️ Input Defense Component Matrix
- Overarching Transient Suppressor: An
SMBJ13CA (or SMAJ13CA) bidirectional TVS diode sits immediately behind
the input barrel jack pins. It clips microsecond inductive hot-plugging
spikes up to 35V before they can punch through the gate oxide layers of
your board's silicon. - Downstream Power Protection: Handled natively by the
LM74700-Q1 Ideal Diode Controllers on the main power lines. They block negative voltages up to -65V, isolating the buck rails effortlessly. - Localized Charger Protection: The
CN3795 charger sits before the ideal diodes and cannot tolerate negative voltages. An AO3401A P-Channel MOSFET (SOT-23) is placed right on its 12V branch line.- An
R_G = 100 kΩ pull-down resistor closes the channel under normal operation. - A
10V Zener Diode (ZD_G) sits in parallel with R_G to protect the delicate ±12V gate ceiling of the AO3401A from input transient voltage ringing.
3. Battery Charger Circuit (Consonance CN3795)
An asynchronous buck topology running at 310 kHz in an accessible SSOP-10 footprint.
⚙️ Component Configurations & Overrides
- MPPT Disable Override: To prevent the solar tracker circuit from choking a fixed 12V mains supply, the
VMPPTpin (Pin 3) is held permanently above its 1.205V threshold using a 10 kΩ (Top) / 2.2 kΩ (Bottom) divider tied to VCC. This locks the pin safely at ~2.16V. - Constant Current (CC) Shunt: A 1206-size 60 mΩ (0.5W) power resistor (
R_CS) is placed across the CSP and BAT pins to lock the constant charging rate to a steady 2.0A. - Adjustable Termination Voltage Divider (7.8V – 8.4V): Wired to the
FB pin (Pin 7) against its internal 1.205V reference loop:R_FB1 (Top Resistor): 200 kΩ (Strictly 0.1% tolerance)R_FB2 (Bottom Safety Stop): 33.2 kΩ (0.1% tolerance) — Sets a hard maximum charging cap at 8.47V even if the trimmer is dialed to zero.VR_FB (Tuning Potentiometer): 5 kΩ Multi-turn Trimmer in series below R_FB2. Dialing it to max drops the charging limit cleanly to 7.51V.
📐 External Charging Power Loop
- Switching MOSFET:
AO4407A (30V, 12A P-Channel in an easy SOP-8 package with external legs). At 2A charging, it generates negligible heat. - Power Inductor:
22 µH Sumida CDRH127LDNP-220MC (12x12mm
industrial footprint with large side-weld pads). Shifting up to 22 µH
ensures low current ripple at the 310 kHz switching speed. - Catch Diode:
SS34 or SS54 (3A/5A, 40V Schottky Diode in an accessible SMA/SMB flat-cap package).
4. Integrated Buck Regulator (Diodes Inc. AP64500)
A synchronous step-down regulator integrated directly onto the motherboard PCB layout running at 500 kHz in a hand-solderable SO-8EP package. Layout features a 1.5mm unmasked via in its center belly pad for backside solder iron manual back-filling to the ground plane.
🧮 Component Calculations & Feedback Loop
- Frequency Programming (
R_T): A 200 kΩ (1%) resistor from Pin 5 to ground programs the internal clock to 500 kHz. - Input Capacitance: 2x 22 µF 25V X7R ceramic capacitors placed immediately against
VIN (Pin 2) and GND (Pin 7). - Output Capacitance: 3x 22 µF 25V X7R ceramic capacitors in parallel. At a 5.1V load, DC Bias Derating reduces them by ~20%, leaving a true operational capacitance of .
- Bootstrap Capacitor: A single 0.1 µF (50V) ceramic capacitor bridging Pin 1 (
BST) and Pin 8 (SW). - Adjustable Output Network (4.8V – 5.2V Target): Wired to the
FB pin (Pin 4) against its internal 0.8V reference:R1 (Top Resistor): 100 kΩ (1%)C4 (Feedforward Capacitor): 39 pF or 56 pF populated across R1 to maximize loop speed during transient Pi spikes.R2 (Bottom Resistor): 18.2 kΩ (1%) — Sets a hard physical upper stop at 5.20V.VR1 (Voltage Trimmer): 2 kΩ Potentiometer in series under R2. Dialing it to max drops the regulation target down to 4.76V.
- Type-II Loop Compensation (
COMP Pin 6): Optimized mathematically for the 53 µF real output capacity to target a stable loop crossover frequency ():R_COMP (Series Resistor): 6.2 kΩ (1%)C_COMP (Main Capacitor): 10 nF (X7R)C_COMP2 (Secondary Cap): DNP (Do Not Populate) — Footprint is left empty.
5. Active "Virtual Ground" Shunt 2S Balancer
Replaces
the difficult-to-solder leadless WSON-8 BQ29200 with an indestructible,
fully hand-solderable active shunt balancer built from generic
footprints.
- The Controller: An TLV9102 (SOIC-8) dual rail-to-rail op-amp. It compares the real battery midpoint (
MID) against an ideal voltage reference created by two 100 kΩ (Strictly 0.1% tolerance) resistors (R1, R2). - The Switch Drivers:
AO3401A (P-Channel) and AO3400 (N-Channel) in standard SOT-23 housings. - The Shunt Bleed Elements: 68 Ω (1W 1206 power resistors) (
Rb1, Rb2). When a cell drifts, the op-amp biases the corresponding MOSFET to bleed out an active ~58.8 mA from the higher cell. - Stabilizers: 0.1 µF ceramic capacitors are
placed on the reference divider and op-amp feedback loops to prevent
transient gate chatter or oscillation at the cell boundary.
6. Power Management & Control Logic (The dual 555 Core)
🗺️ Schematic Revision 10.0.6 Topology
The timing, protection, and automatic shutdown sequencers operate as a discrete hardware state machine driven off a dedicated LM2931-5.0 (SOIC-8) low-dropout logic rail decoupled with a 10µF high-ESR aluminum electrolytic output capacitor (C8).
🧠 Audited Logic Node Configurations
🛡️ Hardware Under-Voltage Lockout (TL431)
- Resistor Network: Changed to
R16 = 120 kΩ and R17 = 100 kΩ, paired with positive feedback hysteresis resistor R4 = 240 kΩ. - Performance: Fits your exact written specification: trips sharply at 5.68V under load to protect the cells from deep depletion, and locks the power path off until the cells recover all the way to a 7.50V rebound threshold before releasing.
🕒 Power Loss Glitch Filter (U1 NE555P)
- Passives:
R11 = 1.2 MΩ and C2 = 100 µF (Electrolytic). - Action: Provides a 3-minute grace period following
a mains power cut to let the Pi ride out brief line cuts. If power is
not restored, its output drops Low to signal a safe operating system
shutdown to the Pi via GPIO.
🕒 Shutdown Watchdog (U2 NE555P)
- Passives:
R12 = 1.8 MΩ and C3 = 100 µF (Electrolytic). - Action: Provides a 2-minute shutdown watchdog before turning on
Q3 (2N3904) to ground out the Master Logic Node and eliminate standby battery drain.
🔄 Early Termination Latch (U8 TLV9351xDBV)
- The Architecture: Resolves zombie power states immediately.
U8 compares a static 1.66V reference on its non-inverting input (Pin 3) against PI_3V3 on its inverting input (Pin 4). - The Hookup: When the Pi is running,
U8 outputs 0V. The microsecond the Pi finishes shutting down and its 3.3V rail drops to 0V, U8 outputs 5V High. This runs through a 1N4148 signal diode (D3) directly into THRES (Pin 6) of U2, forcing an instant watchdog timeout and killing main system power early to preserve the cell charge.
Here are the schematic diagrams that follow the above conceptual design in full detail.
This is the Battery Charger circuit.
This is the 2S Cell Balancer in the discrete version.
This is the hart of the UPS, the dual 555 Controller section.
Here is the Ideal Diode OR circuit, that mixes the Cell voltage with the 12V main supply:
And finally the on-board 5.1V Buck regulator for currents up to 5A that will power the Pi models 2 and 3 and a light Model 4.
The optional external Buck regulator module will supply 5.1V with up to 10A for the heavier loaded Model 4 and 5 systems.
Now that I have that conceptual design under my belt, I was able to order most of the critical parts. While waiting for them, I can continue with the modules.
I have already used the charger a few times with different cells, and tested the cell balancer. This was with the older Efest cells that were not ain a good shape, so discharge testing was minimal. I now have received two fresh Efest IMR 14500 cells, and fully charged them. Now I can run some tests with the ideal diode and the 5A discharge, using my DL in the Battery Test mode.
I will soon show some of the results here.
Stay tuned, I'm only beginning...