Building a DIY uninterruptible power supply (UPS) for microcontrollers is not as simple as wiring a relay and a battery to a breadboard. When your ESP32 brownouts during a Wi-Fi transmit spike or your Raspberry Pi corrupts its SD card during a mains switchover, the fault almost always lies in the power conversion topology and dropout headroom. A commercial UPS handles this with massive lead-acid batteries and high-frequency inverters, but embedded systems require precise, low-noise DC-DC conversion. This guide breaks down the exact regulator math, topology trade-offs, and protection circuits needed to build a robust solid-state embedded UPS.
Topology Showdown: Linear vs. Switching for Embedded UPS
The first decision in your power path is how to step down or regulate the battery voltage to your microcontroller's 3.3V or 5V rail. The choice between linear and switching regulators dictates your battery life, thermal management, and analog sensor accuracy.
| Topology | Example Part | Efficiency (at 1A) | Heat Dissipation | Output Noise | Approx. Cost |
|---|---|---|---|---|---|
| Linear (LDO) | AMS1117-3.3 | ~66% (from 5V) | 1.7W (High) | < 10µV RMS | $0.15 |
| Step-Down (Buck) | MP2359 | ~88% (from 5V) | 0.39W (Low) | 20-50mV p-p | $0.45 |
| Buck-Boost | TPS63020 | ~92% (from 3.7V) | 0.28W (Very Low) | 30-60mV p-p | $2.80 |
The Dropout Math: Why LDOs Fail in Battery UPS Designs
If you are powering a 3.3V ESP32 from a single Li-ion cell (which ranges from 4.2V fully charged down to 3.0V depleted), an LDO like the AMS1117-3.3 will fail you. The AMS1117 requires a minimum dropout voltage ($V_{dropout}$) of 1.1V at 1A. This means your input voltage must never drop below 4.4V ($3.3V + 1.1V$). Once your Li-ion cell discharges to 4.3V, the LDO output sags below 3.3V, triggering the ESP32's brownout detector (BOD) and causing a reboot.
For a single-cell Li-ion UPS, you must use a buck-boost converter like the Texas Instruments TPS63020. It maintains a strict 3.3V output whether the battery is at 4.2V (buck mode) or 3.2V (boost mode), extracting nearly 30% more runtime from the cell compared to a buck-only or LDO topology.
Design Example: 5V/3.3V Li-Ion Backed UPS for ESP32/Pi
Below is a proven specification sheet for a DIY uninterruptible power supply capable of supporting an ESP32-WROOM-32 (peak TX current ~350mA) or a Raspberry Pi Zero 2 W (peak ~350mA), with enough headroom for sensors and relays.
| Subsystem | Function | Selected Component | Key Parameters |
|---|---|---|---|
| Input Protection | TVS & Reverse Polarity | SMAJ5.0A + P-Channel MOSFET (Si2301) | Clamps at 7.0V; blocks negative voltage |
| Power Path Mux | Seamless Switchover | TPS2119 (Dual Input Mux) | 2.5A max, 40mΩ $R_{DS(on)}$, break-before-make |
| Battery Charging | 1S Li-Ion CC/CV | MCP73831T-2ATI | 500mA charge rate, 4.2V regulation |
| DC-DC Conversion | 3.3V Rail Generation | TPS63020DSJ | 2.0V-5.5V $V_{in}$, 3.3V $V_{out}$, 2A peak |
| Energy Storage | Backup Power | 1x 18650 Li-Ion (e.g., Samsung 30Q) | 3000mAh, 15A continuous discharge rating |
Input Range and Switchover Mechanics
The TPS2119 power multiplexer monitors both the external 5V USB-C input and the boosted 5V battery rail. When mains power is present, it routes the USB 5V to the system and enables the MCP73831 charger. If the USB voltage drops below the undervoltage lockout (UVLO) threshold, the TPS2119 switches to the battery rail in under 100µs. This is fast enough to prevent the ESP32's internal capacitors from drooping below the 2.7V reset threshold during the transition.
Thermal Realities and Derating Your DIY UPS
Power path management generates heat, especially when using linear switchover methods like Schottky diodes instead of active MOSFET multiplexers. If you attempt to build this UPS using dual Schottky diodes (e.g., 1N5822) for OR-ing the power sources, you must account for thermal derating.
A 1N5822 diode has a forward voltage drop ($V_f$) of roughly 0.4V at 2A. Power dissipated is $P = V_f \times I = 0.4V \times 2A = 0.8W$. In a sealed plastic enclosure with an ambient temperature ($T_a$) of 45°C, the diode's junction temperature will easily exceed 100°C, accelerating failure and wasting 15% of your battery capacity as heat. Always use an active ideal diode controller or a power mux like the TPS2119, which drops only 40mV ($0.08W$ heat) at the same current.
For the DC-DC stage, the TPS63020 is housed in a QFN-10 package with an exposed thermal pad. To keep the junction temperature ($T_j$) below 105°C at a continuous 1.5A load, you must pour a solid copper ground plane on both the top and bottom layers of your PCB directly beneath the IC, connected by an array of thermal vias (0.3mm diameter, 0.6mm pad). Without this copper heatsink, the effective thermal resistance ($\theta_{JA}$) rises from 30°C/W to over 80°C/W, forcing the IC into thermal shutdown during sustained Raspberry Pi CPU loads.
DIY Uninterruptible Power Supply FAQ
What are the ripple and noise expectations for a switching UPS?
A buck-boost converter like the TPS63020 operates at a switching frequency of 2.4MHz. Under a 500mA load, you should expect an output voltage ripple of roughly 30mV to 50mV peak-to-peak. For digital logic (I2C, SPI, Wi-Fi), this is entirely acceptable. However, if your ESP32 project involves reading high-resolution analog sensors (like a 16-bit ADS1115 ADC) or audio DACs, this switching noise will corrupt your lower bits. To fix this, add a post-regulator LC filter (a 10µH shielded inductor followed by a 22µF X7R MLCC capacitor) or use a high-PSRR LDO (like the AP2112K-3.3) powered from the 3.3V switching rail exclusively for the analog sub-circuit.
What input voltage range and protection does a DIY UPS need?
If your UPS is designed for a 5V USB-C input, the actual voltage can sag to 4.5V under heavy cable resistance, or spike to 20V if a user accidentally plugs in a USB-C PD laptop charger set to a higher voltage profile. Your input stage must include:
1. A TVS Diode (like the SMAJ5.0A) to clamp fast transients and ESD.
2. An Overvoltage Protection (OVP) IC (like the AP9101C or a simple Zener + crowbar SCR circuit) set to trip at 5.5V to 6.0V, physically disconnecting the input if a PD negotiation fails and 9V/12V is pushed down the line.
3. A Polyfuse (PTC) rated at 2A hold / 4A trip to protect the upstream USB host from dead shorts on your custom PCB.
Can I use a standard cheap 18650 BMS module for my microcontroller UPS?
Most generic blue 1S BMS modules found on Amazon use the DW01A IC paired with an FS8205A dual MOSFET. While these protect against overcharge and deep discharge, their overcurrent protection threshold is typically fixed around 2.5A to 3.0A. A Raspberry Pi 4 booting up alongside a motor driver or an ESP32 transmitting on Wi-Fi while driving a relay can easily draw transient spikes of 2.5A for a few milliseconds. This transient will trip the cheap BMS, instantly cutting power to your microcontroller and defeating the purpose of the UPS. For embedded DIY UPS designs, either select a BMS with a higher trip threshold (5A+) and a delayed trip curve, or bypass the BMS discharge MOSFET entirely and rely on your DC-DC converter's undervoltage lockout (UVLO) to prevent battery over-discharge.






