3,000 mAh10 µAGPIO34ESP32RTCz zWi-Fi1void setup() {2 setCpuFrequencyMhz(80);3 int m = analogRead(34);4 sendReading(m);5 esp_sleep_enable_timer_wakeup(T);6 esp_deep_sleep_start();7}state mA s mA·ssleep 0.01 600 6sense 31 1 31send 240 2 480total 603 517m
01002003004000100020003000daysmAhCHARGE LEFT IN THE CELLnever sleepsevery 10 minevery 30 min
Back: the sensor node (battery, current meter, ESP32 with its RTC timer, soil sensor, Wi-Fi antenna)Front: the firmware card and the power budget card; below, the plot of charge left over daysTokens: charge leaving the battery (more tokens, more current), the reading and Wi-Fi packetsA battery-powered ESP32 soil sensor: a 3,000 mAh cell, a current meter, the chip with its RTC timer, a soil sensor and a Wi-Fi antenna, with the firmware and the power budget on cards in front. Each 603 s cycle uses 517 mA·s: 6 asleep, 31 sensing, 480 sending. That is 0.86 mA on average, so the cell lasts about 146 days. The plot drains the cell for three designs: never sleeping (4 days), waking every 10 minutes (146 days) and every 30 minutes (426 days).

One wake-up

  1. 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.

Do the sums

Make it last

What happens

;; step 1/11 · budget
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 again

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. 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.