Dear friends welcome to the ESP32 Deep Sleep Tutorial! Today we are going to learn how to put the ESP32 chip into the Deep Sleep mode in order to conserve power and make our projects battery friendly. There is a lot to cover so let’s get started!

Intro to the ESP32 Deep Sleep Tutorial

Hello, guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics projects. In this channel, I share everything about the projects I build to help you develop similar projects or inspire you to start making things because it is easy, fun and creative. Subscribe to the channel now if you do not want to miss any future video.

The ESP32 chip is a fantastic new chip with great features. It offers a lot of processing power, two 32 bit cores, a lot of memory, Bluetooth and WiFi in a small and easy to use chip. One of the most interesting things about the ESP32 chip is that it offers a low-power deep sleep mode which is very easy to use. Let’s see how to use it.

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. 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. This small amount of memory is very useful as you are going to find out in a moment. Also note, even the RTC memory of the ESP32 chip is 4 times larger than the memory of the Arduino Uno.

The WiFi modules, the Processing Cores, and the Bluetooth module require a lot of current to operate. So, if we want to conserve power we have to disable them when don’t use them. This is what we are going to do now. We are going to put the ESP32 to Deep – Sleep mode where it disables everything except the RTC module. There is a light sleep mode and the Deep – Sleep mode. In Deep Sleep mode the ESP32 offers the lowest power consumption. It just needs 0.01 mAs of current in Deep Sleep mode and that’s why we are going to try today.

——————–
WHERE TO BUY
——————–

DOIT ESP32: https://educ8s.tv/part/ESP32

Firebeetle ESP32: https://educ8s.tv/part/FireBeetle

LEDs: https://educ8s.tv/part/LEDs

Resistors: https://educ8s.tv/part/Resistors

Small Breadboard: https://educ8s.tv/part/SmallBreadboard

Jumper Wires: https://educ8s.tv/part/JumperWires

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

In this mode as I said earlier, everything is disabled. The CPU cores, the WiFI module, the Bluetooth Module, the Peripherals and so on. Along with the CPU, the main memory of the chip is also disabled, so everything stored in the memory is lost forever. The only module that still works when in deep-sleep mode is the RTC module, the ultra-low-power co-processor, and its memory! So, if we save the data we want to survive the Deep-Sleep mode into the RTC memory they will be intact when we wake the chip back up.

There are three ways to wake up the chip. We can use a timer, a GPIO pin, or the co-processor. Today we are going learn how to use the timer to wake up the chip after a specific amount of time. Let’s see an example.

I have connected two LEDs to this ESP32 board. When the ESP32 boots up it lights up the yellow LED for three seconds, and then it goes into Deep-Sleep mode for 3 seconds. When it wakes up, it lights up the Green led for 3 seconds and goes back to sleep. 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.

Let’s take a quick look at the code of this project. As you can see the code is very simple. In order to put the ESP32 into Deep-Sleep mode, all we need is two lines of code. We enable the timer with the esp_sleep_enable_timer_wakeup function, we enter the time to sleep in seconds here, and then we call the esp_deep_sleep_start function. That’s it! There is a small difference with the execution of the code though. When we use the deep-sleep function, each time the ESP32 wakes up, it executes the setup function again. The loop function is never called. All the variable values are lost, except if we save them in the RTC memory using this prefix. In this example, I save the bootCount int variable into the RTC memory in order the program to know if it is the first time it runs and turn on the correct LED. As always you can find the code of this example in the description below.

——————–
CODE
——————–

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv