By Kevin McAleer, 6 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to calculate the output of a voltage divider and build one that turns light into a voltage.
A voltage divider is two resistors in series that turn a bigger voltage into a smaller, useful one. It is the simplest sensor circuit there is, and it is how our night light will tell light from dark. Almost every analog sensor you meet, from light to temperature to joystick position, uses this trick.
Put two resistors in series across a supply, and take the voltage from the middle point:
Supply (Vin)
|
[R1]
|---- Vout (the middle point)
[R2]
|
GND
The voltage at the middle is:
Vout = Vin x R2 / (R1 + R2)
If R1 and R2 are equal, Vout is half of Vin. If R2 is bigger than R1, Vout is closer to Vin. If R2 is smaller, Vout is closer to 0 V. The ratio is what matters, not the actual values.
A potentiometer is a divider with a moving middle. It has three pins: the outer two connect to the supply and ground, and the middle pin (the wiper) gives Vout. Turning the knob slides the wiper, changing the ratio.
Build it: 10k pot on the breadboard, outer pins to the + and - rails, the wiper pin free. Measure from the wiper to ground with your meter and turn the knob. You should sweep from 0 V to the supply voltage.
Follow the voltage from the supply to the Pico pin:
flowchart LR
V["3.3 V"] --> L["LDR<br>resistance falls in light"]
L --> J(("Vout"))
J --> R["10k fixed resistor"]
R --> G["GND"]
J --> A["Pico ADC pin<br>GP26"]
A light dependent resistor changes its resistance with light: roughly 1k in bright light, 10k in a normal room, and 200k or more in the dark (very rough, as parts differ a lot). Exact numbers vary between parts, so measure yours (you did that in lesson 6).
For the night light, we put the LDR on top (R1) and a fixed 10k resistor underneath (R2), with a 3.3 V supply:
3.3 V ---[LDR]---+---[10k]--- GND
|
Vout
In bright light the LDR has a small resistance, so Vout is high. In the dark the LDR resistance is huge, so Vout drops close to 0 V. The voltage tells us how much light there is.
# Run on your computer or the Pico
# Voltage divider: LDR on top, fixed 10k on the bottom, 3.3 V supply
def divider(vin, r_top, r_bottom):
return vin * r_bottom / (r_top + r_bottom)
vin = 3.3
fixed = 10_000
conditions = [
("bright sun", 1_000),
("room light", 10_000),
("dusk", 50_000),
("dark room", 500_000),
]
for name, ldr in conditions:
vout = divider(vin, ldr, fixed)
raw = int(vout / vin * 65535) # what the Pico's read_u16() would give
print(f"{name:<11} LDR={ldr:>7} ohm Vout={vout:.2f} V raw={raw}")
Output:
bright sun LDR= 1000 ohm Vout=3.00 V raw=59577
room light LDR= 10000 ohm Vout=1.65 V raw=32767
dusk LDR= 50000 ohm Vout=0.55 V raw=10922
dark room LDR= 500000 ohm Vout=0.06 V raw=1285
The last column is the number the Pico will report, which we use from lesson 13.
Picking the fixed resistor: the best sensitivity is when the fixed resistor is about the same as the LDR’s resistance in the middle of the range you care about. Our 10k is a good choice for a room.
Why this matters: you now know how to turn “how much light” into “how many volts”. The Pico can read voltages, so this is the bridge between the real world and your code.
Common mistakes:
Teachers: LDRs from different kits behave very differently, so tell learners to use their own meter readings from lesson 6 rather than the numbers in the text. A dark corner or a cardboard tube over the LDR gives a repeatable “dark” for the whole class.
vin to 4.5. Use only the meter here: never connect a divider powered from the 4.5 V pack to a Pico pin.Why: If the fixed resistor is much smaller or larger than the LDR range, Vout sits near one end.
Quick quiz 1 of 3
With the LDR on top and a 10k resistor below, what does Vout do when it gets darker?
Quick quiz 2 of 3
A divider has two equal resistors on 3.3 V. What is Vout?
Quick quiz 3 of 3
Why swap an LDR and the fixed resistor?
Comments