Monitoring Battery Voltage

A project log for Solar Powered WiFi Weather Station V3.0

ESP32 based Open Source Weather Station

Debasish DuttaDebasish Dutta 10/07/2021 at 14:370 Comments

The weather station is run by a 18650 Li-Ion battery, so it is essential to monitor the battery status. The max voltage input to the ESP32 board is around 3.2~3.3V but a fully charged 18650 battery voltage is 4.2V. So to measure this voltage we have to step down the voltage by using a voltage divider network.

The voltage divider is made up of 27k (R1) and 100k (R2).

When you have your ESP32 powered with batteries or solar-powered as in this case, it can be very useful to monitor the battery level. One way to do that is to read the output voltage of the battery using an analog pin of the ESP32.
However, the battery we’re using here outputs a maximum of 4.2V when fully charged, but the ESP32 GPIOs work at 3.3V. So, we need to add a voltage divider so that we’re able to read the voltage from the battery.

The voltage divider formula is as follows:

Vout = (Vbat*R2)/(R1+R2)

So, if we use R1=27k Ohm, and R2=100k Ohm,

We get: 1 Vout = (4.2*100k)/(27k + 100k) = 3.307V

So, when the battery is fully charged, the Vout outputs 3.307V that we can read with an ESP32 GPIO pin. To select the voltage divider resistance values, you can use this online calculator.