analogRead and PWM: a pot dims an LED
analogRead turns 0–5 V into a number from 0 to 1023 (10 bits). analogWrite cannot make a real voltage: it switches the pin fully on and off 490 times a second, and the share of time it is on (the duty cycle, 0–255) sets the average. Only pins 3, 5, 6, 9, 10 and 11 can do it.

Open this lesson in the labFree, in your browser, no account needed.
Try it on the bench
- Turn the pot (select it, drag Position) and watch the numbers and the LED.
- Change pin 9 to 8 in the sketch and upload: pin 8 has no PWM, so the LED is only fully on (128 and up) or off.
- Open the Serial Monitor at a different baud rate: the text turns to garbage, because both ends must agree.
Parts on the bench
In the course
Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.