ESP32 Deep Sleep Tutorial for Low Power Projects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Dear friends welcome to another video! 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! 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. 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. Let’s now see the power consumption of the board. When the ESP32 is in active mode, it draws around 60mAs of current from the battery. When the ESP32 is in Deep Sleep mode it draws around 19mAs of current! This is a big reduction in current draw, but the creators of the chip claim that it needs 0.01mA of current in deep-sleep mode. What’s wrong with our setup? The culprit is the board. I am using a DOIT ESP32 board, the first ESP32 board that appeared on the market about a year ago. The design of the board is not optimized for power consumption so, even in deep-sleep mode, it needs a lot of current. Luckily there are better designed ESP32 boards out there. For example, the Firebeetle ESP32 board by DFrobot is better designed and can achieve a deep-sleep current of just 0.01mΑs when powered by a 3.3V power supply. If we power the board with the same battery pack we used before, which outputs around 4.8V, we can see that the current draw is 48mAs in active mode and just 0.05mAs Deep Sleep mode! Impressive isn’t it! We can further reduce the power consumption of the board if we use a 3.3V battery or power supply. I will try that in a future video. The 0.05mΑs of current that the board requires in Deep-Sleep mode is the lowest current draw I have ever seen in a fully featured ESP32 board, with USB to serial driver, regulator, and battery circuit. If you have discovered any board that can achieve similar or better results than the Firebeetle board, please let me know in the comments section below, I would love to try it. The power consumption of the Firebeetle ESP32 board in Deep-Sleep mode is extremely low. It needs around 1.44 mΑhs per day if powered by 4 AA rechargeable batteries. So, in theory, this power bank which has a capacity of 2.500mAhs can power the board for almost 5 years if we put it in Deep Sleep mode! Of course, we are going to wake up the board from time to time to perform a task which will require more power, so the battery life will be reduced greatly. For example, do you remember the E-Paper thermometer we built last week? It needed 60mAs current when not updating. Now, using the deep sleep functionality of the chip, I managed to reduce current draw to 0.43mAs of current. So, with this power bank, we now have an estimated battery life of around 3 months. Great, isn’t it? But I think there is a lot of room for improvements; there is a small current leak somewhere in my circuit. If we can reduce it, we can make this project run on batteries for over a year! I think this is amazing! We now have an extremely powerful board with very low power consumption. The best of all is that all we need to do to take advantage of this is to use just two lines of code! I will start using this feature a lot in my future projects. Unfortunately, the ESP32 software & hardware is not mature yet. There is a software or hardware bug that appears in both the ESP32 boards I tried when using the deep sleep mode. After a random number of wakes up, the ESP32 goes to sleep and it won’t wake up again. This bug can happen after a couple of wake ups, or after 100. It is just random. One simple solution I discovered is to add a small delay of 500ms after waking up and before reading from the RTC memory. This way the project worked fine, but of course the penalty we pay is reduced battery life, because the chip is in active mode for 500ms more in each wake up. I think this bug will be resolved in the near future with a new software or hardware fix. I would love to know your opinion about the Deep Sleep mode that the ESP32 offers. Are you going to use it in any of your projects? Please post your ideas in the comments section below; I love reading your thoughts! If this is your first time here, I would love to have you subscribed. In this channel, I post videos about DIY projects twice a month. I love making things, and I believe that anyone can make things, anyone can become a maker. That’s why I created this channel, to share my knowledge with the community and learn from the community. I hope you will join us. I will see you in the next video! [ Translating these subtitles? Add your name here! ]
Info
Channel: educ8s.tv
Views: 167,538
Rating: undefined out of 5
Keywords: ESP32, ESP32 Tutorial, ESP32 Deep Sleep, Low Power, Arduino, Arduino Tutorial, Firebeetle, ESP32 Board, ESP32 Power Consumption, ESP32 RTC, ESP32 Coprocessor, ESP32 Project, DIY, educ8s, educ8s.tv, WiFi, Arduino WiFi, Arduino Bluetooth, ESP32 BLE, ESP32 WiFi, ESP32 Light Sleep, ESP32 Timer, ESP32 Wake Up
Id: y1R2y8dCsIg
Channel Id: undefined
Length: 8min 14sec (494 seconds)
Published: Sat Feb 17 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.