Go Down

Topic: Arduino voltmeter calculations (Read 2 times) previous topic - next topic

robtillaart

#10
Jun 02, 2011, 07:24 pm Last Edit: Jun 02, 2011, 07:29 pm by robtillaart Reason: 1
The precision of tha ADC of the Arduino is 10 bit, in practice the last bit may be inaccurate. That means you have approx 500 steps for 0..15 volt ==> at best 1/30 volt precission = 0,2% . Assume the resistors have an accuracy of 1% . suppose VREF has an accuracy of 2%.

Then - float carVoltage = analogRead(A0) * VREF / 1024.0 / R2 * (R1 + R2); - would give an max accumalate error of
                                                   0.2% +     2%  +    0%     + 1% + 1% + 1%  = 5.2%

=> 15V * 5.2% = 0.8 Volt max error => so one tenth of is indeed very good.

Disclaimer not official error math, just an first order approximation.

One can improve the measurement by doing the AnalogRead multiple times:
Code: [Select]

float readVoltage()
{
 #define SAMPLES 3.0
 float rv = 0;
 for (int i=0; i< SAMPLES ; i++) rv += analogRead(A0);
 rv /= SAMPLES;
 return rv * 0.01576;   // average of 3 reads times the calculated constant.
}


If time is not an issue one can take more samples ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up