10micro:bit · MakeCode 30 minutes
Brightness knob
Read a potentiometer on P1 and set the LED brightness.

Lesson goal: Read analogReadPin(P1) (0..1023) and copy it to analogWritePin(P0).
Open MakeCodeSection 1
Understand
- potentiometer
- voltage divider
- analog input
- ratio to supply
- 1Knob outer legs to 3V and GND, middle leg to P1.
- 2analog read gives 0–1023 and sets the LED brightness.
- 3Voltage shown is a rough estimate.
Safety first
- Unplug the USB cable before you add, move or remove any wire. Plug back in only after an adult or you have re-checked every connection against the table.
- micro:bit pins are 3 V logic. Never connect 5 V, a battery pack or anything from a 5 V supply to any ring, port or the 3V ring.
- The pot's outer legs go to 3V and GND only, never to 5 V.