5

My loop code is this:

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(float(sensorValue*5000.0/1023));
delay(1);        // delay in between reads for stability

When I read 5V it gives 5000 mV. When I read 3.3V pin it gives 3211 mV. When I read 1442 mV battery it gives 1392. What do you think about this situation?

NOTE: There is no any additive circuit. Just wires.

  • 1
    How do you know your 1442mV battery is actually at 1442mV? Using a Voltmeter? Also, if you measure a 3.3V pin, it is usually off a bit, and I wouldn't be surprised to see 3211mV (or 3400mV) from a 3300mV regulator – Allan Nørgaard Mar 16 '15 at 14:21
  • Btw it is not necessary to use float(...) to print the number over the serial line, it will accept any data type :) – Allan Nørgaard Mar 16 '15 at 14:24
  • Both your measurement (e.g. using a voltmeter) and the ADC of the Arduino have a limited accuracy (cf. table 28.7 in the datasheet of the ATmega328). Therefore you should never expect them to agree to all given digits. – fuenfundachtzig Mar 16 '15 at 14:24
  • All comments are true but it gives 5V correctly, why? And my voltmeter is not corrupted. I also read a voltage refence IC's output, there is a 40-50 mV error still. – user30878 Mar 16 '15 at 14:32
5

Your question contains a number of errors and misconceptions.

Firstly the maximum output of a successive approximation ADC (here 0x3ff) corresponds to Vref - 1 LSB The voltage will thus be sensorValue*5000.0/1024. Note this error is less than the error of ±2LSB.

Measuring your 5V is futile, as this is the default analog reference, so the result must be 0x3ff.

Measuring the 3.3V pin will give a relative value to the 5V reference. Both are produced from commercial grade regulators with a accuracy of ±5%.

You are also confusing the precision of the reading (10 bit) with accuracy which is a best ±5% ±2LSB.

If you really want to measure voltage you should use the internal 1.1V bandgap reference. You would of course need to reduce the 5V and 3.3V to less than 1.1V. This introduces another potential error (even if you use 1% resistors), but would give more accurate results which are directly comparable.

  • Is there 1.1V ref. exists in UNO? – user30878 Mar 17 '15 at 9:21
  • Are you sure its not 1023 but 1024? – user30878 Mar 17 '15 at 9:22
  • 1
    And note 5V pin is not at 5V, its 5.15 V. I think the problem is this. – user30878 Mar 17 '15 at 9:23
  • @user30878 for 1.1V ref see arduino.cc/en/Reference/AnalogReference re 1024 see arduino.cc/en/Reference/AnalogRead (or read the Atmega data sheet) – Milliways Mar 17 '15 at 10:19
  • Yes, if the 5V pin is 5.15 then the reference voltage will be high. Thus you need to multiply by 5/5.15 = 0.97 to correct the results. This gives figures which roughly agree with what you got. (3.20 instead of 3.3, and 1398 instead of 1442). Plus what the others said about accuracy. – Nick Gammon Jul 11 '15 at 3:34
3

Both your measurement (e.g. using a voltmeter) and the ADC of the Arduino have a limited accuracy (cf. table 28.7 in the datasheet of the ATmega328). Therefore you should never expect them to agree to all given digits.

Concerning the points raised in your comment:

All comments are true but it gives 5V correctly, why?

analogRead returns a value between 0 and 1023. For all voltages above an (unknown) threshold close to 5 V, it will saturate and always return 1023, no matter what the actual input voltage is. This value is then converted to 5.000 V in your code. What you are probably seeing is just the maximum value your code can return, not an accurate measurement of a 5 V input voltage.

And my voltmeter is not corrupted.

It doesn't have to be corrupted. It will still be off. Have a look at the manual to find the nominal accuracy. (Also note that accuracy and precision are two different things and different from the number of digits of the display, assuming your voltmeter is digital.)

  • Thanks for clear my mind for maximum voltage. I already know it but I was confused a bit. – user30878 Mar 17 '15 at 9:18
  • I mean voltmeter is working correctly. – user30878 Mar 17 '15 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.