I need to measure voltage between 0-5V
the problem is sometimes, 5v supply can go down to 4V, the arduino works, but measurment is wrong because voltage reference is not 5V anymore
Can I supply 5V on Aref, have 4V on "5V power input" pin, and measure correctly 4.5V on a analog pin?
altzu:
Can I supply 5V on Aref, have 4V on "5V power input" pin, and measure correctly 4.5V on a analog pin?
No.
The answer is to lower the input voltage with a voltage divider to <= 1volt.
Then switch the A/D reference internally (with code) to 1.1voltAref in setup().
That makes things also independent of supply voltage variations.
Leo..
Another benefit of the internal reference is the input is still protected to Vcc (5v), despite having a full scale voltage of ~1.1volts .
So if you arrange the input to your resistor divider to give you 1v with a 5v volt input , that would mean you could put 25v on the divider and not damage the Arduino ( as that would still only give 5v on the analog input)
Note that different devices have a large variation of the 1.1V reference, so you have to calibrate your
Arduino specifically, as the nominal 1.1V can be anything from 1.0V to 1.2V according to the datasheet.
[ This would be a big issue for mass-production ]
You might also want to consider external voltage references which are commonly available in 4.096V, 2.56V,
or simply using the 3.3V pin as a 3.3V reference?