I need to read a 0-1.2V analog input (as accurately as possible) but, I know the measurement is affected by supply voltage. I bought some zeners and was going to read A0 (the zener) then read A1 the input to get a correct reading.
Now I learn that I can use the internal reference and I don't need the zeners. I've read sample code but I just can't grasp how this works.
Can someone post a code snippet showing me how to set the reference and how to use it to correct A1?
I'm using a ProMini if that matters.
Thanks in advance.
The internal reference is approximately 1.1 volts, the voltage you are testing must be lower than this, a voltage divider can do that. What is the maximum voltage you expect to see, and the output impedance if you know it?
const float aRef = 1.1; // measured with accurate voltmeter
const byte aInPin = A0; // signal input pin
Serial.begin(9600); // set serial monitor baud rate to match
analogReference(INTERNAL); // use internal 1.1 volt reference
volts = analogRead(aInPin) * aRef / 1024;
Serial.println(volts,3); // 3 decimal places
delay(500); // time to read
The FIRST project I am trying with this is a LM34 temp sensor so, the input voltage probably will only go up to 1.05V.
1.1V worst case.
1.05V = 105F
1.1V = 110F
So, when you set "analogReference(INTERNAL)", all of the ADCs are measured against it automatically?
"= analogRead(aInPin) * aRef / 1024;" (which equals " (A0/1024)*aRef ) to get the value?
THAT makes sense. Outsider, you're awesome!
I was under the impression that you had to read the Reference and read the ADC. It's nice to know the internal ref 'automatically" corrects the ADCs.
You must ensure nothing is connected to the AREF pin, and call analogReference(INTERNAL) in setup() before
Each individual chip will need its own calibration, since the internal reference is spec'd to be anywhere
from 1.0 to 1.2V. For any particular chip it should be pretty stable with temperature, but note that it
is not a precision voltage reference.
The best way to store the calibration data is in EEPROM, so its persistent with the chip and you don't
have to change the sketch (you'll need a separate calibration sketch you run once to determine
Frankly using a precision external reference seems like a lot less hassle!