If the battery is 12V lead acid, a voltage divider will work fine. Use a 3:1 divider to reduce the battery voltage to the 0-5V range for a 5V Arduino. Add a capacitor (say 100 nF to 10 uF) across the voltage divider output to reduce external electrical noise.
If you use the Arduino with its on board 5V regulator as the voltage reference, that should be stable and will give you a resolution of 0.005V. Average several readings for best stability.
You will have to calibrate the final result, using an accurate DVM.
~US$2.00 including worldwide shipping is too expensive?
This sketch might be the best a bare Arduino can do.
Leo..
/*
0 - ~17volt voltmeter
works with 3.3volt and 5volt Arduinos
uses the stable internal 1.1volt reference
10k resistor from A0 to ground, and 150k resistor from A0 to +batt
(1k8:27k or 2k2:33k are also valid 1:15 ratios)
100n capacitor from A0 to ground for stable readings
*/
unsigned int total; // holds readings
float voltage; // converted to volt
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
Serial.begin(9600); // ---set serial monitor to this value---
}
void loop() {
total = 0; // reset
analogRead(A0); // one unused reading to clear any ghost charge
for (int x = 0; x < 64; x++) { // 64 analogue readings for averaging
total = total + analogRead(A0); // add each value
}
voltage = total * 0.0002567; // convert readings to volt | ---calibrate by changing the last three digits---
Serial.print("The battery is ");
Serial.print(voltage); // change to (voltage, 3) for three decimal places
Serial.println(" volt");
delay(1000); // readout delay
}
I'm trying to measure the voltage of a large battery (optima 55ah) that powers a small 240v invertor (to charge my motorbike battery).
Which battery are you trying to measure? Is this while the invertor is operating? I'm guessing you have a charger connected to the invertor?
Could you draw the WHOLE system you are trying to use?? What tolerance resistors are you using? If you want as accurate as can be, you need to be very specific in what you have
Tolerance of the resistors is irrelevant, since you have to calibrate anyway.
Long term stability and temp coeficient is.
Common 1/4watt metalfilm resistors might be ok for this.
Not sure what the temp drift of Arduino's 1.1volt Aref is either.
Leo..
Wawa:
~US$2.00 including worldwide shipping is too expensive?
The price I saw was $10 without shipping. Maybe there is other hardware that can measure voltage.
tinman13kup:
Which battery are you trying to measure? Is this while the invertor is operating? I'm guessing you have a charger connected to the invertor?
No, that's not going to work well as the impedance is an order of magnitude too high. You need a 100nF
capacitor in parallel with the 100k resistor to fix this. (a low leakage type) Are you using star-grounding?
Arduino Uno
There is less than 1v difference between a full battery and an empty one. That's why I want it to be accuracy on 0.01V.
I can understand wanting that precision, but 0.05V accuracy is plenty for a lead-acid 12V battery.