ESP32 BASICS · LESSON 14
Deep Sleep & Low-Power Modes
Cutting power draw for battery projects using deep sleep, timers, and wake-on-pin.
Battery-powered ESP32 projects live or die on how well they use deep sleep — a mode where almost everything on the chip is powered down and current draw drops by several orders of magnitude.
deep_sleep.ino
#define SLEEP_SECONDS 60
void setup() {
Serial.begin(115200);
Serial.println("Taking a reading, then sleeping...");
// ... read a sensor, send data ...
esp_sleep_enable_timer_wakeup(SLEEP_SECONDS * 1000000ULL);
esp_deep_sleep_start();
}
void loop() {
// never reached — deep sleep restarts the chip on wake
}
What survives sleep
Deep sleep resets most of the chip, including regular variables — setup() runs again from the top on wake, as if the board had just been powered on. Values that need to persist across a sleep cycle must be stored in RTC memory or flash instead of an ordinary variable.
Waking up
A wake can be scheduled with a timer, as above, or triggered by a change on certain GPIO pins — useful for a project that should sleep until a button is pressed or a sensor trips.
KEY IDEA
Deep sleep is a restart, not a pause — design your code around "run once, then sleep," not "resume where I left off."