Many sensors are just resistors whose resistance changes: with light, with temperature, with bending. A microcontroller cannot read resistance. It can read voltage. A voltage divider turns one into the other.
Key idea
Two resistors in series across $V_{\text{in}}$ split it. The voltage across the bottom one is $V_{\text{out}} = V_{\text{in}} \dfrac{R_2}{R_1 + R_2}$, where $R_2$ is the resistor between the output and ground.
Why it works
The current is the same through both resistors, so each gets a share of the voltage in proportion to its resistance. This is Ohm's law on two parts at once.
Worked example: Half and half
$V_{\text{in}} = 5\ \text{V}$, $R_1 = R_2 = 10\ \text{k}\Omega$.
- $V_{\text{out}} = 5 \times \dfrac{10}{20} = 2.5\ \text{V}$.
Answer: 2.5 V.
Worked example: A light sensor
A light-dependent resistor (top, $R_1$) reads 2 kΞ© in bright light; the fixed bottom resistor is 10 kΞ©; $V_{\text{in}} = 3.3\ \text{V}$.
- $V_{\text{out}} = 3.3 \times \dfrac{10}{12} = 2.75\ \text{V}$.
- In the dark the sensor might be 50 kΞ©: $3.3 \times \dfrac{10}{60} = 0.55\ \text{V}$.
Answer: 2.75 V bright, about 0.55 V dark.
Common mistake
Putting the wrong resistor on top of the fraction. The top of the fraction is the resistor between the output and ground.