18 October 2026
What Is PWM? How Your Child Can Fade an LED Without a Dimmer Switch
Your child already knows how to turn an LED on and off with digitalWrite. Now they want more: a lamp that fades in and out like it's "breathing," a fan that spins at whatever speed they choose, a robot that speeds up and slows down smoothly.
The problem: a digital pin has only two states — HIGH or LOW, on or off. There is no "slightly on." So where do all those smooth effects come from?
The answer is a clever trick called PWM (Pulse Width Modulation): switching on and off so fast the human eye can't keep up, and adjusting the ratio of on-time to "fake" different brightness levels.
Blinking so fast the eye gets fooled
Imagine flipping a light switch 490 times per second. Your eyes can't follow that — instead of seeing flicker, they perceive the average brightness.
- On 10% of the time, off 90% → the eye sees a dim light.
- On 50%, off 50% → medium brightness.
- On 100% → fully bright.
That on-time ratio is called the duty cycle. PWM is literally "adjusting the width of the on-pulse" — the wider the pulse (the longer it's on in each cycle), the brighter the LED. On an Arduino the pulses repeat about 490 times per second, fast enough that every effect looks smooth.
That's why PWM is nicknamed "fake analog": the pin is still just jumping between 5V and 0V, but on average it behaves like a varying voltage. For LEDs and motors — the two things kids control most — that's plenty.
The code: one line does it
Arduino has a dedicated PWM function, called analogWrite (don't let the name fool you — it's still digital PWM under the hood):
analogWrite(9, 128); // about 50% brightness: value range 0–255
The value runs from 0 (fully off) to 255 (fully on). To make an LED "breathe," just ramp the value up and down in a loop:
for (int i = 0; i <= 255; i++) { analogWrite(9, i); delay(10); } // fade in
for (int i = 255; i >= 0; i--) { analogWrite(9, i); delay(10); } // fade out
Two gotchas beginners always hit:
- Not every pin can do PWM — only pins marked with a ~ next to the pin number (on the UNO: 3, 5, 6, 9, 10, 11). Plug into a regular pin and
analogWritedoes nothing. - The scale is 0–255, unlike
analogReadfor sensors which is 0–1023. Mixing up the two scales is a classic beginner bug.
PWM is everywhere around your child
Once they know PWM, they'll start spotting it everywhere:
- A "breathing" night light: the classic first experiment, just a few lines of code.
- A 3-speed mini fan: a button cycles the duty cycle through 30% → 60% → 100%.
- A buzzer with volume control: same buzzer, PWM decides how loud.
- Motor speed control — the big one: a robot that sprints on straights and slows down where precision matters. Without PWM a robot only knows "full speed" or "stopped" — it could never take a smooth turn.
A step-up experiment for parent and child (it ties in nicely with the potentiometer lesson): read a knob with analogRead, then map the value to PWM brightness — twist the knob and the LED follows. Five lines of code, and your child sees the full "sense → decide → act" loop.
From a breathing LED to a competition robot
PWM is the bridge between "making a lamp for fun" and "controlling a real robot." Later, on the C++ track with ESP32 kits (for ages 13+), the very same PWM drives four mecanum wheels in four directions and throttles motors from sensor input — the same principle your child learns today with a single LED.
On ManuStem, your child meets PWM early in the Component Lab lessons: Gen AI writes the "breathing" loop together with them, the 3D preview shows the robot speeding up and slowing down exactly with the duty cycle they set, and the Agent coach explains why the motor goes "dead" on a pin without the ~ mark — before frustration sets in.
ManuStem has 28 lessons (8 Component Lab + 20 Competition Robot), 4 free trial lessons, for ages 8+. Kids learn entirely in the browser — AI Circuit wires, Gen AI writes code with them, the Agent coach debugs step by step — no kit required, in Vietnamese and English.
Let your child make their first LED "breathe" at stem.manusignal.com — free, 15 minutes, right in the browser.