### Author Topic: battery calculation again  (Read 2483 times)

#### d00m178

• Jr. Member
•  • Posts: 78 ##### battery calculation again
« on: November 04, 2015, 05:30:50 PM »
hello

https://lowpowerlab.com/forum/index.php/topic,1206.0.html
more that 100 times but I don't understand why my in my case it doesn't work as expected.

I have 4 AA batteries power source == 6.24 V
but it sees only 0.46v
analog reads from A2 - 143-144

and 143*0.00322 == 0.46

why it is happens - I don't know..

UPD:
Also I don't understand this

from sender code -https://github.com/LowPowerLab/MailboxNotifier/blob/master/MailboxNotifier4_sender_withWeatherShield.ino

why 1.47 ? if power source == 9V (http://lowpowerlab.com/blog/2013/08/27/mailbox-notifier-project-upgrade/)
and "The 10M+470K gives a ratio of 31.97%. "
this dividerRatio with should be 3.125

9v - 100%
x - 32%

x == 9*32/100 == 2.88v on analog pin
and " inverse of the ratio of the divider (1/0.32)" == 3.125

so why 1.47 ?
and why "to calculate the actual voltage of the battery I need to know what the battery rated voltage is (ie starting point)" ??

very very strange.

« Last Edit: November 04, 2015, 05:37:00 PM by d00m178 »

#### d00m178

• Jr. Member
•  • Posts: 78 ##### Re: battery calculation again
« Reply #1 on: November 05, 2015, 05:08:06 AM »
Anything?

#### Felix

• Hero Member
•     • • Posts: 6617
• Country:  ##### Re: battery calculation again
« Reply #2 on: November 05, 2015, 09:30:03 AM »
I guess I would have to repeat myself.
It's a very simple circuit. It just divides voltage just like water from a bottle into 2 smaller cups. If you understand what that divider does then it's pretty easy to figure out that formula. Or you can create your own formula, or change the resistors to change the divider ratio and maximise resolution.
Note that depending on what the voltage of your MCU is, a divider ratio may max out your analog port reading if the divided voltage exceeds the voltage of your MCU (or analog REF voltage).

#### d00m178

• Jr. Member
•  • Posts: 78 ##### Re: battery calculation again
« Reply #3 on: November 05, 2015, 11:51:25 AM »

Yes, it is very simply - circuit and formula but.. it doesn't work in my case - there are some differences between voltage which I measure via MCU and voltage that I can measure by voltmeter.

I have Anarduino+RF96 - pretty the same as Moteino.
it has also Vcc == 3.3v
I power it from 4AA battery. Voltmeter shows me 6.11v on Vin pin. On Vcc pin - 3.3v
So I suppose voltmeter works ok.

then I build divider.
now with 1M+470K(1uF)
all online calculators and my calculations says me that after divider I should have 1.95v
then I need to know dividerRatio.

6.11 - 100%
1.95 - x%
x == 1.95*100 / 6.11 == 3.14

so dividerRatio == 3.14

my code:
Code: [Select]
``    for (byte i=0; i<10; i++){      reading += analogRead(BATT_MONITOR);        }    DEBUG("reading:"); DEBUGln(reading/10);    divVolts = (reading / 10.0)* 0.00322;    DEBUG("divVolts:"); DEBUGln(divVolts);    batteryVolts = (reading / 10.0)* 0.00322 * 3.14;    DEBUG("batteryVolts:"); DEBUGln(batteryVolts);``

it shows:

divVolts: 1.93

batteryVolts: 6.06

Now I have difference in voltage about 0.5v

Seems I need tune some parameters in formula ? or it is allowable error for MCU ?

Also would  you please explain second part of my previous question - why dividerRatio == 1.47 and why "to calculate the actual voltage of the battery I need to know what the battery rated voltage is (ie starting point)" ??

• NewMember
• • Posts: 11 ##### Re: battery calculation again
« Reply #4 on: November 05, 2015, 12:11:19 PM »
if the scheme is like that :

VIN -> 1M -> A2 -> 470K -> GND

then when reading A2 you'll get 470K / (470K + 1000K) = 31,97 % of VIN and you have to multiply by 1/0.3197 = 3.13 to get you real battery voltage

So in you case :

599 * (3.3 / 1023) * 3.13 = 6.04V

•  