ESP32 Deep Sleep modes with Arduino IDE
ESP32 comes with a dual-core processor. The dual-core processing provides efficiency in terms of performance as well as power consumption. In this post, we’ll explore how to access both cores on the ESP32 and compare the performance between single-core and dual-core operations.
Table of Content
ESP32 Power Modes
ESP32 has Five Power Modes:
- Active Mode
- Mode-Sleep Mode
- Light-Sleep Mode
- Deep-Sleep Mode
- Hibernation Mode
Power Mode | CPU | Wi-Fi/Bluetooth | RTC Memory & Peripherals | ULP | Power Consumption |
---|---|---|---|---|---|
Active Mode | ON | ON | ON | ON | Refer [RF Modes] |
Modem-Sleep Mode | ON | OFF | ON | ON | 20 mA to 68 mA |
Light-Sleep Mode | PAUSE | OFF | ON | ON | 0.8 mA |
Deep-Sleep Mode | OFF | OFF | ON | ON | 10 uA to 150 uA |
Hibernation Mode | OFF | OFF | RTC Memory – OFF RTC Timer – ON (Slow clock 8 MHz) RTC GPIOs – ON | OFF | 5 uA |
Power Off | OFF | OFF | OFF | OFF | 1 uA |
Please find power consumption for various RF modes in ESP32:
RF Mode | Min | Typ | Max | Unit |
---|---|---|---|---|
Transmit 802.11b, DSSS 1 Mbps, POUT = +19.5 dBm | – | 240 | – | mA |
Transmit 802.11g, OFDM 54 Mbps, POUT = +16 dBm | – | 190 | – | mA |
Transmit 802.11n, OFDM MCS7, POUT = +14 dBm | – | 180 | – | mA |
Receive 802.11b/g/n | – | 95 to 100 | – | mA |
Transmit BT/BLE, POUT = 0 dBm | – | 130 | – | mA |
Receive BT/BLE | – | 95 to 100 | – | mA |
Why Sleep Modes?
Imagine you have an ESP32 Smartwatch. Let’s assume we have a battery of 500 mAH and other sensors, display, and modules consume negligible power. Let’s compare the battery backup of the watch in active vs sleep mode. Let’s assume our device is 90% of the time is in Deep-Sleep Mode and 10 % of the time in Active Mode.
battery backup = battery capacity (mAH) / current consumption
battery backup(Active Mode) = 500 (mAH) / 240 mA = 2.1 Hours
battery backup(Deep-Sleep) = 500 (mAH) / {(150*0.9 uA)+(240*0.1 mA)} = 21 Hours
From the battery life calculation, you can clearly see that the watch will have 10x more battery backup. You can still increase the battery backup by putting the ESP32 into Hibernation mode and increasing the sleep duration.
Putting ESP32 in different Power Modes?
The function esp_deep_sleep_start(void) puts ESP32 in Deep-Sleep Mode. However, you need to define the wakeup source before putting ESP32 into sleep mode.
esp_deep_sleep_start(void);
Wakeup Sources
Timer Wake-up
ESP32 can wake up at predetermined times. It is useful in applications where devices don’t need to remain active all the time.
- Applications:
- Alarm clocks in mobile,
- Smart Watch,
- Weather Station data logger
esp_sleep_enable_timer_wakeup(time_in_us);
Touch Wake-up
ESP32 will wake up when touch is detected on the capacitive touch-sensing GPIO pins.
- Applications:
- Fingerprint Scanner,
- Touch wake-up on the Smartphone screen
touchSleepWakeUpEnable(pin, threshold);
External (GPIO) Wake-up
ESP32 will wake up when the signal is detected on pins.
- Applications
- Wildlife tracking Camera (captures photo when movement is detected),
- The power button in the Smartphone
esp_sleep_enable_ext0_wakeup(pin, level);
AND
esp_sleep_enable_ext1_wakeup(pin, level);
Examples
#define TIME_TO_SLEEP 5
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println(esp_sleep_get_wakeup_cause());
Serial.println("ESP32 is going to sleep for ...");
// Enable timer wakeup
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * 1000000); // Convert to microseconds
// Start deep sleep
Serial.println("ESP32 sleeping now");
Serial.flush();
esp_deep_sleep_start();
Serial.println("ESP32 sleeping now")
}
void loop() {
Serial.println("Inside loop() function")
}
CEW
WVE