Skip to content

1024 used instead of correct 1023 in analogRead reference #708

Open
@StefanT83

Description

@StefanT83

Dear reader,

I believe there is an error (typo) in the online documentation of
https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
related to the number 1024 being used wrongly, instead of 1023 which is the correct one.

In my opinion the resolution of Arduino Uno is 5 Volt / 1023 = 4.8875855 mV per unit. This value will allow us to match the reading of 1023 into 5 Volt (not more, nor less).

Let's check the consequences of what is mentioned on the online site: Arduino "will map input voltages between 0 and the operating voltage(5V or 3.3V) into integer values between 0 and 1023. On an Arduino UNO, for example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit. ". So if we do the maths, it means that if one gets a reading from the Arduino of 1023, if we multiply that by the resolution of 4.9 mV, we end up with 5.0127 Volt (i.e. more than 5 Volt). This contradicts the first statement.

Can we conclude there is a typo on Arduino's online documentation of arduinoread() function?

Activity

transferred this issue fromarduino/Arduinoon Oct 23, 2019
changed the title [-]typo in the arduinoread() documentation[/-] [+]typo in the analogRead() documentation[/+] on Oct 28, 2019
matthijskooijman

matthijskooijman commented on Oct 28, 2019

@matthijskooijman
Collaborator

So if we do the maths, it means that if one gets a reading from the Arduino of 1023, if we multiply that by the resolution of 4.9 mV, we end up with 5.0127 Volt (i.e. more than 5 Volt). This contradicts the first statement.

This seems like a rounding error. If the resolution is 5/1024 and you multiply that by 1023, there is no way that will end up above 5.

It will end up slightly below 5, which can be unexpected. However, I this is a matter of interpreting the results. I haven't checked the datasheet, but I think that a reading of "0" might actually mean any voltage between 0 and 4.9mV, whereas 1023 means anything between 4995.1mV and 5V. So just doing "ADC reading * resolution", will get you the lower limit on the measured value, which is then obviously not 5V for 1023, but a bit lower.

The datasheet might offer some info to confirm how voltage map to analog readings exactly, I'm not 100% sure my above interpretation is exactly accurate.

Also, in practice the accuracy of an ADC is such that the measurement error is typically up to a few LSB's (i.e. a few times the 4.9mV resolution), so any offset of less than one LSB might not really matter much.

changed the title [-]typo in the analogRead() documentation[/-] [+]1024 used instead of correct 1023 in `analogRead` reference[/+] on Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      1024 used instead of correct 1023 in `analogRead` reference · Issue #708 · arduino/reference-en