G2Labs Grzegorz Grzęda
Low Power Deep Sleep Modes in ESP32: Exploring Power Saving Techniques
June 18, 2024
Low Power Deep Sleep Modes in ESP32: Exploring Power Saving Techniques
The ESP32 is a powerful microcontroller that offers not only Wi-Fi and Bluetooth connectivity but also a range of low power modes. These low power modes can help conserve battery life in applications where power consumption is a critical factor. In this blog post, we will explore the different deep sleep modes available in the ESP32 and how they can be utilized to achieve power saving in your projects.
Understanding Power Consumption
Before diving into deep sleep modes, it’s crucial to understand power consumption and its implications. Power consumption is typically measured in milliwatts (mW) or microwatts (µW). The ESP32, like any other microcontroller, consumes power during its active state. However, even when it is in sleep mode, it still requires power to maintain its functionality and be ready to wake up.
The deep sleep modes in ESP32 allow developers to put the microcontroller in a low power state while preserving its state and the necessary peripherals. By doing so, power consumption can be significantly reduced, resulting in longer battery life or reduced energy bills.
Exploring Deep Sleep Modes
The ESP32 offers different deep sleep modes to cater to various power saving requirements:
Light Sleep (Light Sleep Mode 0)
Light Sleep (Light Sleep Mode 0) is the shallowest sleep mode available on the ESP32. In this mode, the CPU is turned off, but the RTC (Real-Time Clock) and ULP (Ultra-Low Power) coprocessor remain functional, allowing the ESP32 to wake up on certain triggers, such as timed wake-ups or external interrupts.
To utilize Light Sleep mode, you can use the esp_sleep_enable_timer_wakeup()
function to set up timed wake-ups or esp_sleep_enable_ext0_wakeup()
to enable wake-up by external interrupts.
Here’s an example that puts the ESP32 in Light Sleep mode for 10 seconds:
Deep Sleep (Light Sleep Mode 1)
Deep Sleep mode (Light Sleep Mode 1) takes the power saving a step further by turning off the RTC, reducing power consumption even more. To wake up from Deep Sleep mode, the ESP32 must rely solely on external triggers, such as a button press or an interrupt generated by an external device.
Hibernation (Deep Sleep Mode)
Hibernation (Deep Sleep Mode) is another power-saving mode available on the ESP32. It provides the lowest power consumption but requires resetting the system to wake it up. In Hibernation mode, most of the system, including the RTC and ULP coprocessor, is powered off. This mode is useful when external factors determine when the ESP32 should wake up, such as a scheduled time or a remote signal.
To enter Hibernation mode, you need to set the desired wake-up behavior using esp_sleep_enable_ulp_wakeup()
or esp_sleep_enable_time_wakeup()
, followed by calling esp_deep_sleep_start()
.
Examples and Use Cases
Now that we have a basic understanding of the different deep sleep modes let’s look at a couple of practical examples:
Example 1: IoT Sensor Application
Imagine an IoT application where an ESP32 gathers sensor data every minute and sends it to a remote server. In this scenario, it would be wasteful to keep the ESP32 in an active state during the time between sensor readings.
By utilizing Light Sleep mode, the ESP32 can save a significant amount of power, increase the overall lifespan of the device, and reduce costs associated with battery replacements. The ESP32 can be programmed to wake up every minute, read sensor data, connect to the server, send data, and go back to sleep.
Example 2: Wireless Sensor Network
In a wireless sensor network, multiple ESP32 nodes can be employed to monitor different environmental parameters. These nodes can be deployed in a remote area with limited power sources, making energy optimization crucial.
By utilizing Deep Sleep mode, the ESP32 nodes can operate for an extended period while consuming minimal power. Each node can wake up at predefined intervals or when a particular condition is met and send the collected sensor data to a central hub using a mesh network. This approach allows for efficient and reliable data collection from multiple remote locations.
Conclusion
In this blog post, we explored the low power deep sleep modes available in the ESP32 microcontroller. Understanding power consumption and utilizing these modes can significantly increase the battery life or reduce energy consumption in IoT projects.
By selectively choosing the appropriate sleep mode based on your project’s requirements, you can strike a balance between functionality and power consumption. Whether it’s a simple IoT device or a network of wireless sensors, the ESP32’s power-saving capabilities provide a solution to achieve long-lasting and efficient operation.