[SOLVED] analog input with voltage divided AREF not giving expected result

Hi, I was testing the use of a voltage divided AREF (using the 5V Uno output with two equal 10k resistors), to bring the analog input range down to 2.5V. I was doing this to measure the voltage of an AA battery. The voltage reading I get from my multimeter is 1.35V but the Uno is calculating 1.54V.

I tried recreating the circuit using circuits.io and don't have this problem (ie the simulated Uno outputs the same 1.5V as the battery 1.5V). I wonder if this is something I am not understanding about resistances of the other parallel components affecting the voltage divider, or something silly I am doing with the AREF. Any help would be much appreciated!

I've attached an image of the circuit (the resistors are all 10k), and the sketch code is below.

int analogValue = 0;
float voltage = 0;

void setup() {
  analogReference(EXTERNAL); // setting AREF to voltage divided input
  Serial.begin(9600); // enabling serial output
}

void loop() {
  analogValue = analogRead(0);
  voltage = 0.0048 * 0.5 * analogValue; // *0.5 because have set ref to 0.5 * 5V
  Serial.println(voltage);
  delay(500); // delay 500ms between value updates
}

You should not be expecting accurate results with this approach.

The Arduino voltage is almost certainly not 5.00V, nor are the voltage divider resistors accurate.

What value do you get in analogValue?

It should be 1.34 * 1023/2.5 => 548.

Have you decoupled the reference voltage? how accurate are your resistors? Is the arduino +5 actually +5?

there are several possible error sources.....

regards

Allan

A more stable 5volt/supply independent ~2.5volt Aref can be made by connecting a 10k resistor between the 3.3volt pin and the Aref pin. And ofcourse setting Aref to external.
And you always have to calibrate.
The maths line could be:
voltage = 0.0024 * analogValue; // calibrate by changing 0.0024xx
Leo..

Hi, thanks for all of the replies. Summarising the answers to the above questions:

Measured values:

  • Arduino 5V, Vin = 4.97V
  • Resistor R1 (+ve side of divider) = 9.82k
  • Resistor R2 (-ve side of divider) = 9.92k
  • Resistor R3 (parallel with battery) = 9.84k
  • analogValue = 634 (= 0.0024 * 634 = 1.54V)
  • AREF voltage = 2.46V

By my calculations the AREF input should be:
= Vin * R2 / (R1 + R2)
= 4.97 * 9.92 / (9.82 + 9.92)
= 2.5V

I don't understand what "Have you decoupled the reference voltage" means?

I can't see any tolerances above that would explain the significant discrepancy between the Arduino predicted battery voltage of 1.54V and my DMM measurement of 1.35V. I am sure it is my fundamental misunderstanding of something.

If I disable the AREF and amend the maths line I get 1.32V measured from the Arduino, ie what I would expect. So it is definitely something silly I'm doing with the AREF.

Thanks, Peter.

Hi,

the resistor on the battery line is to pulldown the A0 input when the battery is disconnected.

I was using the voltage divider with equal R1 and R2 to give a 2.5V input to AREF, so changing the A0 input range from 5V to 2.5V. Is that not right?

Peter.

I don't understand what "Have you decoupled the reference voltage" means?

It means put a 0.1uF ceramic capacitor across each of the 10K resistors in the potential divider.

From this page analogReference() - Arduino Reference

Alternatively, you can connect the external reference voltage to the AREF pin through a 5K resistor, allowing you to switch between external and internal reference voltages. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) = ~2.2V at the AREF pin.

This should tell you that a 10K impedance is way too high for an external reference voltage for the Aref pin.

From the Aref page:
"Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin."
So you DON't use a voltage divider, because there is already some build-in resistance.
That will throw off your 10k:10k divider.

As said in post#3, use a single (pull up) resistor.
Use it from the 3.3volt pin, because that voltage is potentially more stable than the 5volt pin.
Leo..

First off, just a note about what I was trying to achieve here. I was just playing around with the AREF input to see if I could change the input range at A0. I just happened to have a simple tutorial battery voltmeter circuit setup from a book I'm reading, hence trying it with this. I'm not too concerned about its accuracy for this application, but I'm glad I tried it because it has shown up some problems with my understanding.

Thanks for the pointer to those notes under the analogReference() documentation, I hadn't seen that. I'm trying to get my head around this, so bear with me. I am only just starting to learn about electronics and Arduino so don't assume that my basics are right yet!

I'm a bit confused about when a reference voltage is a reference voltage. I mean, everything has a resistance, so when you are saying "10k is way too high" and "DON'T use a voltage divider" at the AREF, I think what you are saying is that its not fundamentally a problem to do that, just you need to take that into account when working out the voltage the AREF pin sees?

For example if I connect a battery directly to the AREF it has resistance, and is still acting as a voltage divider with the AREF's 32k input but is it just that its resistance is so low that its effect is negligible on the voltage division equation. So when people say a "reference voltage" does that just mean a voltage source with low resistance relative to the circuit its being attached?

I'm also confused by that documentation saying "Alternatively, you can connect the external reference voltage to the AREF pin through a 5K resistor, allowing you to switch between external and internal reference voltages." I think the alternative is not using a resistor at all? Is that right? If that is right, then I'm not sure what it means by using a 5k resistor allows you to switch between external and internal reference voltages? Why can't you switch without it?

Thanks, Peter.

The reference voltage is the size of the ruler that measures the analogue inputs.

If the reference voltage is 5volt (default), then the 1024 steps of the 10-bit A/D are stretched across 5volt.
Then 2.5volt on the analogue input(s) will result in an A/D value of ~512.

If you lower Aref, then the "ruler" gets smaller.

If you make Aref e.g. 2.5volt, then the 1024 A/D steps will be spread over 0-2.5volt.
Then 2.5volt on the analogue inputs will give an A/D value of 1023.

In your case (with a 10k:10k divider on Aref) Aref won't be 2.5volt because if the 32k internal resistance of the Aref pin. The "bottom" resistor of the divider is a combination of the external 10k resistor and the internal 32k resistor.
(10k + 32k) / (10k + 32k) = 7k62. So the divider is really 10k:7k62.
That will result in an Aref voltage of 7.62k / (10k + 7.62k) * 5volt = 2.16volt.
Leo..

badbunny_uk:
I'm also confused by that documentation saying "Alternatively, you can connect the external reference voltage to the AREF pin through a 5K resistor, allowing you to switch between external and internal reference voltages." I think the alternative is not using a resistor at all? Is that right? If that is right, then I'm not sure what it means by using a 5k resistor allows you to switch between external and internal reference voltages? Why can't you switch without it?

The 5k resistor (minimum value) is to protect the Aref pin in case you forget to set Aref to external.
Leo..

Hi Leo,

thanks for bearing with me on this. I get how the A/D range is being spread to the smaller analogue range set by the AREF value, its more the concept of the reference voltage itself that is confusing me. My thoughts are that everything has a resistance so whatever I connect to AREF will act as a voltage divider with the 32k internal pin resistance. Just if the external resistance is low enough, then its effect becomes negligible. So is a 'reference voltage' just a voltage source with low resistance relative to the circuit its connected?

If I was to use another voltage, like the 3.3V with 10k resistor you suggested earlier, how do I know how much the internal resistance is (ie within the circuit generating the 3.3V) ? I think I am a bit confused as to where my consideration of resistances ends in the voltage division equations. Is the resistance in the Arduino itself really low such that its negligible in these equations for voltage division?

I'm also wondering why the external 5k resistor is needed for protection. Doesn't the 32k AREF pin resistance provide the protection? Or is that disabled somehow when the EXTERNAL option isn't selected?

Thanks, Peter.

My thoughts are that everything has a resistance

Yes but when talking about the resistance of inputs and outputs we normally say "impedance" which in this case is the same thing but for AC signals also takes into account any capacitance and inductance altering the phase.

If I was to use another voltage, like the 3.3V with 10k resistor

I use the 3V3 voltage without any resistor, in that way the reference voltage IS 3V3.

I'm also wondering why the external 5k resistor is needed for protection.

If you look at the schematic in the data sheet for the chip you will see the external AREF input can be connected to the Avcc or the internal 1.1V reference with the FET controlled by REFS0 bit. This means if you have a voltage on AREF and make a mistake and set that bit incorrectly then you are connecting two unequal power supplies together. This causes a lot of current to flow and burns stuff. A resistor limits the current under these fault conditions.

Hi Mike, I don't understand this:

I use the 3V3 voltage without any resistor, in that way the reference voltage IS 3V3.

My understanding is that a voltage has an associated impedance from whatever is creating that voltage. So in the Arduino there is some circuitry creating that 3V3 level. Is it just that the 3V3 Arduino voltage has such a low associated impedance that it is effectively negligible in any downstream voltage division equations and thus its impedance isn't important?

Thanks, Peter.

Yes that is right, the 3V3 comes from a voltage regulator and those have out impedances in the order of a fraction of an ohm which in comparison to the 32K input impedance of the AREF is known by the technical phrase as "bugger all".

Awesome. Thanks for all the help guys, much appreciated.

So to summarise, if anyone has skipped to the end here...

The problem was that I had not realised that the AREF pin has its own internal resistance of 32k in addition to my 10k:10k voltage divider, so the voltage I thought I was getting at AREF was not right.

Thanks,
Peter.

I alway measure the voltage at the AREF pin with a DMM and store in a global float, ie. float aRef = 4.92 or whatever, especially with a Nano where the reverse blocking Schottky diode may drop the voltage 0.2 - 0.3V, on a Nano you have to run an analogRead() instruction before the AREF pin shows anything. Then you can write (for a Nano);

float aRef = 4.72; // measured with DMM
void setup()
{
   Serial.begin(9600);
}
void loop()
{
   float volts = analogRead(0) * aRef  / 1023;
   Serial.println(volts);
   //
   // more code
   //
}

@outsider, the correct divisor is 1024.

Did you measure Aref with a 10k resistor between 3.3volt and Aref, with Aref set to external?
Leo..

badbunny_uk:
Awesome. Thanks for all the help guys, much appreciated.

So to summarise, if anyone has skipped to the end here...

The problem was that I had not realised that the AREF pin has its own internal resistance of 32k in addition to my 10k:10k voltage divider, so the voltage I thought I was getting at AREF was not right.

Thanks,
Peter.

That's why you should read the datasheet if possible, the peculiarities of each pin type will be given. Somewhere
I recall it saying that AREF must be driven from a low impedance source.