
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 3 /* Time ESP32 will go to sleep (in seconds) */ We enable the timer with the esp_sleep_enable_timer_wakeup function, we enter the time to sleep in seconds, and then we call the esp_deep_sleep_start function. In order to put the ESP32 into Deep-Sleep mode, all we need is two lines of code.Įsp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR) esp_deep_sleep_start()
ESP32 FROM TIME IMPORT DEEPSLEEP CODE
Let’s take a quick look at the code of this project. From now on it will only blink the green LED, so the chip remembers that it is not the first time it boots up because we are using the RTC memory to store an integer value. When it wakes up, it lights up the Green led for 3 seconds and goes back to sleep. When the ESP32 boots up it light up the yellow LED for three seconds, and then it goes into Deep-Sleep mode for 3 seconds. I have connected two LEDs to this ESP32 board. It just needs 0.01 mAs of current in Deep Sleep mode and that’s why we are going to try today. In Deep Sleep mode the ESP32 offers the lowest power consumption. There is a light sleep mode and the Deep – Sleep mode. We are going to put the ESP32 to Deep – Sleep mode where it disables everything except the RTC module. So, if we want to conserve power we have to disable them when don’t use them. The WiFi modules, the Processing Cores, and the Bluetooth module require a lot of current to operate. Also note, even the RTC memory of the ESP32 chip is 4 times larger than the memory of the Arduino Uno.

This small amount of memory is very useful as you are going to find out in a moment.

Inside the RTC module, we can find a PMU (Phasor measurement unit) a small and very low power 32-bit co-processor, and 8Kbs of RAM memory. Inside the ESP32 chip, we can find the two processing cores, the RAM and ROM memory, the WiFi module, the Bluetooth Module, a hardware acceleration module for cryptographic applications, the RTC module, and a lot of peripherals.
