Hello everyone,
I recently encountered a surprising issue with the ADC on my Arduino Uno R4 WiFi. While attempting to measure a constant voltage, I noticed that the analogRead()
function returns values that seem incorrect compared to my older Arduino Uno R3.
Below is the code I used.
void setup()
{
Serial.begin(9600);
pinMode(A1, INPUT);
}
void loop()
{
int value = analogRead(A1);
double converted = value * 5.0 / 1023.0;
Serial.print("value = "); Serial.println(value);
Serial.print("converted = "); Serial.println(converted);
Serial.println("");
delay(1000);
}
When probing GND (wire from pin A1 to closest GND pin), and 5V, both Arduino's give the same result : value = 0
or value = 1023
.
However, when probing the 3.3V pin, R4 result is incorrect :
R3 : value = 683
, converted = 3.33
R4 : value = 725
, converted = 3.54
This behavior is similar on all analog pins (from A0 to A5). Moreover, it also appears with different resolutions (12-bit or 14-bit).
I don't see any mentions of this behavior in the datasheet, nor in the Arduino UNO R4 WiFi ADC Resolution doc page.
Is this behavior expected on the Uno R4, and if so, can it be calibrated ? Or Do I have a defect board ?
Thanks a lot for your help.
Pierre
Delta_G
November 25, 2024, 7:53pm
2
Most likely neither board has a vref of exactly 5.0V. For accurate readings you should take into account the actual voltage.
Most likely the two boards are simply running slightly different voltages. This would be expected as they have very different regulators.
1 Like
With a multimeter, measure the actual voltage on your 5V pin.
Multiply by that value instead of 5.0 when calculating converted
.
I think you'll find the value of converted
will be correct.
1 Like
Well, ... Indeed, the voltage on the AREF pin of the R4 is 4.63V.
I am now a bit embarrassed I have not checked before !
Anyway, thank you for the hint !
Watch out for the difference in the nominal 5V line if you power the board by the barrel connector.
I'm currently using the USB supply, but I'll definitely be more careful in the future.
Interestingly, I’ve never encountered this issue with any of my Uno R3 boards.
Thanks again for the hint
Wawa
November 26, 2024, 7:03am
7
You should use one of the internal reference voltages of the board.
That makes voltage measurements independent of supply voltage.
The Uno R3 has a ~1.1volt Aref for this, the R4 has AFAIK a 1.5volt Aref.
See this page.
Just use a voltage divider to dial down your input voltage to or below that Aref value.
Then use the actual Aref voltage in your formula.
Leo..
1 Like