# UPS for ESP32 Microcontroller [duplicate]

I have two e-bike batteries. One of which i am using to power my ESP32. Now i want to switch to other battery when my batt-1 is low. I am switching battery using relay. But doing so, I suspecting i might reset esp32 and hence state will be lost. I need solution around this problem.

P.S. Can not give external power supply to esp32

• a battery is an external power supply – jsotola Jan 1 at 20:28
• There's really many duplicates of this question. Search for "switch over power supply" or similar on this site. – Marcus Müller Jan 1 at 21:22
• also, honestly, an e-bike battery will probably take a looooong time to be depleted by an ESP32. – Marcus Müller Jan 1 at 21:23

If both batteries can be connected to the circuit simultaneously, you can consider using a power-OR topology. The simplest is two low-drop diodes, such as Schottky diodes with a suitable forward current (at least load current + safety factor) and sufficiently high reverse voltage (at least max battery voltage + safety factor; if reverse protection is an issue then at least twice max battery voltage + safety factor):

simulate this circuit – Schematic created using CircuitLab

Note shared ground/negative terminal.

This will allow current to be drawn from the battery with higher voltage, while preventing reverse (charging) current into the second battery. You can either just have the batteries connected to holders so that the user manually replaces them for charging, or you can use a pair of relays to realize this configuration.

There are more advanced versions of this configuration, where you replace the diodes with ICs that act as ideal diodes (perhaps with additional enhancements or features). In order to suggest one, we would need to know exact specifications.

The easiest approach is to use a capacitor that will power the system during the changeover period.

For capacitance C farad, time t seconds, current i amps and voltage drop V volt

C = t x i / V

So if eg
t = 0.01 seconds i = 0.1 A V = 0.1V (drop in capacitor voltage during changeover)
C = t x i / V = 0.01 x 0.1 / 0.1 = 0.01 farad = 10,000 uF.

A shorter holdup time, lower current or larger allowable voltage drop will all decrease the required capacitor value.