How to use deep sleep on ESP32 to save battery
Deep sleep is the ESP32's “mostly off” mode. The CPU stops, most peripherals shut down, and only the RTC domain stays alive so the chip can wake later.
Important mindset shift
After deep sleep, your code starts from the top again. It's basically a reboot, not a pause/resume. If you need to keep data, store it (RTC memory, NVS, or external storage).
Minimal deep sleep (timer wake)
#include <esp_sleep.h>
// Wake every 60 seconds
static const uint64_t wakeSeconds = 60;
void setup() {
Serial.begin(115200);
delay(200);
// (Do your work here: read a sensor, send data, etc.)
Serial.println("Awake. Doing work...");
// Configure timer wake, then sleep
esp_sleep_enable_timer_wakeup(wakeSeconds * 1000000ULL);
Serial.println("Sleeping now.");
Serial.flush();
esp_deep_sleep_start();
}
void loop() {}How to actually get low current
Deep sleep current depends on your board as much as the ESP32 chip. Dev boards can burn extra power in USB chips, LEDs, and regulators.
- Turn off always-on LEDs if your board has them (or pick a board designed for battery use).
- Don't power sensors continuously unless you have to. Switch sensor power with a transistor or a dedicated load switch.
- Use a good regulator (low quiescent current). Some cheap regulators waste more than the sleeping ESP32.
Quick check
If your “deep sleep” current is still high, the usual culprit is the dev board hardware (USB chip, LED, regulator), not your code.
Deep sleep is a reboot-style sleep: do your work fast, configure a wake source, then call esp_deep_sleep_start(). For real battery life, choose low-power hardware and avoid always-on loads.
Related: Wake from deep sleep (timer/touch/GPIO) · ESP32 not waking up · Power ESP32 from batteries safely