ESP32: wire a 18650 battery with a TP4056 charge controller
Wire a single 18650 cell to an ESP32 using the TP4056 charge controller. The minimum circuit for any battery-powered ESP32 project.
The single most useful battery for ESP32 projects is the 18650 cell. It is the same battery used in laptops, vape pens, and Tesla Powerwalls (scaled up). It has high energy density, is rated for hundreds of charge cycles, and is available for $3-5 per cell from reputable sources.
Pair it with the TP4056 charge controller and you have a battery system that charges over USB, has built-in over-discharge protection, and powers the ESP32 at 3.3V via a regulator. This tutorial is the minimum circuit.
What you need
- One 18650 cell (use a genuine Samsung, LG, Panasonic, or Sony cell. Counterfeit 18650s are everywhere and can be dangerous.)
- TP4056 charge controller board (the kind with battery protection built in; about $1 from anywhere)
- 3.7V to 3.3V LDO regulator (the ME6211 or HT7333 are the standard picks. The AMS1117-3.3 also works but has higher quiescent current.)
- One 100uF electrolytic capacitor
- One 10uF electrolytic capacitor
- Wires, soldering iron, basic tools
“TP4056 with protection” is the version you want. The bare TP4056 chip does not include the over-discharge protection circuit. The modules with “DW01” or “8205A” markings on them have it. Modules without those markings do not.
Wiring
18650 + --- TP4056 B+
18650 - --- TP4056 B-
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
The TP4056 charges the 18650 from any 5V source (USB). It outputs the battery’s voltage (3.0-4.2V depending on charge state) on OUT+. The LDO regulator drops that to 3.3V for the ESP32.
Important: do not power the ESP32 from the TP4056’s OUT+ pin directly. The battery voltage is 4.2V when fully charged, which exceeds the ESP32’s 3.3V maximum. The LDO regulator is mandatory.
What the TP4056 actually does
The TP4056 is a single-chip linear charger for single-cell lithium-ion batteries. It charges at a configurable rate (typically 1A, set by the R3 resistor on the module) using the CC/CV profile:
- Constant current (CC) at 1A 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-ion charging profile. Doing it wrong (over-voltage, over-current, fast charge at high temperature) damages the cell and can cause fire. The TP4056 handles all of that.
The TP4056 board also includes the DW01 protection chip and a dual MOSFET (8205A). These provide:
- Over-discharge protection. Disconnects the battery from the load when voltage drops below about 2.5V. Prevents the cell from being damaged by deep discharge.
- Over-charge protection. Disconnects the charger when voltage exceeds 4.3V.
- Short circuit protection. Disconnects the load on a short.
- Over-current protection. Disconnects the load above about 3A.
These protections are why you want the version with the protection circuit, not the bare TP4056 chip.
Reading the battery voltage
The ESP32 can measure its own supply voltage using the ADC’s internal hall-sensor channel as a proxy, but the cleaner way is to read the battery voltage through a voltage divider:
const int BATT_PIN = 34;
const float R1 = 100000.0; // 100k
const float R2 = 100000.0; // 100k (gives 50% 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. With R1 = R2 = 100k, the divider halves the voltage, so the formula above is correct for a 1:1 divider.
The ESP32 draws about 10 uA through the divider continuously. That is small enough not to matter for most projects. For ultra-low-power projects, use a 1M + 1M divider (1 uA) and account for the ADC’s internal resistance.
Battery life math
A genuine 18650 cell has about 2500-3500 mAh capacity at 3.7V nominal. Convert to watt-hours:
Wh = Ah * V = 2.5 Ah * 3.7 V = 9.25 Wh
The ESP32 draws about 30 mA active (with Wi-Fi), or about 0.1 mA in deep sleep with periodic wake-up. If you sleep 99% of the time and wake briefly every minute:
Average current = 0.99 * 0.1 mA + 0.01 * 30 mA = 0.4 mA
Battery life = 2500 mAh / 0.4 mA = 6250 hours = 260 days
That assumes a single wake per minute. For projects that wake more often (e.g. every second), the active current dominates and the battery lasts about a week.
The charging current
The TP4056 charges at a current set by the R3 resistor on the module:
| R3 value | Charge current |
|---|---|
| 1.2 kohm | 1 A (default on most modules) |
| 2.0 kohm | 580 mA |
| 3.0 kohm | 400 mA |
| 5.0 kohm | 250 mA |
| 10 kohm | 130 mA |
| 20 kohm | 50 mA |
For most 18650 cells, 0.5-1 A is the standard charge rate. Charging faster than the cell’s spec (usually 0.5C, where C is the capacity) damages the cell. For a 2500 mAh cell, max safe charge current is 1250 mA.
The 100uF capacitor
The TP4056’s output has a small amount of switching noise. The 100uF capacitor across OUT+ and OUT- smooths this for the ESP32. Without it, the ESP32 may brown-out during Wi-Fi activity.
What you learned
- TP4056 with the DW01 protection chip is the standard charger for 18650 cells in ESP32 projects.
- LDO regulator (3.7V to 3.3V) is mandatory; the ESP32 cannot handle the 4.2V fully-charged battery voltage.
- Voltage divider on GPIO 34 lets you read battery voltage through the ADC.
- Realistic battery life is months to a year for typical sensor projects.
When something breaks
- Battery reads 0V or the ESP32 does not power up. Battery is dead or the protection circuit tripped. Plug in USB; the TP4056 will charge the cell back up to the protection threshold.
- ESP32 resets when Wi-Fi connects. Bulk capacitor too small or missing. Add 100uF across the LDO output.
- Battery gets hot during charging. Counterfeit cell. Genuine cells do not get more than slightly warm during 1A charging.
- TP4056 LED does not light. No USB power, or bad USB cable (charge-only, not data and power).
What to build next
- The deep sleep tutorial shows the code patterns for the 99%-asleep math above.
- The solar + 18650 tutorial covers adding a small solar panel for perpetual battery projects.
- The book ESP32 in Production covers battery certification (UN38.3) for shipping products with lithium batteries.