Skip to content

PWM LED Fade

Fade an LED smoothly with a PWM output instead of switching it only on and off.

PWM LED Fade: the matching Arduino Uno circuit rendered in Circuitera’s simulator
Matching Circuitera simulator circuit. Real firmware capture; modeled components are idealized.

Wire it up

Disconnect power before changing connections. Follow terminal names rather than wire colors.

FromToWhy it matters
Uno · 9Resistor (r-led1) · 1Match this terminal to the sketch
Resistor (r-led1) · 2LED (led1) · AMatch this terminal to the sketch
LED (led1) · CUno · GND.1Ground reference

The complete sketch

pwm-led-fade.ino
void setup() { pinMode(9, OUTPUT); }
void loop() {
  for (int value = 0; value <= 255; value++) {
    analogWrite(9, value);
    delay(5);
  }
  for (int value = 255; value >= 0; value--) {
    analogWrite(9, value);
    delay(5);
  }
}

The launch buttons use this same code and a matching saved circuit.

Build it step by step

  1. Open a complete project

    Launch in Simulator creates a separate Uno sketch and its matching wired circuit. Existing sketches are preserved. Press Run to compile and execute.

  2. Explore the live circuit

    Watch a complete rise and fall, then change delay(5) to alter the fade speed.

  3. Try it on hardware

    Disconnect power while wiring. Match terminal names in the table, select the exact board, Verify, then connect and upload. Check component ratings and power requirements first.

Understand the sketch

Duty cycle

analogWrite accepts 0–255. The output is still digital: PWM changes how much of each cycle is HIGH. The model averages the resulting LED current.

If something is different

No gradual fade

Use D9, a PWM-capable Uno pin, and keep the 220 Ω resistor in series with the LED.

Expected output and tested scope

The LED brightness increases and decreases as the PWM duty cycle changes. This is not an analog voltage output.

Version 1 · Last source- and build-matched test: 2026-10-25. Actual shipped AVR-GCC WASM compilation and Uno AVR engine execution; no physical hardware test.

Supported tutorial target: Arduino Uno R3 / ATmega328P. Compile: PASS · Modeled execution: PASS. Other boards require a separate review of pins, voltage, libraries and the exact build profile.

Keep exploring.