let's consider this simple piece of code:
void setup() {
Serial.begin (9600);
}
void loop() {
int code = analogRead (A2);
double voltage = code *5/1024;
Serial.print("Voltage is ");
Serial.println(voltage);
delay (500);
}
It is simply the A/D conversion of a voltage applied between A2 and GND. Unfortunately I saw that this reading is not so accurate. Precisely, if I use a battery of 3.5V, on the serial monitor I will see the value voltage = 3.00. If I use a battery of 1.5V, I will see 1.00 V.
This means that the program works correctly, but it is not accurate. Which is the reason for this and how can I solve it? I do not understand the reason for this since the resolution of Arduino as ADC is equal to 5/1024 = 4.88 mV, so I think that we may have a quantizazion error of 4.88mV, and not of 0.5V.