// LAB 09 · INTERACTIVE
PWM simulator: how analogWrite dims an LED
Change the duty cycle and the speed: see the square wave, the average voltage and the LED dim.
⚡ POWERING UP THE LAB…
// HOW IT WORKS
The idea in 30 seconds
- PWM switches the pin fully ON and OFF very fast. Duty cycle = how much of each cycle it is ON.
- Average voltage = duty × 5 V. 25 % duty on a 5 V pin averages 1.25 V.
- Above about 50–100 blinks a second your eye can't see the flicker, so the LED just looks dimmer.
- On an Arduino Uno, analogWrite(pin, 0–255) sets the duty; PWM runs at about 490 Hz (pins 5 and 6: about 980 Hz).
Watch the lessons
More labs
All labs →LAB · INTERACTIVE · NEWLogic gatesFlip two switches and watch AND, OR, NOT, XOR and friends decide if the lamp lights.LAB · INTERACTIVE · NEWBinary & hex bitsFlip 8 bits and see the number in decimal, hex and binary — plus the PORTB line to write it.LAB · INTERACTIVEResistor colour codeTap the bands, read the value — then beat the decode challenge.
