← All articles

18 October 2026

What Is PWM? How Your Child Can Fade an LED Without a Dimmer Switch

PWM - pulse width modulation fades an LED

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.

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:

  1. 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 analogWrite does nothing.
  2. The scale is 0–255, unlike analogRead for 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 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.

Read the Vietnamese version:

PWM là gì: cách con làm đèn LED 'thở' mà không cần núm vặn