3 · Outputs & actuators
PWM: dimming an LED
Intermediate15 min
Goal
Breathe an LED from 0 to 255 with analogWrite().
Why it matters
PWM fakes an analog voltage by chopping the signal very fast — the basis of dimmers and motor drives.
Steps
- 01Place the LED on a PWM pin (3, 5, 6, 9, 10 or 11).
- 02Ramp a variable from 0 to 255 with a for loop.
- 03Apply analogWrite(pin, value), then ramp back down.
This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.