The Light Sleep mode is one of the low power consumption modes available on the ESP32, similar to a “suspend” mode of a computer.
In this mode, the ESP32 consumes less than 1mA (for example, 800mA on the ESP32 and 240uA on the ESP32-S3)
In this mode, the CPU, RAM, and digital peripherals are disconnected from the clock and their voltage is reduced. When disconnected from the clock, they stop functioning but remain powered and active.
When the ESP32 is in Light Sleep, it stops executing the program and enters a suspended state. To exit Light Sleep, the available WakeUp Sources are:
- Timer
- GPIO Wakeup
- UART Wakeup
- WIFI Wakeup
- Touchpad
- ULP Coprocessor Wakeup
- External Wakeup (Ext0 and Ext1)
Upon exiting Light Sleep, the program continues execution from the same point where it was. Any information or variable that was saved in memory is retained.
If you need more information about operating modes and WakeUp Sources, you can refer to
Using Light Sleep mode in the Arduino IDE
The functions necessary to use Light Sleep mode are defined in the “esp_sleep.h” file. This library contains the functions and macros needed to configure and control the Light Sleep mode of the ESP32.
With this, it is very easy to employ the Light Sleep mode of the ESP32 in the Arduino environment. First, we define a WakeUp Source with the functions we saw in What are sleep modes in the ESP32.
Next, entering Light Sleep mode is as simple as using the esp_light_sleep_start
function.
/**
* @brief Enter light sleep with the configured wakeup options
*/
esp_err_t esp_light_sleep_start(void);
Code Examples
Using Light Sleep mode
Let’s look at a complete example of how to use Light Sleep mode to make the ESP32 enter deep sleep for 10 seconds and then wake up:
void setup()
{
Serial.begin(115200);
delay(5000);
}
int counter = 0;
void loop() {
Serial.println(counter);
counter ++;
esp_sleep_enable_timer_wakeup(2 * 1000000); //light sleep for 2 seconds
esp_light_sleep_start();
}