The Ultimate Guide to Every Animated Movie of the 90s! ✨

Hello Maker friends! 👋 Tired of sudden blackouts wrecking your PC, NAS or home lab? 💻💥 Let’s build a smart UPS (Uninterruptible Power Supply) using a cheap ESP32 dev board and common parts, no soldering or expensive tools required! We’ll make an intelligent dual-battery backup that switches automatically, sends you alerts, and even hosts a web dashboard—all on a solderless breadboard. It’s like pro-level DIY power management: advanced, hackable, and budget-friendly! 🔋🛠️

By the end of this guide you’ll have an industrial-grade power supervisor for your home projects. It handles two batteries (Lead-Acid + LiFePO4), monitors voltages, talks to your PC/NAS, and finally “cuts the cord” to save the batteries. We’ll walk through every step with diagrams, tips, and example code. Let’s get started! 🎉


1. What Will You Get? 🌟

After assembly, your UPS becomes truly smart and reliable. Here are the killer features of our build:

  • 🔋 Dual Battery Engine: Uses your old Lead-Acid battery first (saving energy costs) and seamlessly switches to a backup LiFePO4 pack when the SLA runs low, without rebooting your PC/NAS. This extends overall runtime and battery life.
  • 💻 Smart Computer Shutdown: The ESP32 connects to your home Wi-Fi and communicates with your PC/NAS. When batteries run out, it tells them to hibernate or shut down safely over the network—avoiding data loss.
  • ⚡️ Zero Power Waste (Latching Relay): We use a special 5V latching relay so that when the system cuts power, the coil draws no current at all. In other words, once it turns off, the battery is fully isolated (0µA drain).
  • 📱 Telegram Alerts: Get instant push notifications on your phone! Using the Telegram Bot API, your ESP32 will message you “⚠️ Power Outage Detected” or “🔋 Battery Low” so you can monitor remotely.
  • 🌐 Web Dashboard: The ESP32 even hosts a tiny webserver. Open it on your phone browser to see real-time battery voltages, mains status, and system health (no extra computer needed).

Think of it as affordable home automation for your power backup. Many big UPS solutions lack dual-battery switching or IoT alerts, but we’ll achieve that with just a ~Rs.1000 ESP32 and a breadboard! (No PCB making or soldering – just plug in components.)


2. Hardware & Shopping List 🛒

Here’s everything you need. These are common parts you can grab online (Amazon, Robu, eBay) or at any electronics market. We’ll assemble it on a solderless breadboard, so no soldering irons or PCB costs needed!

Main Components (the big stuff):

  • ESP32 DevKit V1: The brain of our project. This low-cost Wi-Fi microcontroller board has plenty of GPIOs (up to 30+) and built-in Wi-Fi/Bluetooth. We need these extra pins, so we prefer ESP32 over smaller ESP8266 boards.
  • 5V Relay Module (1-Channel): A standard 5V relay to choose which battery is feeding the UPS. When off, it connects the lead-acid; when on, it switches to the LiFePO4.
  • 5V Latching Relay: A special relay that “latches” on or off. Unlike normal relays, it doesn’t consume power to hold its state. Perfect for acting as a final power cut switch – zero power when idle.
  • Voltage Sensor Module (×2): These little modules (often 0–25V range) are simply two resistors and an op-amp that scale down battery voltage to the 0–3.3V range of the ESP32’s ADC. We need two modules, one per battery.
  • 5V USB AC Adapter (old phone charger): We’ll use this as a mains sensor. When plugged into wall power, it outputs 5V which our ESP32 reads; when power fails, that 5V goes away (without touching 220V directly).
  • PCF8563 RTC Module (Optional): A Real-Time Clock chip with backup battery (coin cell). This keeps time accurately even if Wi-Fi is down, so logs/timestamps stay correct after outages.
  • Micro SD Card Module (Optional): For logging data or saving settings. Handy for long-term monitoring or debug.

Small Components (support parts):

  • BC547 Transistors (×2): Small NPN transistors to drive the latching relay coils. (Think of them as relay drivers/switches controlled by the ESP32 GPIOs.)
  • 1N4007 Diodes (×4): General-purpose diodes for protecting against voltage spikes when driving relays or to combine signals safely (flyback diodes).
  • 1N5822 Diodes (×2): Heavy-duty Schottky diodes (10A rating) in the battery lines. These prevent the two batteries from charging each other when one is higher voltage.
  • Resistors: We need a pair of 10kΩ (for the AC detection divider), and a couple of 1kΩ (for transistor bases).
  • Breadboard & Jumper Wires: A standard full-size solderless breadboard is perfect. It lets you wire everything cleanly without solder. (You can eventually solder for permanence, but you asked for no-solder DIY!)
Solderless breadboard prototype
Figure: A solderless breadboard prototype. We can jam an ESP32, relays, sensors, transistors, etc. onto it – no soldering needed.

3. Step-by-Step Wiring Guide 🔧

Safety First! We’re dealing with battery power and mains-adjacent circuits. Always double-check wiring, and isolate power when adjusting connections. Use fuses on battery lines if possible. Never connect 220VAC to the ESP32 pins – we’re only sensing AC via that USB adapter trick.

Step A: AC Mains Detection (Grid Sensing) 🔌

We want to know when house power goes out. Instead of tapping directly into 230VAC, we’ll use a simple hack: a 5V wall-wart/charger.

  1. Wall Adapter Setup: Plug the USB charger into a normal wall outlet, not the UPS output. That adapter outputs +5V when mains is on.
  2. Cut the USB Cable: Expose the red (+5V) and black (GND) wires. These wires now reflect whether the grid is live.
  3. Voltage Divider: To safely read 5V with the ESP32, make a divider: connect two 10kΩ resistors in series between +5V (red) and GND (black). This creates a midpoint at ~2.5V.
  4. ESP32 Input: Connect the midpoint of the resistors to ESP32 GPIO 34 (ADC input). Also connect GND to ESP32 GND.
  5. Logic: When the adapter is powered, GPIO34 reads ~2.5V (ADC HIGH). When mains fails, +5V goes to 0V, so GPIO34 sees 0V (ADC LOW). In software, treat GPIO34 = HIGH → grid is ON, and LOW → grid is OFF.

This way, the ESP32 indirectly senses AC mains with no direct AC wiring. All voltages are low and safe.

Step B: Connecting the Two Batteries 🔋🔋

We have two 12V batteries: the older Lead-Acid and the backup LiFePO4. We need to monitor both voltages.

  1. Lead-Acid Battery Sensor: Connect the positive terminal (+) of the lead-acid battery to the input of the first voltage sensor module. The sensor will output a scaled 0–3.3V signal (assuming it’s designed for up to ~25V). Feed the sensor’s output pin (often labeled “S”) to ESP32 GPIO 33 (an ADC pin).
  2. LiFePO4 Battery Sensor: Similarly, connect the LiFePO4 positive to the second sensor, and its “S” output to ESP32 GPIO 32.
  3. Common Ground: IMPORTANT: Tie both battery negatives together to ESP32 GND. This common ground lets the ESP32 measure each battery relative to ground.

Each sensor module typically has a calibration adjustment; you should calibrate them later in software (see “Testing” section). Having two separate sensors and ADC pins lets the ESP32 continually compare voltages. LiFePO4 cells usually go up to ~14.6V when full, and lead-acid to ~13V, both under 25V input range of the sensors.

Step C: Battery Selection Relay (Switching Logic) 🔄

Now we wire the 5V single-channel relay that decides which battery powers the UPS output.

  1. Relay Module Connection: Wire the relay module’s VCC to 5V and GND to ground. Connect its control (IN) pin to ESP32 GPIO 13. This pin will drive the relay ON/OFF.
  2. Batteries to Relay: Using the relay terminals:
    • Connect Lead-Acid + through a 1N5822 diode (to prevent backflow) to the NC (Normally Closed) terminal.
    • Connect LiFePO4 + through another 1N5822 diode to the NO (Normally Open) terminal.
    • Connect the COM (Common) terminal to the UPS input (the device you want to power, e.g. a DC-UPS line or DC-AC inverter input).

The diodes ensure that if the relay accidentally shorted, one battery cannot charge the other.

Operation Logic By default (relay off), the NC contact is connected, so the lead-acid battery feeds power. When the ESP32 energizes GPIO13, the relay switches to NO, connecting the LiFePO4. We will drive this automatically: e.g. use lead-acid until voltage drops under a threshold, then trigger GPIO13 HIGH to swap to the backup. This gives us an automatic battery handover. The transition is instantaneous (no reboot), and the UPS never sees a power cut – it just changes source.

Step D: The “Kill Switch” (Latching Relay) 🔪⚡

Finally, the latching relay is our ultimate kill-switch. When batteries are critically low (or timed out), the ESP32 will cut the power completely.

Why Latching? A latching relay has two coils (Set/Reset) and keeps its last state without power. This means once it turns OFF, it draws no current from the battery – ideal for true power-off.

Driving the Latch: The ESP32 GPIO pins cannot directly drive these coils (they need higher current or separate polarity pulses). So we build a small H-bridge using:

  • Two BC547 transistors: each controlling one coil (Set or Reset).
  • Four 1N4007 diodes: for steering current and back-EMF protection.
  • A few resistors: like 1kΩ on transistor bases.

Wiring the H-Bridge: Without going into every detail here, the key is:

  • GPIO 26 connects (via 1kΩ) to the base of Transistor #1 (to Set the relay ON).
  • GPIO 27 connects (via 1kΩ) to the base of Transistor #2 (to Reset the relay OFF).

The transistors and diodes are arranged so that a short 50ms pulse on GPIO26 sends current through the set coil, latching the relay ON, and similarly GPIO27 pulses the reset coil to cut power.

Operation: In software, when it’s time to shut down the output completely (e.g. after the shutdown procedures are done), we send a 50ms HIGH pulse on GPIO 27. This trips the latching relay to OFF and physically disconnects the UPS output. The EPS32 and relays are then truly off, preventing any battery drain.

Pro Tip! You can prototype this latching circuit on a breadboard too. Make sure to connect the latching relay’s common output to the UPS output line, and its contacts in the battery feed line. Once “killed,” no current flows anywhere – batteries are safe!

4. Software: Coding & Flashing the ESP32 💻

With the hardware wired up, we turn to the code. We’ll program the ESP32 (using Arduino or PlatformIO) to monitor everything and take actions.

Environment: Install Visual Studio Code with the PlatformIO extension (free). This lets you manage ESP32 projects easily.

Libraries: We’ll use Arduino core libraries. For Telegram, install the Universal Telegram Bot library and ArduinoJson (via PlatformIO/Arduino Library manager).

Core Code Logic:

  • Initialize Wi-Fi (WiFi.begin("SSID","PASSWORD");) and wait for connection.
  • Read ADC values: e.g. analogRead(33) and analogRead(32), then convert to real voltage. If you use the default 0–25V sensor, multiply by ~6.6 ((raw/4095.0)*6.6).
  • Check the grid sensor pin (GPIO34) for AC status.
  • Switch relay (GPIO13) between batteries based on voltage thresholds.
  • Monitor if battery is low: if below critical level, send a shutdown signal to connected PCs (over network) and after confirming shutdown, trigger the latching relay.
  • Use an HTTP server or AsyncWebServer to serve a simple webpage that shows status (battery volts, grid on/off).
  • Send Telegram messages with bot.sendMessage(chat_id, "Battery Low!", ""); when events occur.

Example Code Snippets:

Wi-Fi Connect:

#include <WiFi.h>
void setup() {
  Serial.begin(115200);
  WiFi.begin("YourSSID", "YourWiFiPassword");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to Wi-Fi");
}

Read Battery Voltages:

int rawLA = analogRead(33);       // Lead-Acid sensor
int rawLi = analogRead(32);       // LiFePO4 sensor
float vLA = (rawLA / 4095.0) * 6.6;    // adjust scale (calibrate as needed)
float vLi = (rawLi / 4095.0) * 6.6;
Serial.printf("Voltages: LA=%.2fV, Li=%.2fV\n", vLA, vLi);

Telegram Alert (using UniversalTelegramBot):

#include <UniversalTelegramBot.h>
WiFiClientSecure netClient;
UniversalTelegramBot bot("BOT_TOKEN_HERE", netClient);
String chat_id = "YourChatID"; // get this from @myidbot on Telegram
...
if (vLA < 11.5 && !sentLowAlert) {
  bot.sendMessage(chat_id, "⚠️ Lead-Acid Battery Low!", "");
  sentLowAlert = true;
}

Automatic Shutdown & Latch Control:

const int RELAY_PIN = 13;       // battery switch relay
const int LATCH_SET = 26;
const int LATCH_RESET = 27;

void switchToLiFe() {
  digitalWrite(RELAY_PIN, HIGH);  // switch relay to LiFePO4
}
void killPower() {
  // Pulse the reset coil to turn everything off
  digitalWrite(LATCH_RESET, HIGH);
  delay(50);
  digitalWrite(LATCH_RESET, LOW);
}
...
if (batteryCriticallyLow) {
  // signal host computers to hibernate (code not shown here)
  killPower();  // cut power after shutdown
}

Customize these snippets as needed. The full code will include Wi-Fi setup, web server initialization (e.g. using AsyncTCP/WebServer libraries), reading all inputs in loop(), handling relay control logic, and the GPIO pin modes (pinMode(...)). After coding, use “Upload” in PlatformIO to flash the ESP32 via USB.


5. Testing, Calibration & Final Checks ✅

Before plugging in your expensive PC, do dry-run tests with something simple (like a 12V bulb or DC fan) and a multimeter.

  • Basic Power-On: With wall power present, the bulb should light (Lead-Acid feeding). Check the web dashboard shows ~12V on the LA battery.
  • Grid Sense Test: Unplug the 5V adapter from the wall – the ESP32 should detect power loss (GPIO34 drops) and (if coded) send a Telegram alert.
  • Battery Switch Test: Manually lower the LA battery voltage (or simulate in code) to test the auto-switch. On switching, the bulb should stay lit (now powered by LiFePO4).
  • Voltage Calibration: Compare the ESP32’s voltage readings (printed in Serial or on webpage) with a multimeter. If they differ, adjust your code’s scale factor or sensor trim pot until they match. Many sensor modules are a bit off by ~10%, so calibrate once and fix it in software.
  • Shutdown Sequence: Let the battery run to critical level. Your code should initiate safe shutdown commands (if you integrated that) and then kill the power (the bulb should go OFF when latching relay triggers). Ensure no current flows after – the ESP should be completely off.
Calibration Tip! You might see the ADC is not perfectly linear. It’s okay to apply a small multiplier offset. Measure a known 12.0V and adjust code: e.g. if ESP reads 11.5V, multiply by 12.0/11.5. Once everything behaves correctly with the dummy load, remove power, hook up your real UPS input or inverter to the common output, reconnect the batteries through the relay, and then try with your actual devices. Monitor closely the first few times.

Congratulations! 🎉 You’ve built a cheap, solderless smart UPS. It will use your old lead-acid first (saving cost) and seamlessly fall back to a robust LiFePO4 (for longevity). The ESP32 brain handles shutdown and alerts, and the latching relay protects your batteries from needless drain. Feel free to customize further: add LCD display, use MQTT instead of Telegram, or integrate with home assistant. The sky’s the limit with ESP32!


6. Why This Rocks (and SEO Focus) 🌈

  • Cheap & Breadboard-Friendly: All components (< $30) and a breadboard, no PCBs or soldering needed. Perfect for quick prototyping or hobbyists.
  • DIY Home Lab: Protect your PC/NAS without buying an expensive industrial UPS. This home automation hack uses a cheap ESP32 to do something powerful: IoT-grade power monitoring and control.
  • Open-Ended Project: You learned to interface ADC, relays, Wi-Fi, Telegram – skills you can reuse. The ESP32 is a Swiss Army knife for DIY electronics!
  • Energy Efficient: Latching relays and sleep modes mean the supervisor itself barely draws power between events, so it won’t kill your batteries.
  • Community Tools: We even referenced open tools and libraries (Telegram Bot, AsyncWebServer) to speed up development.

Big takeaway: With a small breadboard and minimal parts, you can build something very sophisticated. An ESP32 can handle power control, network communication, user interface, and logic – no expensive PLC or lab tools required. This project shows the huge potential of cheap IoT boards: real-time automation with custom features, done by us, the makers. 😎🔧

Have fun building, and stay tuned to the ESP32 hackery! If your friends laugh that you built your own UPS, just say, “It’s ESP32 magic” 😉.


Sources & Further Reading: We leaned on various online tutorials for latching power switches and Telegram alerts to fine-tune this design.

About the author

Student, Photographer by Hobby, Blogger / Content Writer

Post a Comment