Arduino – LED – Fade – Tutorial


Arduino – LED – Fade – Tutorial is an intriguing project that demonstrates how to control the brightness of an LED, creating a gradual and smooth transition between light and dark. This effect, often referred to as LED fading, can be used in various applications, including mood lighting, visual effects, and more.

Hardware Required

1×Arduino UNO
1×USB 2.0 cable type A/B
1×220 ohm resistor
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino
1×(Optional) Screw Terminal Block Shield for Arduino Uno
1×DIYables Sensor Kit 30 types, 69 units

What is Arduino – LED – Fade?

Arduino – LED – Fade – Tutorial is a project that showcases the capability of Arduino to control the intensity of an LED’s illumination smoothly. Instead of simply turning the LED on and off, this project allows you to achieve a gradual and aesthetically pleasing transition between different brightness levels.

How it Works

The LED fading effect is achieved through Pulse Width Modulation (PWM). PWM allows us to control the average voltage delivered to the LED by rapidly turning it on and off. By varying the duty cycle (the time the LED is on versus off), we can create the illusion of varying brightness levels. This code gradually increases and decreases the LED’s brightness in a loop, resulting in the fading effect.

Circuit Diagram

LED - Fade - Arduino Tutorial

Features of Arduino LED Fade

  1. Smooth Transition: Achieve graceful and gradual light intensity transitions.
  2. Customizable Fading Speed: Adjust the speed at which the LED fades in and out.
  3. Public Domain Code: The example code provided is available in the public domain, fostering learning and adaptation.
  4. Creative Lighting Effects: Ideal for creating ambiance or visual effects in various projects.
  5. Efficient Power Management: Enables energy-efficient illumination control.
  6. Simple Hardware Setup: Requires minimal components, making it accessible for beginners.


#define LED_PIN 9  // the Arduino PWM pin connected to the LED

int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(LED_PIN, OUTPUT);

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(LED_PIN, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  // wait for 30 milliseconds to see the dimming effect

How to Program

  1. Set up the Arduino UNO and connect the components according to the hardware requirements.
  2. Open the Arduino IDE on your computer.
  3. Copy and paste the provided code into the IDE.
  4. Upload the code to the Arduino UNO board.
  5. Observe the LED connected to pin 9 smoothly fading in and out, creating a captivating effect.

Application of Arduino LED Fade

  1. Mood Lighting: Create soothing or dynamic lighting effects for room ambiance.
  2. Visual Displays: Implement in visual displays, art installations, or interactive exhibits.
  3. Dimmable Indicator Lights: Use for status or feedback indicators with adjustable brightness.
  4. Fade-In/Fade-Out Alerts: Employ in notification systems for subtle alerts.
  5. Energy-Efficient Lighting: Control LED brightness in low-power applications to save energy.
  6. Simulation and Prototyping: Simulate natural light changes in prototypes or models.

Leave a Comment

six + five =