firmwareMIT

Arduino Uno: fade

breadboardhub/arduino-fade
arduinounoled
ShareXLinkedInFacebookRedditWhatsApp
B
Mike M
v1.0.0 · UpdatedNov 24, 2026 ·0 downloads ·0 forks
// Fade: analogWrite on pin 9 (a PWM pin) sets the LED's brightness, 0 to 255.

const int LED = 9;
int brightness = 0;
int step = 5;

void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
  analogWrite(LED, brightness);
  brightness = brightness + step;
  if (brightness <= 0 || brightness >= 255) {
    step = -step;
  }
  delay(30);
}
Description

Dim an LED up and down with PWM. It compiles and runs on a virtual Uno in the browser. Change the step from 5 to 1 to fade more slowly.

Cite this design
@design{breadboardhub/arduino-fade,
  title = {Arduino Uno: fade},
  author = {breadboardhub},
  url = {https://www.breadboardhub.com/breadboardhub/arduino-fade},
  version = {1.0.0}
}