Let’s see how this works using an example from the library.
#QUEEN DEEPSLEEP CODE#
In the Arduino IDE, you just have to specify the sleep time in microseconds in the following function: esp_sleep_enable_timer_wakeup(time_in_us) Code Enable Timer Wake UpĮnabling the ESP32 to wake up after a predefined amount of time is very straightforward. The ESP32 RTC controller has a built-in timer you can use to wake up the ESP32 after a predefined amount of time. This feature is specially useful if you are running projects that require time stamping or daily tasks, while maintaining low power consumption. The ESP32 can go into deep sleep mode, and then wake up at predefined periods of time.
You can decide what peripherals to shut down or keep on during deep sleep.You can use one or combine more than one wake up source. This means configure what will wake up the ESP32. First, you need to configure the wake up sources.To write a sketch to put your ESP32 into deep sleep mode, and then wake it up, you need to keep in mind that: You can use the ULP co-processor to wake up – this won’t be covered in this guide.You can use two possibilities of external wake up: you can use either one external wake up, or several different external wake ups.You can use the timer, waking up your ESP32 using predefined periods of time.You might also like reading: ESP32 Pinout Reference: Which GPIO pins should you use? Wake Up SourcesĪfter putting the ESP32 into deep sleep mode, there are several ways to wake it up: The RTC_GPIO pins are highlighted with an orange rectangular box.
You can use that table as a reference, or take a look at the following pinout to locate the different RTC_GPIO pins. The ESP32 datasheet provides a table identifying the RTC_GPIO pins. RTC_GPIO Pinsĭuring deep sleep, some of the ESP32 pins can be used by the ULP co-processor, namely the RTC_GPIO pins, and the Touch Pins. This mode of operation is useful if you need to wake up the main CPU by an external event, timer, or both, while maintaining minimal power consumption. While the ESP32 is in deep sleep mode the RTC memory also remains powered on, so we can write a program for the ULP co-processor and store it in the RTC memory to access peripheral devices, internal timers, and internal sensors. In deep sleep mode neither CPU or Wi-Fi activities take place, but the Ultra Low Power (ULP) co-processor can still be powered on. Having your ESP32 in deep sleep mode means cutting with the activities that consume more power while operating, but leave just enough activity to wake up the processor when something interesting happens. Cut down on alcohol: While alcohol might seem like it helps you fall asleep, in reality, it reduces the quality and period of deep sleep that you get.If you put your ESP32 in deep sleep mode, it will reduce the power consumption and your batteries will last longer.
However, it’s important to avoid caffeine at least 7 hours before you go to bed to have a good night’s sleep. No coffee before bed: Coffee lovers might drink cups of coffee around the clock when left to their own devices.Listen to white or pink noise: If you struggle a little with going to sleep at night, listening to some white or pink noise can help with that.Instead of these, consume more foods that are low in fat and high in protein and fiber. One study shows that eating less fiber and more fats and sugars can cause your sleep to be more disrupted. Have a healthy diet: There are many reasons to have a healthy diet, and getting quality sleep is one of them.Taking a hot shower before bed, or hitting the sauna are great ways to get some heat in. Spend some time in the sauna: Some research shows that heat can help you get better deep sleep.Exercise: Research shows that regular exercise can increase and improve the quality of your deep sleep.