VIN Technologies › Labs › Microcontroller Lab
PWM fade (analogWrite ramp)
Microcontroller Lab · free online experiment, runs in your browser with no install or sign-up.
Open this experiment in the circuit simulator
Objective
Ramp the duty cycle of pin 9 from 0 to 100 % and watch the LED brighten.
Procedure
- Press Start Simulation and watch the LED brighten over about 1 s.
- Change the step 5 to 15 for a coarser, faster ramp.
Theory
analogWrite(pin, b) produces a 490 Hz PWM wave with duty b/255. The LED's average current, and so its brightness, grows in proportion to the duty cycle.
Questions to answer
- Why does the eye see the LED as dimmer rather than flickering at 490 Hz?
Components used
Arduino UNO R3 (clone, SMD), Breadboard 400 points, LED 5mm Red, Resistor 220 ohm 1/4W
About the model
Breadboard contacts are ideal (no contact resistance or capacitance). Arduino-style C/C++ subset interpreter (not AVR machine code): no interrupts or libraries, int is 16-bit, only delay() advances time, pin modes are fixed after setup(). Outputs are 5 V behind 25 Ω.
Open this experiment in the circuit simulator