Using Light Sleep Mode with ESP32 for Power-Efficient IoT Projects

What is Light Sleep Mode on ESP32?

Light Sleep mode on the ESP32 allows the microcontroller to enter a low-power state while retaining the ability to quickly wake up and resume operations. In this mode, the CPU, most peripherals, and Wi-Fi are powered down, but the RTC (Real-Time Clock) and ULP (Ultra Low Power) coprocessor continue to function. This is ideal for battery-powered IoT applications where minimizing power consumption is crucial.

How Light Sleep Mode Works

When the ESP32 enters Light Sleep mode, the main CPU is paused, but other components like the Wi-Fi, Bluetooth, and GPIO pins can be used to wake up the device. The system can be triggered to wake up by external events such as button presses, timers, or sensors. The ESP32 can also periodically wake up to collect data, transmit it, and then return to sleep, making it very power-efficient for long-term use.

  • Connect the ESP32 to your development environment and install the necessary libraries in Arduino IDE.
  • Configure GPIO pins that will be used for triggering wake-up events.
  • Use the `esp_light_sleep_start()` function to put the ESP32 into Light Sleep mode.
  • Implement a wake-up source like a button or a timer to trigger the wake-up event.
  • Monitor power consumption during Light Sleep mode using a multimeter or a dedicated power meter.
  • Test the system’s power consumption and adjust wake-up intervals to optimize battery life.

Formula: Power Consumption in Light Sleep Mode = [Base Power Consumption] + [Power Consumption of Active Components]

Components Required

  • 1 × ESP32 Development Board
  • 1 × Push Button (for wake-up event)
  • 1 × Breadboard and Jumper Wires
  • 1 × Power Meter (optional for measuring current)
  • 1 × 3.7V Li-ion Battery (for portable power supply)
  • 1 × Voltage Regulator (if needed for battery connection)

Pin Configuration

  • GPIO 0 (Button Pin): Used to trigger the wake-up event from Light Sleep mode.
  • GPIO 13 (LED Pin): LED used to indicate when the ESP32 is awake.

Ensure the GPIO pin used for triggering wake-up is configured as an input with a pull-up or pull-down resistor to prevent false triggers.

Wiring and Connections

  • Button VCC -> 3.3V
  • Button GND -> GND
  • Button OUT -> GPIO 0
  • LED VCC -> 3.3V
  • LED GND -> GND
  • LED OUT -> GPIO 13

Code for ESP32 Light Sleep Mode

1#include <esp_sleep.h>
2
3#define BUTTON_PIN 0
4#define LED_PIN 13
5
6void setup() {
7  pinMode(BUTTON_PIN, INPUT_PULLUP);
8  pinMode(LED_PIN, OUTPUT);
9  Serial.begin(115200);
10  Serial.println("ESP32 Light Sleep Example");
11}
12
13void loop() {
14  Serial.println("Entering Light Sleep");
15  digitalWrite(LED_PIN, HIGH);
16  esp_sleep_enable_ext0_wakeup(BUTTON_PIN, LOW); // Wake up on button press
17  esp_light_sleep_start(); // Put ESP32 into Light Sleep
18  digitalWrite(LED_PIN, LOW);
19  Serial.println("Woke Up from Light Sleep");
20  delay(1000); // Add delay before going back to sleep
21}

Code Explanation

  • #include <esp_sleep.h>: Includes the ESP32 sleep library for managing sleep modes.
  • esp_sleep_enable_ext0_wakeup(BUTTON_PIN, LOW);: Sets up an external wake-up source (button press) to trigger the wake-up from Light Sleep.
  • esp_light_sleep_start();: Puts the ESP32 into Light Sleep mode, where most peripherals are powered down but the RTC and ULP remain active.
  • digitalWrite(LED_PIN, HIGH);: Turns on an LED to indicate that the ESP32 is awake.
  • delay(1000);: Adds a delay before the ESP32 goes back to sleep, allowing time for observing the wake-up behavior.

Applications

  • Battery-powered IoT devices
  • Low-power sensor networks
  • Smart home devices with extended battery life
  • Wearable health monitoring systems
  • Environmental monitoring systems
  • Remote data logging and transmission

Conclusion

Using Light Sleep mode on the ESP32 is an effective way to conserve power in battery-powered IoT applications. By intelligently managing sleep and wake cycles, the ESP32 can significantly extend the operational lifetime of devices, making it ideal for long-term deployments where access to power is limited or unavailable.