Battery voltage read

Hi i have two problems with my battery voltage indicator

int sensorValue = analogRead(A2);
float voltage = sensorValue * (5.00 / 1023.00);

1.Voltage value is incorrect how do i tweak it?

2.If battery voltage goes down voltage value increase how to fix it?

Sorry for my english :smiley:

2.If battery voltage goes down voltage value increase how to fix it?

Use the 1.1 V internal reference.

1.Voltage value is incorrect how do i tweak it?

What is the actual voltage and how much error are you getting?

2.If battery voltage goes down voltage value increase how to fix it?

Are you powering the Arduino from a battery? The "5V" reference is the Arduino's 5V power supply, so if it's not really 5V you'll get bad measurements. (So like AWOL says, if that's the case use the optional 1.1V reference.)

Use the 1.1 V internal reference.

And a voltage divider (2 resistors) to bring the voltage down to 1.1V or less. And, adjust your calculations to reflect the voltage divider and the 1.1V reference.

See this link for a possible solution.

...R

DVDdoug:
What is the actual voltage and how much error are you getting?

Displayed voltage is 3.19v and actual battery voltage is 3.93v

DVDdoug:
Are you powering the Arduino from a battery? The "5V" reference is the Arduino's 5V power supply, so if it's not really 5V you'll get bad measurements. (So like AWOL says, if that's the case use the optional 1.1V reference.)
And a voltage divider[/u]** (2 resistors) to bring the voltage down to 1.1V or less. And, adjust your calculations to reflect the voltage divider and the 1.1V reference.

I already have 2 10k resistors and yes im powering my arduino from battery

AWOL:
Use the 1.1 V internal reference.

I cant when i try to compile i get INTERNAL1V1' was not declared in this scope im using arduino nano v3

INTERNAL1V1 is for a Mega.

analogReference(INTERNAL); // is for a Nano

Scale the voltage divider so that max battery voltage has ~1volt on the divider tap.

The maths line also has to change to.
It should have the divider ratio and Aref in it.
1.1volt Aref is never exactly 1.1volt. It could be 1.0 to 1.2volt.
Leo..

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: