Power budgets and battery life
About this lesson
How long will a battery device last? Write a power budget: every state the device is in, the current it draws there and for how long. Follow one wake-up of an ESP32 soil sensor (deep sleep at 10 µA, sensing at 31 mA, Wi-Fi at 240 mA), add up the charge, find the 0.86 mA average and turn a 3,000 mAh cell into about 146 days. Then see which levers matter: the radio, how often it wakes, and sleep itself. The Hardware lessons “How batteries work” and “Power supplies” explain capacity and regulators; here we spend that capacity.
Where the charge goes
A battery holds a fixed amount of charge. A power budget lists each state a device is in, the current it draws there and for how long. Our example: an ESP32 soil sensor that reports every 10 minutes.
power budget every state the device is in:
current (mA) and time (s)
device ESP32 soil sensor, 3,000 mAh cell
cycle sleep -> wake, sense -> send -> sleep
// ESP32 (Arduino core): soil sensor on GPIO34, one report every 10 minutes
const uint64_t T = 600ULL * 1000000ULL; // 600 s, in microseconds
void sendReading(int m) {
// join Wi-Fi and send m: the connectivity lessons show how
}
void setup() {
setCpuFrequencyMhz(80);
int m = analogRead(34);
sendReading(m);
esp_sleep_enable_timer_wakeup(T);
esp_deep_sleep_start();
}
void loop() {} // never reached: waking from deep sleep boots againRead the lesson step by step
Where the charge goes
A battery holds a fixed amount of charge. A power budget lists each state a device is in, the current it draws there and for how long. Our example: an ESP32 soil sensor that reports every 10 minutes.
power budget every state the device is in: current (mA) and time (s) device ESP32 soil sensor, 3,000 mAh cell cycle sleep -> wake, sense -> send -> sleep // ESP32 (Arduino core): soil sensor on GPIO34, one report every 10 minutes const uint64_t T = 600ULL * 1000000ULL; // 600 s, in microseconds void sendReading(int m) { // join Wi-Fi and send m: the connectivity lessons show how } void setup() { setCpuFrequencyMhz(80); int m = analogRead(34); sendReading(m); esp_sleep_enable_timer_wakeup(T); esp_deep_sleep_start(); } void loop() {} // never reached: waking from deep sleep boots againSleep: 10 µA for 600 s
Most of the time the chip is in deep sleep. The processors and most memory are off; only a small real-time clock (RTC) keeps counting. The datasheet gives 10 µA. That lasts 600 seconds.
lines 5-6 esp_sleep_enable_timer_wakeup(T); esp_deep_sleep_start(); deep sleep CPUs, most RAM, digital peripherals off RTC timer + RTC memory on: 10 µA time 600 s (T = 600,000,000 µs) charge 0.01 mA x 600 s = 6 mA·sSense: 31 mA for 1 s
The RTC timer wakes the chip and setup() starts again from the top. With the processor at 80 MHz and the radio off, it draws up to 31 mA. Reading the sensor takes about 1 second.
wake the program boots again: setup() from line 1 line 2 setCpuFrequencyMhz(80); line 3 int m = analogRead(34); 0..4095 (12 bits) current 20 to 31 mA at 80 MHz, radio off: budget 31 charge 31 mA x 1 s = 31 mA·sSend: 240 mA for 2 s
Now Wi-Fi joins the network and sends the reading. The radio transmits at up to 240 mA. Joining and sending take about 2 seconds, so we budget 240 mA for the whole 2 seconds.
line 4 sendReading(m); join Wi-Fi, send transmit 240 mA (802.11b, +19.5 dBm) receive 95 to 100 mA budget 240 mA for all 2 s: a cautious figure charge 240 mA x 2 s = 480 mA·sCharge = current × time
Charge is current times time. In milliamp-seconds (mA·s): sleep 0.01 × 600 = 6, sense 31 × 1 = 31, send 240 × 2 = 480. One whole cycle of 603 seconds uses 517 mA·s.
state mA s mA·s sleep 0.01 600 6 sense 31 1 31 send 240 2 480 total 603 517 charge (mA·s) = current (mA) x time (s)The average current
Spread that charge over the whole cycle: 517 mA·s ÷ 603 s = 0.86 mA. To the battery the device looks like a steady 0.86 mA load, even though it really draws short bursts.
average = charge / cycle time = 517 mA·s / 603 s = 0.857 mA asleep 99.5% of the time, but the bursts set the averageBattery life
Capacity is in milliamp-hours (mAh). A 3,000 mAh cell can give 0.86 mA for 3,000 ÷ 0.86 ≈ 3,500 hours. That is about 146 days, almost five months on one charge.
capacity 3,000 mAh (1 mAh = 3,600 mA·s) life = capacity / average current = 3,000 mAh / 0.857 mA = 3,499 h = 145.8 days per day 20.6 mAhThe radio is the cost
Of the 517 mA·s, the send uses 480: 93%. Sleep is only about 1%. So shaving microamps off sleep barely helps here. Sending less often, or for less time, is the big lever.
sleep 6 mA·s 1.2% sense 31 mA·s 6.0% send 480 mA·s 92.8% total 517 mA·s 100.0% cut the biggest row firstWithout sleep: 4 days
If the chip never slept and stayed awake at 31 mA, the same cell would last 3,000 ÷ 31 ≈ 97 hours: about 4 days. Sleep is what turns days into months.
always awake 31 mA, radio off life 3,000 mAh / 31 mA = 96.8 h = 4.0 days with sleep 145.8 days: 36 times longerWake every 30 minutes
Set the timer to 30 minutes (1,800 s). Each cycle now uses 529 mA·s over 1,803 s: 0.29 mA on average. The battery lasts about 426 days, almost three times longer.
line 5 T = 1800ULL * 1000000ULL; // 30 min sleep 0.01 mA x 1,800 s = 18 mA·s cycle 529 mA·s / 1,803 s = 0.293 mA life 3,000 / 0.293 = 10,225 h = 426.0 daysLeave a margin
Real cells give less. A lithium-ion cell loses 1 to 2% of its charge a month on its own, and its protection circuit about 3% more. Cold, regulators and LEDs cost too. Budget with a safety margin.
self-discharge 1-2% a month (after the first day) protection about 3% a month more also cold, the regulator, LEDs, a USB chip so measure the real board, keep a margin
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01A device draws 240 mA for 2 seconds. How much charge is that?
Charge is current times time: 240 mA × 2 s = 480 mA·s (milliamp-seconds).
02One cycle uses 517 mA·s and lasts 603 s. What is the average current?
Average current = charge ÷ time = 517 ÷ 603 ≈ 0.86 mA. The bursts are big but short, so the average is small.
03About how long does a 3,000 mAh cell last at an average of 0.86 mA?
3,000 mAh ÷ 0.86 mA ≈ 3,500 hours, which is about 146 days. Real cells give somewhat less (self-discharge, cold, the regulator).
04In this budget the send uses 480 of 517 mA·s. Which change helps battery life most?
The send is 93% of the charge, so sending half as often nearly halves the average current. Halving the sleep current saves only 3 of 517 mA·s.
05What happens when an ESP32 wakes from deep sleep on its timer?
Deep sleep turns off the processors and most memory, and Wi-Fi connections are dropped. Waking is like a reset: the firmware boots again, so setup() does the work and then calls esp_deep_sleep_start() once more.
Glossary
- Power budget
- A table of every state a device is in, the current it draws there and for how long, used to work out its average current and battery life.
- Charge (mA·s, mAh)
- Current multiplied by time. 1 mAh is 1 mA for an hour, which is 3,600 mA·s.
- Capacity (mAh)
- How much charge a battery can deliver. A 3,000 mAh cell could, ideally, give 3 mA for 1,000 hours.
- Average current
- The total charge used over a cycle divided by the cycle's length: the steady current that would drain the battery at the same rate.
- Duty cycle
- The fraction of time a device spends awake. Low-power devices are awake for a tiny fraction and asleep the rest.
- Deep sleep
- An ESP32 power mode in which the processors and most RAM are off; only the RTC timer and RTC memory stay on (about 10 µA).
- RTC timer
- A small real-time clock that keeps counting while the chip sleeps and wakes it at a set time.
- Self-discharge
- The slow loss of charge a battery suffers even with nothing connected.
Notes and sources
- Currents are from the Espressif ESP32 datasheet (v5.3): deep sleep with the RTC timer and RTC memory on, 10 µA; processor on at 80 MHz with the radio off, 20 to 31 mA (we take the top); Wi-Fi transmit at +19.5 dBm, 240 mA; receive, 95 to 100 mA. The 1 s and 2 s awake times are this example's assumptions.
- Budgeting 240 mA for the whole send is cautious: while it joins the network the radio is often receiving (95 to 100 mA) or idle. Real budgets come from measuring the board with a current meter or a power analyser.
- The figures are for the ESP32 chip itself. A development board adds a voltage regulator, a USB chip and LEDs, which can draw far more than the sleeping chip; battery devices use bare modules or boards built for low power.
- The 3,000 mAh cell is the teaching cell from the Hardware lesson "How batteries work". The plot drains it in a straight line at the average current and ignores self-discharge, so real lives are shorter.
- Waking from deep sleep is like a reset: the program boots again and setup() runs from the top, so loop() is never reached. Anything that must survive the sleep goes in RTC memory or flash.
- Espressif, ESP32 Series Datasheet v5.3 (tables 4-2 and 5-4: power modes and RF currents)
- ESP-IDF Programming Guide: Sleep Modes (ESP32)
- ESP-IDF Programming Guide: Deep-sleep Wake Stubs (ESP32)
- Arduino-ESP32 core: esp32-hal-cpu.h (setCpuFrequencyMhz)
- Arduino-ESP32 documentation: ADC (analogRead)
- Battery University BU-802b: What does Elevated Self-discharge Do?
Quiz Unlocks after the last step.