This article should be used in conjunction with the video below;
In this article you will discover how to get your ESP32 to monitor and report on it’s own battery level. Handy for battery powered projects. All your require are two resistors (anything from 1K upwards, I generally use 10K). The voltage in pin on the ESP32 has sometimes different labels. On DOIT boards it’s labelled as VIN and on DEV Kit C boards it’s “V5” or “5V” depending upon the source of your board. It is recommended that you do not go above 5V unless your board has some issues being powered from 5V. I have read that some (not sure if it’s all boards) will not be happy with voltages above 5V. As 3AA (or 3AAA) amount to just under 5V when fresh this seems a good source to use. If you want to power yours from say 3.7V lithium batteries then you won’t be using a normal dev board and this article will not be for you.
The connections
Beloe is the circuit diagram, note that I’ve labelled the supply input to the ESP32 as Vcc.
Note that using pin 13 is arbitrary, any input pin capable of being used as an ADC is suitable (which is basically all on the ESP32). That’s it for the total hardware required. The two resistors act as a potential divider (in this case dividing the input voltage by 2) so that the maximum voltage pin 13 will measure is around 2.5V. This is because we don’t want to measure greater that 3.3V on the ESP32 and indeed it’s not that reliable at the top end voltage as well.
All your software needs to do now is to monitor the value in the ADC pin that represents the lowest voltage your system will tolerate (around 3.9 to 4V generally). You will see this done in the video.
The Software
The demo software presented in the video is very short and give you a basis for your own projects. It is not available for download due to its simplicity.