Blog
ESP32 Deep Sleep: Wakeup, Power
ESP32 deep sleep is what turns a battery-eating dev board into a months-long sensor node — or would, if the LED and regulator did not eat the savings. The wakeup sources, the current numbers, and why your meter disagrees with the datasheet.
What Is Deep Sleep on the ESP32?
Deep sleep powers down the CPU, most RAM, and the radios while a tiny RTC domain keeps the clock and a few kilobytes alive. The chip wakes on a timer, a pin, or the ULP coprocessor, runs your code, and sleeps again. It is the difference between hours and months of battery life on the same board.
How to Put ESP32 in Sleep Mode?
Two lines, in Arduino: configure a wakeup source, then esp_deep_sleep_start(). The board resets into your setup() when it wakes — code after the sleep call never runs. Configure the wakeup before the sleep call each time, because the sketch runs from the top on every boot.
How Do I Wake on a Timer?
esp_sleep_enable_timer_wakeup(60 * 1000000UL) wakes the chip every 60 seconds — the argument is microseconds. This is the pattern for sensor nodes: sleep an hour, read the sensor, publish, sleep again. Accuracy is good enough for logging; the RTC oscillator drifts a little with temperature, so time-of-day work still wants an NTP sync on wake.
How Do I Wake on a Button Press?
esp_sleep_enable_ext0_wakeup(GPIO_NUM_4, LOW) wakes on one RTC-capable pin going low or high. esp_sleep_enable_ext1_wakeup covers several pins with a mask — handy for door sensors and motion detectors. Only RTC GPIOs work here: GPIO 0, 2, 4, and a few others, depending on your exact chip revision.
How Much Current Does Deep Sleep Draw?
The chip itself draws roughly 2.5 to 10 µA in deep sleep current with the RTC timer on. The board you actually own draws more: regulator and power LED add 20 to 100 µA, and some USB bridges pull milliamps even asleep. Measure yours — the datasheet is the floor, not the reality.
Why Does My Battery Still Die Overnight?
Because something stays awake — usually the power LED (unsolder it), the regulator’s quiescent current, or code that never reaches the sleep call. A sketch that prints every loop keeps the chip busy if sleep sits in the wrong place. The power FAQ goes through each drain.
How Do I Keep Variables During Sleep?
Mark them RTC_DATA_ATTR — variables in RTC memory survive deep sleep and reappear on wake. For structured data, NVS storage does the same job with a flash-backed guarantee. Everything else in RAM is gone, and forgetting that produces the classic “why is my counter back at zero” bug.
Can the ESP32 Sense Anything While Asleep?
Yes, with the ULP coprocessor: it runs tiny programs from RTC memory, samples ADC pins, counts pulses, and wakes the CPU on a threshold — all at single-digit microamp costs. It is fiddly, and I have never needed it where a timer plus an interrupt pin did the job. Depending on your board, ext0 is the pragmatic 90% solution.
Light Sleep vs Deep Sleep — What’s the Difference?
Light sleep pauses the CPU but keeps RAM and Wi-Fi state, waking in microseconds — yet it draws roughly 0.8 mA. Deep sleep loses RAM and takes ~10 ms to boot but lands at microamps. For battery projects deep sleep wins; light sleep only makes sense when you must resume instantly. The under-the-hood FAQ explains what stays alive.
How Do I Measure Deep Sleep Current?
Put a multimeter in milliamps on the battery line, not through USB. The reading dances between the sleep baseline and a few mA during boot. A 10 µA goal is below most meters’ resolution, so use the µA range and short leads — or accept that “under a millamp” is good enough for most projects. The examples gallery has battery-node sketches.
What Deep Sleep Cost Is — and What We Can Show You
Honest limit: the simulator does not model sleep current, so microamp metering stays on the bench. What you can rehearse here is the wake logic — the event source that will interrupt the nap: PIR motion events, encoder edges, a button press. Get the wake conditions right virtually; measure the amps for real.