
ESP32 Battery Sensor Node: Deep Sleep and Power Budget
This battery sensor node runs an ESP32 on battery by waking it on a timer, reading a DHT22 sensor, and putting it back into deep sleep. The ESP32 chip draws about 10 microamps in deep sleep, against 160 to 240 mA with Wi-Fi transmitting. The board keeps drawing milliamps: the regulator, the USB serial chip, and the power LED.
Quick facts
| Item | Value |
|---|---|
| Sleep current, chip | About 10 uA in deep sleep, ESP32 Series Datasheet v5.3 |
| Awake current | 80 to 160 mA, peaks near 240 mA on Wi-Fi transmit |
| Wake source | RTC timer, every 10 minutes |
| Sensor | DHT22, temperature and humidity |
| Power | Battery pack through an XL4015 buck converter set to 5 V |
| No solar | This build uses battery power only; no solar panel is fitted |
Battery sensor node: how does deep sleep save battery?
Deep sleep powers down the main CPUs, the Wi-Fi and Bluetooth radios, and most peripherals. Only the RTC domain stays alive, with its timer and a small block of RTC memory. The chip draws about 10 microamps in that state, against 160 to 240 mA with Wi-Fi transmitting. That is a reduction of about 24,000 times.
Deep sleep is effectively a reboot. When the timer fires, the bootloader runs, the sketch loads from flash again, and setup() starts from the top. Normal variables are lost. Only variables tagged RTC_DATA_ATTR survive, in the 8 KB RTC slow memory, so the sketch keeps its boot count there and does its work in setup().
The pattern is wake, work, sleep. The node wakes every 10 minutes, reads the DHT22, connects to Wi-Fi, sends the reading, and sleeps again. The awake time is a few seconds. The sleep time is 597 seconds. Average current is what decides battery life, and the average is dominated by the few awake seconds, not the long sleep.
Why does a dev board never reach 10 microamps?
The 10 microamp figure is the bare ESP32 chip, from the Espressif ESP32 Series Datasheet v5.3. A DevKit V1 board adds an always-on power LED, a USB to serial chip, and a linear regulator, and each of those draws current around the clock. A typical DevKit V1 measures a few milliamps in deep sleep, not 10 microamps. That is still a large saving over 160 mA awake, but it changes the battery math by a factor of 100.
Measure your own board before you promise battery life. Put a USB power meter inline, or a multimeter on the battery lead, and read the current in deep sleep. Write the number down. Every battery estimate in this post uses a 1 mA planning figure for the whole node, not a measured board value, because no bench measurement of the stocked board exists. Replace the planning figure with your measured value before you promise a battery life.
You can cut the board overhead further by removing the power LED or by using a bare module, but that is a hardware modification and it voids any return. For a first build, measure the board as it ships and size the battery for the measured figure.
How do you work out the battery life?
Average current is the awake share times the awake current, plus the sleep share times the sleep current. Wake for 3 seconds at 150 mA every 600 seconds, and sleep at 1 mA the rest of the time. The awake share is 3 divided by 600, or 0.5 percent. The average is 0.005 times 150 mA plus 1 mA, which is about 1.75 mA.
Divide the battery capacity by the average current to get the life. A 2500 mAh pack at 1.75 mA average lasts about 1400 hours, or about 59 days. That is an estimate, not a promise. Cold weather cuts capacity, the buck converter wastes 10 to 20 percent, and the Wi-Fi connect time varies with signal strength.
The biggest lever is the awake time. Every second of Wi-Fi connect time at 150 mA costs as much as 150 seconds of sleep at 1 mA. Keep the awake work short: read the sensor first, connect, send one small packet, and sleep. Do not wait for a slow server, and do not retry forever. Three tries, then sleep and try again next cycle.
How do you power the node from a battery?
The XL4015 buck converter steps the battery voltage down to a steady 5 V for the ESP32 USB input or the 5 V pin. Set the output to 5 V with a multimeter before you connect the board, and never adjust the trimmer while the board is connected. A wrong turn can send the full battery voltage into the board.
The buck converter itself draws current, even with no load. That quiescent draw joins the sleep current, so measure the whole node, converter included, not the board alone. The XL4015 chip draws 2.1 mA typical and 5 mA maximum quiescent current (XLSEMI datasheet Rev 1.6), and the stocked module adds an LED display that draws more, so a converter that draws 5 mA idle will dominate a node that sleeps at 1 mA. The chip runs from 8 to 36 V in and 1.25 to 32 V out; the module is advertised at 4 to 38 V in, 1.25 to 36 V out, and 5 A. Feed it from a battery inside the module range and set the output to 5 V.
This build uses battery power only. No solar panel is fitted, and no solar claim is made, because no solar panel is stocked for this build. If you add solar later, size the panel for the average current plus the charge controller losses, and test it through a cloudy week before you trust it.
Wiring
Wire the build with the power off. Check every connection in the table before you connect any battery or USB cable.
| From | To | Notes |
|---|---|---|
| Battery pack positive | XL4015 IN+ | Battery input to the buck converter; set the output before connecting the board |
| Battery pack negative | XL4015 IN- and ESP32 GND | Common ground |
| XL4015 OUT+ | ESP32 5 V pin or USB 5 V | Regulated 5 V output; set to 5.0 V with a multimeter first |
| XL4015 OUT- | ESP32 GND | Common ground |
| DHT22 VCC | ESP32 3V3 | Module supply 3.3 to 6 V per the Aosong datasheet; the stocked module is a wired 3-wire module (+, -, Out) |
| DHT22 GND | ESP32 GND | Common ground |
| DHT22 DATA | ESP32 GPIO 4 | Single-wire data; 10 k pull-up resistor between DATA and 3V3 if the module has none |
Power budget
The budget below uses a 1 mA planning figure for the sleep current of the whole node, board plus buck converter, because that is the honest planning figure for a DevKit V1 as shipped. It is a planning figure, not a bench measurement: no measured sleep current exists for the stocked board. The chip alone sleeps at about 10 microamps, but the board overhead dominates. Measure your node and redo the math with the measured value.
Awake for 3 seconds at 150 mA every 600 seconds, asleep at 1 mA otherwise, gives an average of about 1.75 mA. A 2500 mAh pack lasts about 59 days at that average, before converter losses and cold weather. Cut the wake interval to 30 minutes and the same pack lasts about 83 days, not 4 months: the awake share falls to one third, but the 1 mA sleep current dominates the average, so tripling the interval only stretches the life by about 40 percent. A slow Wi-Fi join stretches the awake time too: about 13 seconds awake per cycle cuts the same pack to about 25 days.
The DHT22 draws 1 to 1.5 mA while measuring and 40 to 50 uA in standby, per the Aosong datasheet, and the bare sensor pins run VCC, DATA, NC, GND with the grille facing you. Do not read it more often than once every 2 seconds. It is a rounding error next to the Wi-Fi radio. The radio is the cost. Keep the awake time short, send one small packet, and sleep.
Build steps
- Set the XL4015 output to 5.0 V with a multimeter, with no board connected. Lock the trimmer and recheck the output.
- Wire the battery, the buck converter, and the ESP32 from the wiring table. Wire the DHT22 to GPIO 4 with its pull-up resistor.
- Install the Adafruit DHT sensor library and the Adafruit Unified Sensor library from the Library Manager.
- Upload the sketch below. Open the serial monitor at 115200 baud and confirm the node reads the DHT22 and prints the boot count.
- Measure the deep sleep current with a USB power meter or a multimeter on the battery lead. Record the value and update the battery math in this post.
- Leave the node running on battery for 24 hours. Confirm it wakes every 10 minutes and the boot count rises by about 144 per day.
- Calculate the battery life from your measured sleep current, not from the 10 microamp chip figure. Replace the planning figure in this post with the measured value.
Code
Libraries: Adafruit DHT sensor library, Adafruit Unified Sensor library. Board: ESP32 DevKit V1. The sketch does its work in setup() because deep sleep restarts the chip on every wake.
// Battery ESP32 sensor node: DHT22 + deep sleep, timer wake
// Board: ESP32 DevKit V1. Libraries: Adafruit DHT sensor library.
#include
#include
#include
#define DHT_PIN 4
#define DHT_TYPE DHT22
#define uS_TO_S 1000000ULL
#define SLEEP_SECONDS 600 // Wake every 10 minutes
const char* WIFI_SSID = "YOUR_WIFI_NAME"; // Replace with your network
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; // Replace with your password
DHT dht(DHT_PIN, DHT_TYPE);
// RTC memory survives deep sleep; normal variables do not.
RTC_DATA_ATTR int bootCount = 0;
void setup() {
Serial.begin(115200);
bootCount++;
Serial.print("Boot count: ");
Serial.println(bootCount);
dht.begin();
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("DHT22 read failed");
} else {
Serial.print("Temp: "); Serial.print(temperature, 1);
Serial.print(" C, Hum: "); Serial.print(humidity, 1);
Serial.println(" %");
// Join Wi-Fi with a bounded wait, then send the reading here:
// HTTP POST, MQTT, or ESP-NOW. Keep it short: connect, send
// once, then sleep. A slow join stretches the awake time, so
// the 10 second cap below keeps one bad cycle from draining
// the battery.
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long wifiStart = millis();
while (WiFi.status() != WL_CONNECTED && millis() - wifiStart < 10000) {
delay(500);
}
}
// Arm the RTC timer, then sleep. This call never returns.
esp_sleep_enable_timer_wakeup(SLEEP_SECONDS * uS_TO_S);
Serial.println("Going to sleep for 10 minutes");
Serial.flush(); // Let the text leave before power drops
esp_deep_sleep_start();
}
void loop() {
// Never reached: deep sleep restarts the chip from setup().
}
Test and tune it
Confirm the node wakes every 10 minutes by watching the boot count rise by 6 per hour. A count that rises faster means the node is resetting instead of sleeping, usually from a weak battery or a loose wire.
Measure the sleep current with the USB cable unplugged and the battery connected. If the meter reads over 5 mA in sleep, the buck converter quiescent draw or the power LED is the cause. Measure the board alone, then the converter alone, to find which one dominates.
Run the node for a week on battery and log the battery voltage at each wake. A steady fall is normal. A sudden drop means the Wi-Fi connect time grew, usually from a weak signal, so move the node closer to the router.
FAQ
How long will an ESP32 sensor node last on battery?
It depends on the measured sleep current, not the 10 microamp chip figure. At 1.75 mA average, a 2500 mAh pack lasts about 59 days. Measure your board in deep sleep and redo the math with that number.
Why does my ESP32 use more power asleep than the datasheet says?
The datasheet figure is the bare chip. The DevKit board adds a power LED, a USB serial chip, and a regulator, and each draws current around the clock. Measure the whole board, not the chip.
What wakes the ESP32 from deep sleep?
The RTC timer is the workhorse: wake every N minutes to sample and report. A pin, a touch pad, or the ULP coprocessor can also wake it. This build uses the timer only.
Does deep sleep keep my variables?
No. Deep sleep restarts the chip, so normal variables are lost. Only variables tagged RTC_DATA_ATTR survive, in the 8 KB RTC slow memory. Keep counters and last readings there.
Can I add solar power to this node?
Not in this build. No solar panel is stocked for it, so no solar claim is made here. A solar version needs a panel, a charge controller, and a cloudy-week test before you trust it.
Parts used
Build it with the ESP32 DevKit V1 Development Board, 30-Pin WROOM-32, the DHT22 / AM2302 Digital Temperature & Humidity Sensor Module, and the XL4015 5A DC-DC Step Down Buck Converter Module with LED Display, 2-Pack. The always-on version is ESP32 WiFi Sensor Telemetry: Live Dashboard with BME280, and the flash logging version is ESP32 Sensor Data Logger: Flash Logging and WiFi Download. For the chip radios behind the choice, see ESP32 vs ESP32-S3 vs ESP32-C3 vs ESP32-C6.
Sources
- Aosong DHT22 / AM2302 datasheet
- XLSEMI XL4015 datasheet, Rev 1.6
- Espressif sleep modes API reference
- Espressif ESP32 Series Datasheet
- Adafruit DHT sensor library
Last updated: 2026-11-21. Search volume: not verified. Product links use the store short link form with the product ID; confirm the product slug at publish time.
For the ESP-NOW protocol behind the gateway pattern, see ESP-NOW Explained: Two ESP32 Boards, No Router.
