The voltage
A digital pin only sees HIGH or LOW. An analog input pin measures any voltage from 0 to 5 V and turns it into a number. The Arduino Uno R3 has six: A0 to A5. We read A0.
A potentiometer is a 10 kΩ resistor with a sliding contact, the wiper. Its ends sit on 5 V and GND, so the wiper picks a voltage between them. At 64% of the way up it gives 3.20 V.
Inside analogRead
Line 2 calls analogRead(A0). The Arduino core writes the channel number into a register called ADMUX, then sets the ADSC bit to start a conversion. The CPU then waits until the converter clears ADSC.
The chip has six analog pins but only one converter. A multiplexer, a selector switch, connects just the chosen pin to it. ADMUX says channel 0, so 3.20 V from A0 goes through and the other five wait.
A switch lets the voltage charge a tiny 14 pF capacitor to 3.20 V. 1.5 ADC clock ticks after the start, the switch opens. The capacitor now holds 3.20 V steady, even if the knob moves, while the bits are worked out.
Successive approximation: test one bit per clock tick. Is 3.20 V at least 2.50 V, half of 5 V? Yes: bit 9 is 1. At least 3.75 V? No: bit 8 is 0. Ten tests later, the ADC register holds 1010001111.
Using the number
Binary 1010001111 is 655. The datasheet's rule agrees: 3.20 × 1024 / 5 = 655.4, rounded down to 655. analogRead returns it, and line 2 stores it in raw.
Line 3 undoes the rule: 655 × 5.0 / 1024 = 3.198 V, and println shows 3.20. One step is 5 V / 1024 = 4.88 mV, so every voltage from 3.198 V up to 3.203 V reads 655.
The ADC clock is 16 MHz / 128 = 125 kHz: one tick every 8 µs. A conversion takes 13 ticks, 104 µs, so at most about 9,615 readings a second. Our delay(500) asks for only two.
What happens
;; step 1/9 · analog digital pin HIGH or LOW, nothing between analog pin any voltage 0 .. 5 V -> a number 0 .. 1023 Arduino Uno R3: A0 A1 A2 A3 A4 A5 inside the ATmega328P: one converter, shared by all six
The datasheet's rule is ADC = Vin × 1024 / Vref, and 1023 (0x3FF) means "the reference minus one step", so this lesson divides by 1024 to go back. Arduino's ReadAnalogVoltage example divides by 1023.0 instead; the two differ by less than one step (4.88 mV). Real readings are not exact: the datasheet gives ±2 LSB absolute accuracy, and the reference is the board's 5 V supply, which is rarely exactly 5.00 V. Expect the last digit or two to jitter; later lessons in this module cover the reference voltage, smoothing and calibration.