ESP32 - Determining LiPo Battery Voltage

Hi guys,

I have just ordered these products with the intention of connecting the units together along with an ESP32.

Whilst Im comfortable with the physical connections and charging, I juist realised that I also want to be able to interrogate and determine the battery voltage.

Any ideas or suggestions as to how I would go about this?

Thanks

Jon

1 Like

A voltage divider and a PWM pin is often used.
I was looking for a schematic for you and found this thread which looks promising.

1 Like

Thanks for this.

Looks like this is the most important bit:

V(out) = V(in)*(R2/(R1+R2))

(R2 corresponding to the blue resistor in your schematic and R1 the red resistor)

In regards to the capacitor, it would reduce noise at the pin by adding a small (100nF) capacitor from the GPIO pin to ground. Below is a schematic of these suggestions, you may even consider higher resistor values.

Am I correct in thinking that 4.2V is my maximum (Vin) and 3.3V is my V(out)? If thats the case, Im thinking I need a 3.3k and 1.8k ohm resistors. Does that sound correct?

Also, in terms of where I physically connect the voltage divider to, do I parallel the connections where the battery connects to the charger and then connect the +ve side to the ESP GPIO?

Ultimately I am designing a function that needs to go into deep sleep, wake up every hour, obtain a battery voltgage and read a temperature value from a DS18b20, write these into a database and then go back to deep sleep for the next hour. The aim is to minimise charging requirements, so I dont want something that will constantly be sucking up juice!

Thanks

Jon

1 Like

Hey Jon,

Typically, most projects use the addition of an INA219 or equivalent board to do voltage reading. This can then be read via I2C to get an approximate voltage of the battery, easily allowing sensing in most circumstances for portable projects.

This is super handy when working with something like a Xiao ESP32, which has a charging IC built in, but does not have the ability to measure battery charge. I have recently started a project using this exact setup and it seems to be the best way of integrating this into a project.

For your use case, this may not be the best use case. You could maybe use a basic MOSFET to allow sensing and a reading on wake to minimise power draw. Just wire it in parallel so that the MOSFET controls the line to the voltage reader and switches it until it gets a reading, then turns off when going into deep sleep.

Cheers,

Blayden

2 Likes

This is cool. Feels like the right choice for this project.

2 Likes