What is the correct way to interpret the built-in Analog-to-Digital Converter output? When using the built-in analog to digital converter of the Arduino Uno Rev 3's Atmega328P with a reference voltage of 5V, what is the appropriate function to interpret the output? There is conflicting information on the Arduino website and in the datasheet for the Atmega328P (Arduino Uno Rev 3's chipset).

A lot of code examples on the internet indicate that the appropriate conversion factor is 5V/1023 (including the Arduino website: float voltage= sensorValue * (5.0 / 1023.0);).

Per the Atmega328P's datasheet, it indicates the conversion factor is 5V/1024:


If Vin and Vref are 5V, then the ADC reading would need to be 1024 in order to have a true reading of 5V, which is not possible since 1023 is the max output of the ADC. The closest reading to 5V we can get from this equation is ~‭4.9951 (5V*1023/1024).

With the Arduino example's conversion factor of 5V/1023, we get 5V for an ADC output of 1023.

Additionally, since the information from both sources is in conflict, it got me thinking a little more: The ADC is inherently sampling, and I am not sure if the ADC rounds up/down to the nearest value, so perhaps the closest approximation of Vin is an equation like the following that splits the difference:

Vin = (ADC+(ADC+1))/2 * 1024/Vref

Using the above equation, an ADC reading of 0 with Vref=5V would give Vin = (0 + (0+1))/2 *1024/5V = ~0.00244. This equation never gives a reading of 5V or 0V, but rather a value that splits the difference between samples.

Perhaps I am splitting hairs since the absolute accuracy of the ADC is "±2 LSB absolute accuracy", but I would still like to know which is the best equation to convert an output from the ADC into a voltage measurement.
the Atmega328P's datasheet, it indicates the conversion factor is
  5V/1024 [...]


Indeed. And the datasheet is the only authoritative source. All the
other sources are second-guessing.


  If Vin and Vref are 5V, then the ADC reading would need to be 1024 in
  order to have a true reading of 5V


You can't get a true reading of 5&nbsp;V. As per the datasheet (emphasis
mine): “0x000 represents analog ground, and 0x3FF represents the
selected reference voltage minus one LSB”.

Any input voltage larger that the maximum representable voltage will
read as 0x3ff (i.e.&nbsp;1023), just like any negative voltage (within
the forward voltage of the protection diode) will read as zero. Thus,
reading either&nbsp;0 or&nbsp;1023 should be interpreted as a saturation
of the ADC, meaning the actual voltage is unknown.


  The ADC is inherently sampling, and I am not sure if the ADC rounds
  up/down to the nearest value


In principle it should round to the nearest value. The transition in the
reading from&nbsp;0 to&nbsp;1 should ideally happen at
Vref/2048. C.f., again, the datasheet, subsection “ADC
Accuracy Definitions”: “Offset: The deviation of the first transition
(0x000 to 0x001) compared to the ideal transition (at 0.5 LSB).”

A little bit further in the page it is stated that the ideal position of
the last transition (1022 to&nbsp;1023) is “at 1.5 LSB below maximum”.


  Perhaps I am splitting hairs since the absolute accuracy of the ADC is
  "±2 LSB absolute accuracy"


Indeed. If you really care you should probably calibrate your ADC. See
Response of the Arduino ADC.

Edit: in a comment you mention that the factor&nbsp;1024 could
conceivably be “a persistent typo that it appears in multiple AVR
chipset datasheets”. It may be an error, but certainly not a typo, as
the datasheet contains multiple independent statements that confirm the
factor&nbsp;1024.