Voltage in, number out
Pin A0 has an ADC (analog-to-digital converter) behind it: it measures a voltage from 0 to 5 V and gives a whole number from 0 to 1023. It cannot feel heat or light. A sensor's job is to turn the world into that voltage.
The potentiometer
A potentiometer, or pot, is a 10 kΩ resistor track with a sliding contact, the wiper, on its middle pin. Turning the knob moves the wiper, so it splits the track into two parts. Together they always add up to 10 kΩ.
Turn the wiper 30 % of the way up: the lower part is 3 kΩ, the upper 7 kΩ. The pin gets that share of 5 V: 1.5 V. analogRead returns 307. Twice the turn, twice the number.
The thermistor
Most sensors are just one resistor that changes. So pair it with a fixed 10 kΩ resistor: a voltage divider. The pin sits at 5 V × sensor ÷ (10 kΩ + sensor). Change the sensor and the voltage follows.
A thermistor is a resistor made to change with heat. Ours is an NTC: warmer means less resistance. The datasheet gives 32.6 kΩ at 0 °C, 10 kΩ at 25 °C and 3.6 kΩ at 50 °C. So the pin voltage falls as it warms.
At 25 °C the thermistor is 10 kΩ, equal to the fixed one, so the pin sits at 2.50 V and reads 512. Line 2 turns the reading back into ohms: 10000 × 512 ÷ (1024 − 512) = 10000 Ω.
Lines 3 and 4 use the thermistor's B value, 3977 from the datasheet, to turn ohms into kelvin (0 °C = 273.15 K), then Celsius: 25.0 °C. Warm it to 35 °C: it reads 404, which gives 34.9 °C. Close, not perfect.
The light cell
Swap in a light cell (LDR, light-dependent resistor). More light means less resistance: at least 1 MΩ in the dark, and 8 to 20 kΩ at 10 lux, very dim light. Same divider, same line 1.
One GL5528 can be 8 kΩ at 10 lux and the next 20 kΩ, so nobody turns it into exact lux. Use it for dark or bright: a night light switches on when raw is above 800. Dark reads about 1013.
What happens
;; step 1/9 · voltage-only board Arduino Uno R3 (ATmega328P, 5 V) line 1 int raw = analogRead(A0); ADC raw = Vin x 1024 / 5 V, top value 1023 one count 4.88 mV the job world -> resistance -> voltage -> number
The B equation is a simple fit through 25 °C and 85 °C. With the datasheet's real resistances it gives 0.8 °C at 0 °C, under one degree off. Vishay's datasheet gives a longer formula for better accuracy. The ATmega328P's ADC works best when the source has 10 kΩ or less behind it. A divider with a 10 kΩ resistor on top never has more than 10 kΩ, even with a light cell at 1 MΩ.