Why your ESP32 battery dies so fast
Where the power really goes in a small battery device, and the simple changes that took one of mine from 1 day to 3.
The first version of a battery device usually works great on your desk, on a USB cable. Then you put a battery in it, and it's dead by tomorrow.
On a smart-bottle project, I cut power use by about 66%, and battery life went from 1 day to 3 days. No new battery, no new chip. Just turning things off.
The only formula you need
Battery life is simple division:
hours = battery capacity (mAh) ÷ average current (mA)For example, with a 1000 mAh battery:
| Average current | Battery life |
|---|---|
| 40 mA | ~25 hours (about 1 day) |
| 13 mA | ~77 hours (about 3 days) |
So the goal is not "a bigger battery". The goal is a smaller average current.
Where the current goes
A rough picture of an ESP32 (exact numbers depend on the chip and the board):
| State | Current |
|---|---|
| Wi-Fi sending | 100+ mA |
| Awake, radio off | tens of mA |
| Light sleep | under 1 mA |
| Deep sleep (chip only) | around 10 µA |
Look at the jump from "awake" to "sleep". That's a thousand times less. Every second your chip spends awake when it doesn't need to is expensive.
Step 1: turn off what nobody is using
The chip is often not the biggest drain. The things around it are: a display, its backlight, sensors that sample all the time, LEDs.
- Turn the display off when nobody is looking at it.
- Put sensors into their own low-power mode between readings.
- Turn off Wi-Fi or Bluetooth until you actually need to send something.
Step 2: sleep, and let the hardware wake you
The best device sleeps most of the time. But then how does it know when to wake up?
Many accelerometers can watch for movement by themselves, and pull an interrupt pin high when they feel motion. Connect that pin to an RTC-capable GPIO on the ESP32, and the sleeping chip wakes up when the device is picked up:
// Wake up when the accelerometer's interrupt pin goes HIGH
esp_sleep_enable_ext0_wakeup(GPIO_NUM_4, 1);
esp_deep_sleep_start();Now the chip isn't checking "did anything move?" a thousand times a second. A tiny sensor does it for almost no power, and the chip sleeps.
Step 3: measure, don't guess
Before changing anything, measure the current in each state with a USB power meter or a multimeter. Write the numbers down. Then change one thing at a time and measure again. You will often be surprised where the power actually goes.
The short version
- Battery life = capacity ÷ average current.
- Turn off the display, sensors and radio when nobody needs them.
- Sleep as much as possible, and let an interrupt wake the chip.
- Measure before and after every change.