An ESP32 plugged into a USB charger just works. The trouble starts when you want to take it to the garden, a mailbox or anywhere without an outlet. That’s where the battery, the regulator and, above all, deep sleep mode come into play.
In this guide you’ll see which batteries suit the ESP32, how to connect them without damaging anything and what to do so they last weeks or months.
In short
- The ESP32 chip runs at 3.3 V (it accepts roughly 3.0 to 3.6 V). A LiPo or an 18650 reaches 4.2 V: you need a regulator.
- Use a low-dropout, low-quiescent-current LDO, not the AMS1117 found on dev boards.
- Charge the battery with a protected charger module, never by connecting it straight to 5 V.
- Deep sleep brings the chip’s draw down to a few microamps: that’s what gives you months of runtime.
- Many DevKit boards draw several milliamps while asleep because of their regulator and USB chip: for battery use, choose your board carefully.
What voltage does an ESP32 need
The ESP32 is a 3.3 V chip. DevKit boards include a regulator that accepts 5 V over USB or on the 5V/VIN pin and steps it down to 3.3 V. You can also power it directly through the 3V3 pin, but then the voltage has to be within the chip’s range.
On top of that, when transmitting over Wi-Fi the ESP32 draws current spikes of several hundred milliamps, and the manufacturer recommends a supply capable of about 500 mA. A power supply or regulator that can’t handle those spikes causes random resets right as it connects to the network.
If you’re new to the ESP32, first check how it differs from Arduino in ESP32 vs Arduino, where we explain the 3.3 V vs 5 V logic-level issue.
Which battery to choose
| Battery | Voltage | Typical capacity | Pros | Cons |
|---|---|---|---|---|
| LiPo pouch | 3.7 V nominal, 4.2 V full | 500–3,000 mAh | Flat and light | Fragile: don’t puncture or bend it |
| 18650 (Li-ion) | 3.7 V nominal, 4.2 V full | 2,000–3,500 mAh | High capacity, rugged | Large; lots of fakes |
| LiFePO4 | 3.2 V nominal, 3.6 V full | 600–1,500 mAh (18650 size) | Fits the ESP32’s range | Less energy, needs a specific charger |
| 3 alkaline AA batteries | 4.5 V when new | ~2,000 mAh | Easy to swap | Need a regulator; not rechargeable |
A LiPo or an 18650 is the most practical choice for almost everything. If you work with multi-cell LiPos in other projects, the guide to LiPo batteries for drones explains safe charging and storage well.

The regulator: why not just any one will do
A charged LiPo gives 4.2 V and a discharged one about 3.0 V. The regulator has to bring that voltage down to 3.3 V while meeting two conditions:
- Low dropout: the lower it is, the longer it keeps delivering 3.3 V as the battery drains.
- Low quiescent current: what the regulator itself draws, even while the ESP32 sleeps.
The AMS1117 on many boards fails on both counts: it needs a bit more than 1 V of headroom and draws about 5 mA at idle. With that, a sensor that sleeps 99% of the time eats through the battery in days.
You’re better off with an LDO designed for batteries, such as the MCP1700 (quiescent current of a few microamps) or an ME6211 if you need more current. If the LDO has a low maximum current, add a 100–470 µF electrolytic capacitor next to the ESP32 to absorb the Wi-Fi spikes. We compare all the types in linear and switching voltage regulators.
Charging and protecting the battery
A lithium battery is charged with a specific profile (constant current, then constant voltage at 4.2 V). Never connect it directly to 5 V. The most common module is the TP4056:
- Buy the version with protection: it has six pads (IN+, IN−, B+, B−, OUT+, OUT−) and an extra chip that cuts off if the battery is over-discharged or there’s a short circuit.
- Connect the battery to B+ and B−.
- Power the module through its USB port or through IN+ and IN− with 5 V.
- Take power for your circuit from OUT+ and OUT−, toward the regulator.
By default it charges at 1 A. For small batteries (under 1,000 mAh) it’s best to lower the current by changing its programming resistor; check the module’s datasheet.
Another convenient option: ESP32 boards that already have a LiPo charger and JST connector built in. Check their documentation for how much they draw while asleep.

Deep sleep: the trick to make it last for months
Awake and on Wi-Fi, the ESP32 draws tens or hundreds of milliamps. In deep sleep it shuts almost everything down and the chip drops to about 10 µA. A typical sensor wakes up, takes a reading, sends it and goes back to sleep:
#define MINUTOS 10
RTC_DATA_ATTR int arranques = 0; // survives deep sleep
void setup() {
Serial.begin(115200);
arranques++;
Serial.printf("Boot number %d\n", arranques);
// 1. Read the sensor
// 2. Connect to Wi-Fi and send the reading
// 3. Sleep
esp_sleep_enable_timer_wakeup((uint64_t)MINUTOS * 60 * 1000000ULL);
esp_deep_sleep_start();
}
void loop() {
// never reached
}
When it wakes up, the ESP32 boots from scratch: that’s why everything goes in setup(). Only variables marked with RTC_DATA_ATTR keep their value. It can also wake up from a pin (a button, a door sensor) instead of a timer.
To keep the awake time to a minimum:
- Use a static IP instead of DHCP: the Wi-Fi connection takes less time.
- Send the reading over MQTT in a single message and go to sleep.
- Turn off the board’s LEDs and power the sensors from a GPIO pin so you can cut their power while sleeping.

How long will the battery last
Runtime depends on the average current draw. An example with a 2,000 mAh LiPo:
| Scenario | Approximate average draw | Estimated runtime |
|---|---|---|
| Wi-Fi always on | ~100 mA | Less than 1 day |
| DevKit with AMS1117, sleeping | ~5–10 mA | 1–2 weeks |
| Optimized board, awake 5 s every 10 min | ~0.9 mA | 2–3 months |
Work it out with your own numbers in the ESP32 battery life calculator. And measure it for real: with a multimeter in series you’ll see whether your board sleeps the way it should.
Measuring the battery charge
To know when to swap it, measure its voltage with the ADC. Since the battery can reach 4.2 V and the ESP32’s ADC must not go above 3.3 V, use a voltage divider with two equal resistors (for example, 100 kΩ + 100 kΩ): the voltage arrives halved. Use an ADC1 pin, which works with Wi-Fi active.
High resistor values keep the divider’s draw low, but not zero: about 20 µA with 200 kΩ in total, which already shows up on a sleeping sensor.
Frequently asked questions
Can I connect a LiPo directly to the 3V3 pin? No. Fully charged it gives 4.2 V, above what the chip accepts. Always go through a regulator or, on boards designed for it, through their battery input.
What about a LiFePO4 directly? Its voltage (3.6 V full, 3.2 V nominal) falls within the ESP32’s range, and some people connect it without a regulator. It works, but you’re at the upper limit; a low-dropout LDO gives you some margin.
Why does my ESP32 reset when it connects to Wi-Fi on battery? Because of the current spikes: a small regulator, thin wires or a nearly empty battery. Add a large capacitor next to the board and check the regulator.
Dev board or “bare” ESP32? For learning, a DevKit. For a permanent battery-powered sensor, a low-power board or a module with your own regulator. If you want to keep learning, start with our Arduino and ESP32 guide.



