ESP32: power with a LiPo battery and TP4056 or MCP73831 charger
Wire a LiPo battery to an ESP32 with a TP4056 or MCP73831 charger. The safer alternative to 18650 for projects that get handled or carried.
The LiPo (lithium polymer) battery is the right pick for most ESP32 projects that get handled, carried, or sit in a box. It is sealed, soft, and does not have the puncture risk of an 18650 cell. The trade: lower energy density, more expensive per Wh, and the flat-pouch shape does not fit a standard battery holder.
I default to LiPo for wearable projects, sensor boxes that get moved, and anything that might be dropped. I default to 18650 for fixed installs (solar-powered, weatherproof enclosures, anything that sits on a shelf and never gets touched).
The charger is the same idea as the 18650 tutorial: a TP4056 (or MCP73831) handles the CC/CV charge profile and over-discharge protection.
What you need
- 1S LiPo battery (3.7V nominal, 4.2V fully charged; pick a capacity to match your runtime needs; 1000 mAh is a common pick for ESP32 sensor projects)
- TP4056 charge controller board (the kind with battery protection built in; about $1) OR an MCP73831 breakout (about $2, smaller)
- 3.7V to 3.3V LDO regulator (the ME6211 or HT7333 are the standard picks for low quiescent current)
- 100uF electrolytic capacitor for the LDO output
- JST-PH 2.0mm connector (most LiPos ship with this; the TP4056 boards also have a JST-PH port)
- Wires, soldering iron, basic tools
Get a LiPo with a built-in protection circuit (PCM/BMS). The protection circuit cuts off the cell at 2.5V (over-discharge) and 4.3V (over-charge). Bare LiPo cells do not have this; they rely on the charger board to provide it. For most projects, a protected cell + TP4056 is double-protection, which is fine.
Wiring (TP4056)
LiPo + -- TP4056 B+ (or JST-PH red wire)
LiPo - -- TP4056 B- (or JST-PH black wire)
USB 5V -- TP4056 IN+ (or USB-C connector's VBUS pin)
USB GND -- TP4056 IN- (or USB-C connector's GND pin)
TP4056 OUT+ -- LDO IN (3.7-4.2V from the battery)
TP4056 OUT- -- LDO GND
LDO OUT (3.3V) -- ESP32 3.3V
LDO GND -- ESP32 GND
Important: do not power the ESP32 from the TP4056’s OUT+ pin directly. The LiPo is 4.2V when fully charged, which exceeds the ESP32’s 3.3V maximum. The LDO regulator is mandatory.
Wiring (MCP73831)
The MCP73831 is a smaller, single-chip version of the TP4056. The breakout boards are about the size of a SOIC-8 chip. The wiring is the same:
LiPo + -- MCP73831 BAT
LiPo - -- MCP73831 GND
USB 5V -- MCP73831 VCC (5V from USB)
USB GND -- MCP73831 GND
MCP73831 BAT -- LDO IN
The MCP73831’s charge current is set by a single resistor on the PROG pin:
| RPROG | Charge current |
|---|---|
| 20 kohm | 100 mA |
| 10 kohm | 200 mA |
| 5 kohm | 400 mA |
| 2 kohm | 1 A (max) |
For a 1000 mAh LiPo, 500 mA charge current is the safe pick. That is a 4 kohm resistor. Most MCP73831 breakouts have a 2 kohm default, which charges at 1A. For larger LiPos, the 1A rate is fine. For small LiPos (under 500 mAh), drop to 5 kohm or 10 kohm.
What the TP4056 actually does
The TP4056 is a linear charger for single-cell LiPo / Li-ion batteries. It charges using the CC/CV profile:
- Constant current (CC) at the programmed rate (usually 1A, set by R3 on the module) until the battery reaches 4.2V
- Constant voltage (CV) at 4.2V until the charge current drops below 10% of the set rate
This is the standard lithium charging profile. The TP4056 also includes the DW01 protection chip and a dual MOSFET, which provide over-discharge, over-charge, short circuit, and over-current protection. Get the TP4056 with these chips on the board (the “DW01 + 8205A” variant). The bare TP4056 does not have these.
LiPo vs. 18650
| Property | LiPo | 18650 |
|---|---|---|
| Energy density (Wh/kg) | 150-200 | 200-260 |
| Form factor | Flat pouch, soft | Hard cylinder |
| Puncture risk | Low (sealed) | High (fire if punctured) |
| Best for | Wearables, portable | Fixed, high-capacity |
| Cost per Wh | Higher | Lower |
| Voltage | 3.7V nominal | 3.7V nominal |
| Capacity range | 100-5000 mAh | 1000-3500 mAh |
| Common chargers | TP4056, MCP73831 | TP4056, same |
The energy density gap matters less than it looks. A 1000 mAh LiPo weighs about 25g; a 3000 mAh 18650 weighs about 50g. The 18650 has 3x the capacity in 2x the weight, but the LiPo fits in places the 18650 cannot (a flat enclosure, a wristband, a small box).
Reading the battery voltage
The ESP32 can read the LiPo voltage through a divider:
const int BATT_PIN = 34;
const float R1 = 100000.0; // 100k
const float R2 = 100000.0; // 100k (1:1 divider)
float readBatteryVoltage() {
int raw = analogRead(BATT_PIN);
float adcVoltage = raw * 3.3 / 4095.0;
return adcVoltage * (R1 + R2) / R2;
}
Wire the divider between the TP4056 OUT+ pin and ESP32 GND, with the middle node on GPIO 34. The LiPo is 4.2V max; the divider halves that to 2.1V, which the ESP32’s 3.3V ADC can read.
For an accurate state-of-charge percentage, the LiPo discharge curve is non-linear. Approximate table:
| Voltage | State of charge |
|---|---|
| 4.20V | 100% |
| 3.90V | 75% |
| 3.80V | 50% |
| 3.70V | 25% |
| 3.60V | 10% |
| 3.50V | 0% (protection cuts off near here) |
The DW01 protection circuit cuts off the cell at about 2.5V. Do not run a LiPo that low; it damages the cell and reduces its capacity permanently.
Battery life math
A 1000 mAh LiPo at 3.7V nominal is 3.7 Wh. The ESP32 draws about 30 mA active (with Wi-Fi) or 0.1 mA in deep sleep. For a sensor that wakes every minute:
Average current = 0.99 * 0.1 mA + 0.01 * 30 mA = 0.4 mA
Battery life = 1000 mAh / 0.4 mA = 2500 hours = 104 days
For a sensor that wakes every 10 seconds (active current dominates):
Average current = ~3 mA
Battery life = 1000 / 3 = 333 hours = 14 days
The above numbers ignore the TP4056’s quiescent current (~50 uA) and the LDO’s quiescent current (~10 uA for the ME6211). For short projects, those matter; for a 100-day project, they are rounding errors.
LiPo safety
LiPos are safer than 18650s in most ways, but they have their own rules:
- Do not puncture the cell. A punctured LiPo releases electrolyte and can vent flame. The pouch is soft; be careful with sharp tools near it.
- Do not short the terminals. A shorted LiPo can deliver hundreds of amps and overheat. Most LiPos have a PCM that cuts off on over-current, but the protection is not instant.
- Charge at the right rate. Charging faster than 1C (e.g. a 1000 mAh cell at >1A) damages the cell. The TP4056’s default 1A is fine for cells 1000 mAh and up; smaller cells need a lower charge rate.
- Do not charge below 0°C. Lithium plating damages the cell. If the project is outdoors, do not charge when the temperature is below freezing.
- Use a fireproof bag for storage. LiPo charging bags (the flame-retardant pouches) cost a few dollars. Use them for any LiPo you are not actively using.
When the protection circuit trips
The DW01 chip on the TP4056 cuts off the load when the cell drops below 2.5V. The fix: plug in USB. The TP4056 will charge the cell back up to the protection threshold (usually 3.0V) before re-enabling the output.
If the cell is below 2.5V for more than a few days, it is permanently damaged. The voltage may come back, but the capacity will be reduced. Replace the cell.
What you learned
- LiPo is the right pick for projects that get handled.
- TP4056 or MCP73831 handles the charge profile and protection.
- A 1:1 voltage divider on GPIO 34 reads the battery voltage.
- The 3.7V to 3.3V LDO is mandatory; do not power the ESP32 from the raw battery.
When something breaks
- Battery reads 0V or the ESP32 does not power up. Protection circuit tripped. Plug in USB; the TP4056 will charge back up.
- ESP32 resets when Wi-Fi connects. Bulk capacitor too small or missing. Add 100uF across the LDO output.
- TP4056 gets very hot during charging. Charging current is too high for the LiPo size. Replace the R3 resistor with a larger value (e.g. 10 kohm for 130 mA).
- Battery percentage is wrong. The LiPo discharge curve is non-linear. Use a lookup table, not a linear formula.
- LiPo is puffy. Stop using it. A puffy LiPo has internal gas buildup and is a fire risk. Dispose of it at a battery recycling center.
What to build next
- The 18650 with TP4056 tutorial is the right pick for fixed installs.
- The deep sleep tutorial shows the 99%-asleep math for long battery life.
- The book ESP32 in Production has the full LiPo certification (UN38.3) walkthrough for shipping products with lithium batteries.