Running an ESP32 on a battery is not as easy as you think. If you want to make battery powered ESP32 based sensor project, this article is for you. I will share some things I do to get the most out of my ESP32 battery and increase the time between charges. ESP32 SoCs are very powerful and are capable of doing some very cool stuff. For example they can stream camera output at up to 1284×1024 pixels (with frame rate of about 6 fps at this size, and faster at smaller sizes) which is amazing for this type of device. But in our case we will measure some values from a sensor and send it to the cloud and we do not want to use the full potential of the device, and it is important for us it lasts as long as possible on battery. Here are some tips I will share with you to decrease power consumption:
1. Choose esp32 board with built-in battery connector and charger
Choose esp32 board
Pick an ESP32 board that has a build-in battery connector and charger. Оften these boards come with an additional ICs that take care of power management. It saves us a lot of headache along with charging and optimizing the power supply circuit. I picked Olimex’s ESP32-DevKit-LiPo board. It’s a nice open source hardware board with reasonable price. Feel free to choose any esp32 board, everything in this article will work equally well.
The Esp32 needs an input voltage of around 3.3V, it will be nice to pick a battery that delivers a similar voltage. In my project I chose BATTERY-LIPO1400mAh
2. Turn off WiFi and Bluetooth before going to deep sleep
We want to keep it in deep sleep as long as possible. In our case we will use wakeup timer to wake it up from deep sleep. So instead of calling esp_deep_sleep_start() directly, we will do some preparations first.
- disconnect the WiFi
- turn off the WiFi and Bluetooth radio (with arduino api)
- turn off the ADC
- then turn off the WiFi and Bluetooth radios (with ESP API)
3. Reduce the clock speed
IoT projects, like this one, are simple and they don’t require a lot of computing power, but ESP32 comes with dual core processor, with clock speed from 80 MHz to 240 MHz.
|Clock Speed||Number of Cores||Power Consumption|
|240MHz||Dual-core||30mA ~ 68mA|
|160MHz||Dual-core||27mA ~ 44mA|
|Single-core||27mA ~ 34mA|
|80MHz||Dual-core||20mA ~ 31mA|
|Single-core||20mA ~ 25mA|
Power consumption of the ESP32 according to Espressif
Reducing the clock speed from 240MHz or 160MHz to 80MHz can drop the power consumption significantly. So we will reduce clock speed to 80MHz.
4. Reduce WiFi connections by using RTC memory
This step is relevant only if you don’t need real time data.
WiFi is pretty power-hungry, so the goal is to minimize the time spent with radio on. This is the step which will have most impact on battery life
Without RTC Memory
Let’s say we want to build temperature and humidity sensor that takes a new measurement every hour.
The calculations are very rough and optimistic, but:
Тhe battery will have to be replaced every 11 days, which I don’t want to do. For me, the time between battery charges should be at least 3 months.
With RTC Memory
The scenario with the use of RTC Memory will look like this:
- Wake up from deep sleep
- Get measure from sensor
- Store the measured data in RTC Memory
- If we have n reading, connect to WiFi and send all collected measures to the cloud.
- If not, go back to deep sleep
Let’s calculate in this scenario where we use RTC Memory. The calculations are very rough and optimistic, but:
In this case the battery will last for 4 months. This is much better.
5. Use static IP and avoid hostnames
- By hard codding an IP addres into your ESP32, we reduce the time it takes to get an address through DHCP.
- If possible avoid using names when connect to remote servers. Creating connection or request with some domain, it requires ESP32 to figure out the IP address behind the domain. This happens through a DNS resolver, and it takes between a few milliseconds and several hundred. If it’s possible use the IP address of the server/resource you want to access.
6. Use bigger battery
Тhe bigger the battery, the more time it lasts. In my case I will use two of these batteries Olimex’s ESP32-DevKit-LiPo board connected in parallel. Which gives me ~ 8 months on battery life.
Nice work, we managed to increase the time between charges from 22 days to 8 months. Thanks to deep sleep and RTC memory we can achieve very cool things. I am happy and satisfied with the result. If this result doesn’t satisfy you, then wifi is not for you. You’d better try LoRaWAN.