Fading LED with Arduino: A Step-by-Step Guide
LED lights are widely used in electronics projects, and one of the popular effects that can be achieved with LEDs is fading. Fading LED refers to the gradual change in brightness of an LED light over a certain period of time. In this guide, we will show you how to build a fading LED project using an Arduino board and control the brightness of an LED using pulse-width modulation (PWM).
Materials and Tools:
1)Arduino board (e.g. Arduino Uno)
2)LED (Light-Emitting Diode)
3)220-ohm resistor
4)Breadboard
5)Jumper wires
Fading LED can be achieved by controlling the amount of time the LED is on and off over a specific period. Pulse Width Modulation (PWM) is a technique used to control the brightness of an LED by rapidly switching it on and off at a specific frequency. The duty cycle of the PWM signal determines the brightness of the LED, where a duty cycle of 100% means the LED is fully on, and a duty cycle of 0% means the LED is fully off. By adjusting the duty cycle, we can achieve the desired brightness of the LED.
Circuit setup:
To build a fading LED project with Arduino, we need to set up the circuit as shown in the diagram below. Connect one end of the LED to a 220-ohm resistor and the other end of the resistor to digital pin 9 on the Arduino board. Connect the other end of the LED to GND on the Arduino board.
Programming:
To control the brightness of the LED, we need to write the code in the Arduino programming language (C++). The code below will gradually increase the brightness of the LED and then decrease it repeatedly.
void setup()
{
pinMode(9, OUTPUT); //Setting PinMode As output
}
void loop()
{
for(int i = 0; i <= 255; i++) //Turning LED On With PWM
{
analogWrite(9, i);
delay(10);
}
for(int i = 255; i >= 0; i--) //Turning LED OFF With PWM
{
analogWrite(9, i);
delay(10);
}
}
Testing and demonstration:
Once the code is uploaded to the Arduino board, the fading LED should start to work. You should see the LED gradually increasing and decreasing in brightness. If everything is working as expected, you can further modify the code to achieve different fading effects.
Conclusion:
In this guide, we have shown you how to build a fading LED project with Arduino. By controlling the duty cycle of a PWM signal, we can achieve the desired brightness of an LED. This project is simple and fun to build, and can be used as a starting point for more advanced projects.
Reference and further reading:
What Is Electronics: Interactive Presentation
Pulse Width Modulation (PWM) tutorial
I hope this guide has helped you learn more about fading LED with Arduino. Happy building!