ESP32 Deep Sleep: Ultra-Low Power for Battery-Powered IoT
Deep sleep is the ESP32's most power-efficient mode, drawing as little as 10-150 µA. This is essential for battery-powered IoT devices that need to run for months or years.
In deep sleep, the ESP32 powers down almost everything except the RTC (Real-Time Clock) and ULP (Ultra-Low Power) coprocessor. It can wake up via timer, external interrupt, touch pad, or ULP program.
Deep Sleep Current Consumption
| Mode | Typical Current |
|---|---|
| Active (WiFi on) | 80–240 mA |
| Modem sleep (CPU on, WiFi off) | 20–40 mA |
| Light sleep | 0.8–1.5 mA |
| Deep sleep | 10–150 µA |
Timer Wake-Up
void setup() {
Serial.begin(115200);
Serial.println("Setup complete. Going to sleep for 10 seconds...");
// Configure timer wake-up (10 seconds = 10,000,000 microseconds)
esp_sleep_enable_timer_wakeup(10 * 1000000);
// Start deep sleep
esp_deep_sleep_start();
// This line never executes — board restarts after sleep
Serial.println("This will never print");
}
void loop() {
// Never reached
}External Wake-Up (GPIO)
const int wakeupPin = 4; // GPIO 4 (RTC GPIO)
void setup() {
Serial.begin(115200);
Serial.println("Setup complete. Waiting for button press on GPIO 4...");
// Enable external wake-up on RTC GPIO
esp_sleep_enable_ext0_wakeup((gpio_num_t)wakeupPin, LOW);
esp_deep_sleep_start();
}
void loop() {}Battery Life Estimation
For a device that:
- Wakes up every 10 minutes
- Runs for 2 seconds (connects to WiFi, sends data)
- Deep sleeps the rest of the time
Average current ≈ (240 mA × 2s + 100 µA × 598s) / 600s ≈ 0.9 mA
With a 2000 mAh battery: Battery life ≈ 2000 mAh / 0.9 mA ≈ 2222 hours ≈ 92 days
RTC Memory (Survives Deep Sleep)
Data stored in RTC memory survives deep sleep:
RTC_DATA_ATTR int bootCount = 0;
void setup() {
Serial.begin(115200);
bootCount++;
Serial.printf("Boot count: %d\n", bootCount);
esp_sleep_enable_timer_wakeup(10 * 1000000);
esp_deep_sleep_start();
}RTC_DATA_ATTR variables are stored in RTC slow memory, which remains powered during deep sleep. This is perfect for retaining state between wake-ups.
Key Takeaways
- Deep sleep consumes 10–150 µA vs 80+ mA active
- Wake-up sources: timer, external GPIO (RTC pins), touch, ULP
esp_deep_sleep_start()never returns — board restarts- Use
RTC_DATA_ATTRfor data that must survive sleep - Battery life depends heavily on duty cycle (awake vs sleep ratio)
Resources
- Espressif Deep Sleep Guide: https://www.espressif.com/en/support/tutorials/faq/how-to-enter-Deep-sleep-mode-with-esp32
- Video: ESP32 Deep Sleep Mode - https://www.youtube.com/watch?v=KxAx_2E3Ljw
- Espressif ESP32 Technical Reference: https://www.espressif.com/sites/default/documentation/esp32_technical_reference_manual_en.pdf