# ESP32 and monitoring battery voltage

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
Hi

I will be powering the ESP32 using a Li-Poly battery.

I would also like to measure the voltage to give an estimate on the battery level, it does not need to be as accurate as a gauge.

I am thinking about adding a simple voltage divider circuit with 47K resistors.

Would this be sufficient?

#### ericgibbs

Joined Jan 29, 2010
18,655
hi DJ,
Over what voltage range do want to monitor the Li-Poly battery. ?
E

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
Hi

I need to monitor 4.2V down to 3V

#### ericgibbs

Joined Jan 29, 2010
18,655
hi DJ,
So that is 1.2V change, so using two 47k series would give 2.1V down to 1.5V change, which is only 0.6V.
That will be a very 'coarse' measurement of the battery voltage, is that OK for you.?

A 740 Bit change at 4096 for the ADC at 3.3v

E

#### sghioto

Joined Dec 31, 2017
5,369
If using the internal reference the voltage divider would need to reduce the voltage to or slightly below the reference when the battery is at 4.2 volts

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
hi DJ,
So that is 1.2V change, so using two 47k series would give 2.1V down to 1.5V change, which is only 0.6V.
That will be a very 'coarse' measurement of the battery voltage, is that OK for you.?

A 740 Bit change at 4096 for the ADC at 3.3v

E
Well a Li-Poly Battery is active from 4.2V to maybe about 3.5V. Anything after that could damage the battery

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
If using the internal reference the voltage divider would need to reduce the voltage to or slightly below the reference when the battery is at 4.2 volts
I agree I need to look at the datasheet again to confirm the reference voltage and then adjust resistors.

#### ericgibbs

Joined Jan 29, 2010
18,655
hi DJ,
Are you writing the Sketch for the ESP32.?
As @RayB points out, you can correct for the ADC non-linearity.
E

#### sghioto

Joined Dec 31, 2017
5,369
Well a Li-Poly Battery is active from 4.2V to maybe about 3.5V. Anything after that could damage the battery
Depending on who you believe some say you are good to 3 volts before recharging and 3.2 volts is considered drained.

#### MrSalts

Joined Apr 2, 2020
2,767
Since ADC only outputs a ratio of 0 to Vcc, a voltage divider between supply and ground will be read as 127 no matter how you slice it unless you have a voltage reference, zener, or other some non-linear device in your circuit to act as VRef.

#### ericgibbs

Joined Jan 29, 2010
18,655
hi Salts,
If I am reading your post correctly, that assumption of 127 is based on a 8Bit ADC, not the 12 Bit ADC of the ESP32.?

E

#### sghioto

Joined Dec 31, 2017
5,369
Since ADC only outputs a ratio of 0 to Vcc, a voltage divider between supply and ground will be read as 127 no matter how you slice it unless you have a voltage reference, zener, or other some non-linear device in your circuit to act as VRef.
The ESP has an internal reference of 1100 or 1200 mV depending on the model from what I have read

#### ericgibbs

Joined Jan 29, 2010
18,655
Hi,
As the ESP32 ADC is ratio metric when using the Vss as the Vref, it means the ADC will not show any change in battery level, so a fixed internal Vref must be used.

E

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
Hi,
As the ESP32 ADC is ratio metric when using the Vss as the Vref, it means the ADC will not show any change in battery level, so a fixed internal Vref must be used.

E
This makes, sense, as long as the battery when I am reading is always about 3.3V, then wouldn't the VCC be adequate?

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
Maybe i am wrong, but the Vref on ESP32 is 1.1 V. It then can be attenuated.

#### Ya’akov

Joined Jan 27, 2019
8,974
True,

Thanks, they are using a form of switch to conserve power. I am correct, without a switch, would the current consumption been still in uA?
If you are using 47KΩ resistors it should be about 35μA.

Thread Starter

#### DJ_AA

Joined Aug 6, 2021
267
Yes, maybe if was to increase it a little, it can reduce further. This way no need for a switch.

Similar threads