I'm reading a 1% 47 ohm resistor value from a voltage divider using analogRead, sequentially in a loop. The first reading displays the correct value of 47 ohms, but all subsequent readings display 46 ohms.
My intent is to map the analogRead value between 10 and 73 ohms, read from my Jeep CJ-7 fueltank float pot, to the fuel quantity in the tank, between 0.0 and 15.0 gallons. One ohm out of 47 ohms is a pretty significant error, and I need to understand what is happening to generate the shift. All responses gratefully appreciated.
Here is the stripped-down code to bare essentials as I struggle to understand:
// include the library code: #include <LiquidCrystal.h>
float reading;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define sensorPIN 5
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
}
void loop() {
// put your main code here, to run repeatedly:
reading = analogRead(sensorPIN);
lcd.setCursor(0, 0);
lcd.println(reading);
delay(2000);
}
It seems like you have things arranged so that analogRead() directly returns a value of 47 or 46. If so, that is not an error of 1 in 47 but rather an error of 1 in 1023 or 1 part in 1000. And the problem is the way you are using your voltage divider.
Assuming the above is correct, you need to arrange your voltage divider so at one extreme of the potentiometer you get 5v and at the other you get 0v. Or, if that is not practical, you could arrange the potentiometer to swing between 1v and 0v and use the Arduino internal ADC voltage reference which is 1.1v (I think).
5*47/(1000+47) = 0.22445 / .00488 V/bit = analog reading of ~46 with Vref = 5V.
Very first reading might be off as the internal sample & hold capacitor charges up & settles for the first reading.
Try internal Vref, 1.1V as noted.
Then will have .00107V/bit, and analogRead will return ~210 with 47.0 ohm
46.53, 47.47 will have somewhat different results.
DennysAIR:
One ohm out of 47 ohms is a pretty significant error, and I need to understand what is happening to generate the shift. All responses gratefully appreciated.
You've only got a resolution of one unit. As othres have said, it would be possible to change the design of your resistor bridge and use a different reference voltage to get better resolution. But no matter how perfectly everything is calibrated and designed it would be easy to get a level which is on the boundary between two adjacent values, and it wouldn't be at all surprising to see the least significant bit wobbling a bit. If anything I'm more surprised that you aren't seeing more variation in the result.