# Battery Monitor

i would like to build a battery monitoring system for 12 12v batteries. i was thinking a could use a system like this:
along with an analog multiplexer and an lcd for voltage reading output

All you need for a 12 volt battery monitor is two resitors setting up a voltage divider.

I used a 47k and 100k and used the adc ( 0 to 15v )

when i do an analogRead, the output changes very quickly as if nothing was connected to it but 4v is being outputted according to my multimeter
any help???

i dont need an rc timer of any kind?

No , I just did a analog test every 100ms or so by adding delay().

My values was constant with a fixed voltage.

i got it working now thanks
i didnt have the ground connected of course

can anyone help me with displaying the voltage to the hundredths place in the serial monitor?
so far i have this but it outputs 12.60 volts when the true voltage is 12.85

827-829 on the analogRead = 12.85v

``````int vPin = 5;
int val = 0;

void setup(){
Serial.begin(9600);
pinMode(vPin, INPUT);
}

void loop(){
Serial.print(val / (645/10), DEC);
Serial.print(".");
Serial.println(val % (645/10) ,DEC);
delay(1000);
}
``````

any help?

Between the (normal) noise in the least significant bit of the ADC, variations in actual values of the resistors, tolerances in the resistors, etc, it may not be reasonable to expect .01V accuracy…

Use a meter to check the actual values of the resistors in your divider and see if some modification to your formula is in order.

-j

i realize that it wont be accurate to .01 volts but is it possible to preserve a decimal when sending over serial?

it said this was true for the float variable, is it true for all decimals?
Serial.println() truncates floats (throws away the fractions) into integers when sending serial. Multiply by power of ten to preserve resolution.

Dont forget that ver13 of the idea has the support for printing to 2 decimal places.
Liquidcrystal and serial print both support it.
With some changes to print.h and print.cpp you can specify the precision.
I believe ver14 will have variable precision available as well.

Gordon

can you explain how to edit the print settings?

You need to modify the print function in print.h and print.cpp in /hardware/cores/arduino/ to accept an extra parameter for the precision and pass it to printFloat.
As a hack I just modified these functions.
It means that wherever you have serial.print you also have to pass the precision.
When I get round to it ill do it properly. But I believe something like this will be added to ver14 of the ide.

in print.cpp

``````void Print::print(double n)
{
printFloat(n, 2);
}
``````

To:

``````void Print::print(double n,uint8_t digits)
{
printFloat(n, digits);
}
``````

and print.h

``````void print(double);
``````

To:

``````void print(double,uint8_t);
``````

Gordon