Why Does analogRead Give Values 0 to 1023?
Most Arduino boards use a 10 bit analog to digital converter. 10 bit means 2^10 levels, so you get 0 to 1023.
How voltage maps to values
- 0V reads as 0
- Half of the reference voltage reads around 512
- Full reference voltage reads as 1023
Example on a 5V board:
int value = analogRead(A0);
float voltage = value * (5.0 / 1023.0);Other boards differ
Some boards use 12 bit or other ADC sizes. ESP32 often uses 12 bit, which gives 0 to 4095. Check your board docs.
Bottom line
0 to 1023 comes from 10 bit ADC resolution. The number is just a map of input voltage.
Related: What is the difference between digital and analog pins? · Can I use analog pins as digital pins? · Why is my sensor giving random readings?