AnalogRead returns wrong value

Sorry if this topics doesn't go here. I have Arduino UNO reading the ouput voltage of a DC step-down converter fixed at around 2.7V.

The measure is done through a voltage divider made with 1M and 100K resistor (obviously with the 1M one pointing to the voltage to measure and the other is between ground and A0).

I have taken into account the 100M impedance of Arduino, and when I read the voltage I get 2.48V when it should be 2.69V measured with voltmeter.

I have tried to set the reference to default and also reviewed the formula to convert 0-1023 to voltage several times, what am I doing wrong?

This is the formula I'm using: Voltage = 11.01 * 4.7mV * analogRead(0);
The 11.01 is the voltage divider.

PS: everything is common grounded.

Hi,
Forget about the arduino input impedance: just deem it as infinite ...
Calculate the resistors divider so as the -output- impedance is less than 10 kOhm.
Regards

With anything less than 5V you don't need a voltage divider. You're just throwing-away resolution.

Accuracy depends on the reference. I assume you're using the default Vcc reference, so what's your Vcc actually measure? (And how well-regulated is it?)

With a voltage divider, resistor tolerance comes-into play.

I have taken into account the 100M impedance of Arduino,

You can't do that... The "100M" isn't necessarily a resistance-to-ground.

This is the formula I'm using: Voltage = 11.01 * 4.7mV * analogRead(0);

Where did '4.7' come from? 5/1023 = 4.89. See [Read Analog Voltage](http://This is the formula I'm using: Voltage = 11.01 * 4.7mV * analogRead(0);).

P.S.
Virtually all "real" voltmeters are calibrated (corrected). A typical-simple calibration is "straight-line calibration". An offset value is added/subtracted to correct the zero reading and a slope value is multiplied to correct the higher-value readings. Usually the slope is corrected at (or near) the maximum reading. The Arduino shouldn't need any zero correction, and the slope probably only needs correction to compensate for reference errors/differences.

neukyhm:
Sorry if this topics doesn't go here. I have Arduino UNO reading the output voltage of a DC step-down converter fixed at around 2.7V.

The measure is done through a voltage divider made with 1M and 100K resistor (obviously with the 1M one pointing to the voltage to measure and the other is between ground and A0).

I have taken into account the 100M impedance of Arduino, and when I read the voltage I get 2.48V when it should be 2.69V measured with voltmeter.

I have tried to set the reference to default and also reviewed the formula to convert 0-1023 to voltage several times, what am I doing wrong?

This is the formula I'm using: Voltage = 11.01 * 4.7mV * analogRead(0);
The 11.01 is the voltage divider.

PS: everything is common grounded.

I think you're better off just drawing a circuit diagram, because your description of the circuit doesn't seem to tie in with the values that you wrote ---- such as .... where do the values of 2.48V and 2.69 V come from?

You mentioned a voltage divider ---- with 1 M connected to 2.7V on one end, and the 'other' resistor connected between 'A0' and GND. So this suggests that A0 is connected to the mid-point of this voltage divider.

So A0 should be reading an equivalent voltage of around 0.245 volt, right? Or.... around level 50 (in the range from level 0 to level 1023) with a 5V reference.

You mention that the UNO is reading the output voltage of the step converter. So this suggests that A0 is connected to the 2.7V output of the step converter? But, on the other hand, you're also suggesting later that A0 is at a different location ----- at the mid-point of the divider.

So.....the question is .... which is it? Which location is A0? At the moment ---- your description suggests A0 is connected to two different spots at the SAME time. That is "I have Arduino UNO reading the output voltage of a DC step-down converter fixed at around 2.7V." versus "the other is between ground and A0".

You need to describe what you're doing more clearly and accurately. Eg. You're trying to estimate (or measure) the voltage at the output of the DC converter by first measuring the voltage at the mid-point of the divider, and then using that measured voltage to calculate (estimate) the voltage at the top of the divider. In other words, if the voltage feeding the top of the divider is 'B', and the midpoint voltage of the divider is 'A', then A = {100/(100+1000)}*B.

So B = {(100+1000)/100}A = 11A

So if the divider midpoint voltage A turns out to be 0.245454545..... volt, then B would be calculated to be 2.7V.

If your 5V reference supply (for the arduino) isn't accurate (ie. is not close enough to 5V), then your measurement of 'A' would be out by a little bit, and the relative error would then propagate to your value of 'B'.

Note that if you are using this 'back calculation' method to estimate the voltage 'B', then to say the following is quite misleading : "I have Arduino UNO reading the output voltage of a DC step-down converter".

Divide by 1024, not 1023.

reversing your calculation showed analogRead must have been returning 48, and correcting
the formula to:

 11.01 * 5.0 / 1024 * analogRead(A0)

gives 2.58V, with an error of at least 2% just due to the low resolution at this voltage.

The 4.7mV values seems to have been a bit bogus (or had you measured your Arduino 5V accurately
and divided already?).

The Arduino input resistance is effectively infinite, not 100M (that's worst case at maximum junction
temperature), whereas your DMM will have a definite real resistance of 10M or something like that.

Most CMOS inputs are 10^10 ohms or more at room temperature, limited by the protection diode
reverse leakage current. This is why they float in voltage if unconnected.

If it was my project I’d use the internal voltage reference , which gives the analog input span as about 1.1 volts and is unaffected by the 5v supply.
Use some sort of voltage divider on the input , but use smaller resistors ( less than 100k? )
Then use the map function and calibrate the reading , rather than calculate it .

hammy:
If it was my project I’d use the internal voltage reference , which gives the analog input span as about 1.1 volts and is unaffected by the 5v supply.
Use some sort of voltage divider on the input , but use smaller resistors ( less than 100k? )
Then use the map function and calibrate the reading , rather than calculate it .

The problem with that is you have to calibrate the sketch for every new board you use it on, as the
1.1 bandgap reference is spec'd as between 1.0 and 1.2V. 5V regulators are much more tightly
controlled, and having to calibrate is extra complexity and work.

Southpark:
I think you're better off just drawing a circuit diagram, because your description of the circuit doesn't seem to tie in with the values that you wrote ---- such as .... where do the values of 2.48V and 2.69 V come from?

You mentioned a voltage divider ---- with 1 M connected to 2.7V on one end, and the 'other' resistor connected between 'A0' and GND. So this suggests that A0 is connected to the mid-point of this voltage divider.

So A0 should be reading an equivalent voltage of around 0.245 volt, right? Or.... around level 50 (in the range from level 0 to level 1023) with a 5V reference.

You mention that the UNO is reading the output voltage of the step converter. So this suggests that A0 is connected to the 2.7V output of the step converter? But, on the other hand, you're also suggesting later that A0 is at a different location ----- at the mid-point of the divider.

So.....the question is .... which is it? Which location is A0? At the moment ---- your description suggests A0 is connected to two different spots at the SAME time. That is "I have Arduino UNO reading the output voltage of a DC step-down converter fixed at around 2.7V." versus "the other is between ground and A0".

You need to describe what you're doing more clearly and accurately. Eg. You're trying to estimate (or measure) the voltage at the output of the DC converter by first measuring the voltage at the mid-point of the divider, and then using that measured voltage to calculate (estimate) the voltage at the top of the divider. In other words, if the voltage feeding the top of the divider is 'B', and the midpoint voltage of the divider is 'A', then A = {100/(100+1000)}*B.

So B = {(100+1000)/100}A = 11A

So if the divider midpoint voltage A turns out to be 0.245454545..... volt, then B would be calculated to be 2.7V.

If your 5V reference supply (for the arduino) isn't accurate (ie. is not close enough to 5V), then your measurement of 'A' would be out by a little bit, and the relative error would then propagate to your value of 'B'.

Note that if you are using this 'back calculation' method to estimate the voltage 'B', then to say the following is quite misleading : "I have Arduino UNO reading the output voltage of a DC step-down converter".

Thanks for the help, but I thought it was clear that I was measuring the converter via voltage divider. Your schematic is correct and that's how I connected everything.
Why do I want to measure such a low voltage with a divider? I thought it was a good idea to use a divider because in case of failure of the converter (if it burns), the output voltage would be same as input (12V) and I have been told to not push 12V directly to analog inputs xd.

Edit: The 2.69V value comes from a voltmeter at the converter's output
The 2.48V value is what I get from arduino after applying conversion integer to voltage and then multiply it by 11 (the divider).

If you use the internal reference the input span of the A/D becomes about 1.1volts, but the input circuitry is still protected to 5volts. You can therefore choose your resistor values to better use the resolution of the A/D , whilst it is then protected against your fault condition.

neukyhm:
Thanks for the help, but I thought it was clear that I was measuring the converter via voltage divider. Your schematic is correct and that's how I connected everything.

That's ok. You wrote that the uno was reading the voltage at the output of the converter.... which never actually occurred. But that's ok. Everything is clear now.

Make sure to measure the resistances of your divider resistors..... since the divider ratio needs to be accurate.... aside from needing an accurate voltage reference.

neukyhm:
Why do I want to measure such a low voltage with a divider? I thought it was a good idea to use a divider because in case of failure of the converter (if it burns), the output voltage would be same as input (12V) and I have been told to not push 12V directly to analog inputs xd.

All you need to do is add a 10k resistor in series, that will protect the analog pin. No need for divider.
You can be extra prudent and add a schottky diode between the analog pin and the 5V supply to prevent
it going above 5V (the schottky diode takes the current that otherwise the analog pin's protection
diodes would absorb).