Interpreting analog voltage values

Hello all! I'm curious about specific formula on Read Analog Voltage page:

float voltage= sensorValue * (5.0 / 1023.0);

Why is maximal voltage divided by 1023 and not by 1024 ? Does it not introduce linear error that is 0 when sensorValue = 0 and ( 5.0 / 1024.0 ) when sensorValue = 1023 ?

The divisor should be 1024.

The page is wrong, but the error is quite common, so you will see that incorrect value used in a lot of places.

Refer to the first post here and ignore the subsequent 8 pages of discussion, which goes nowhere.

The maximum reading is 1023. So if you want 5V to read 5V you divide by 1023. If you prefer 5V to read 4.995V then divide by 1024. Zero isn't a problem, if sensorValue = 0 then the result is also 0 (whatever you multiply and divide it by).


That 5.0 in the formula could give a much higher error then 1023 or 1024.

5.0 assumes the Arduino supply is 5.0volt, which it rarely is.
e.g. a Nano on USB supply is ~4.6volt. That will give a > 8% error.