Table of Contents
#include <esp_sleep.h>
#define TIME_TO_SLEEP 10 // Sleep time in seconds
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("ESP32 going to deep sleep...");
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * 1000000); // Convert seconds to microseconds
esp_deep_sleep_start();
}
void loop() {
// This won't run after deep sleep, as ESP32 restarts upon wake-up
}
- The ESP32 executes the setup() function.
- It prints a message, configures the wake-up timer, and enters deep sleep.
- After the timer expires, the ESP32 wakes up and restarts from setup().
Since RTC memory is not used, the ESP32 enters Hibernation Mode, consuming only ~5µA.