How to Calculate Battery Voltage

I'm trying to figure out how to convert my voltage divider to determine the voltage on the battery. I have an ESP32 board and 4AA NiMH (4.8V) batteries as an external power source.

I used this online calculator http://www.ohmslawcalculator.com/voltage-divider-calculator to determine how to setup my voltage divider. My understanding is that I want to convert the 4.8V to 3.3V via the divider.

The ESP32 has a 12bit ADC.

So, my voltage source is 4.8V, R1 = 10Kohm, R2 = 22Kohm, which should have an output voltage of 3.3V.

When I read the AnalogInput from the 4AA NiMH batteries, I'm getting a reading of 1766 or so (on average).

  1. Am I properly setting up my voltage divider?
  2. How do I convert the 1766 into 3.3V?

Thanks!!

I've never used the ESP32.

How do I convert the 1766 into 3.3V?

That doesn't seem right, but divide the ADC reading by 538 (1766/3.3).

The 12-bit ADC should max-out at 4095, and with a 3.3V reference you should read 4095 at 3.3V.

Your voltage divider calculations are right. But, it's usually a good idea to give yourself some "headroom" in case the battery happens to go over 4.8V.

So I adjusted the resistance to half the input. I now have two 4.7K resistors, and I set a max input voltage of 6. So now my reference voltage is now 3V.

With the updated resistors, I'm getting raw values of 2967 - 2979. I took my DMM, and I measured 5.19V coming straight from the source (the 4AA NiMH).

I'm a bit lost on how to take the 2967 and get 5.19V?

Maybe I'm overthinking this... I changed my calculation to this...

voltage = voltageRaw * (3.3 / 4095.0) * 2;

Since I'm halving the input voltage (two 4.7K resistors), then I now get an input voltage of 4.81. It's not quite 5.19 (which is what I get on my DMM). Am I missing a calculation?

Maybe your resistors are a bit off, maybe the 3.3volt supply isn't exactly 3.300volt.

Just use a single multiplication factor, and calibrate that if needed.

voltage = voltageRaw * 0.001739;

Leo..

1 Like

To calibrate your voltage divider, measure the battery voltage with a multimeter, and calculate a scale factor such that the Arduino output agrees with the multimeter reading.

1 Like

Thanks all! I see how you calculated the 0.001739 value.

5.19/2979 solving for the conversion.

Why those weird numbers?

That works out to 0.001742xxx

One multiplication should also be slightly faster.
Leo..