Arduino LED Fading Circuit – Arduino Tutorial

4,606 views

Here in this tutorial, we will learn about fading an LED by using Arduino. The underlying principle of the Arduino LED fading circuit is based on Pulse width Modulation (PWM). This technique provides high or low voltages to the Digital pin from where we can get fading of an led.

Hardware Components

Following are the necessary hardware items required for Arduino fading LED:

S.NOComponentsValueQty
1.Arduino Uno R31
2.USB Cable A/B1
3.Breadboard1
4.Connecting wires1
5. LED5mm1

Working Explanation

Pulse Width Modulation (PWM), is a term used for comparing analog-type behavior with digital signals i.e it provides a digital output (high or low )to the load at a rate defined by the user. As long as the switch is kept on the power is being transmitted to the load. Digital control is best to define by means of the duty cycle. The term used to maintain on and off condition of a signal. In order to get varying values, all you have to do is to set the Duty cycle which ultimately sets the pulse width of the signal and results in controlling the brightness of Led. In this project, Arduino Led fading Arduino is sending PWM signal to Led which results in fading of led.

Circuit Diagram

Arduino Fading LED

Connections

Follow all steps carefully from the video tutorial at the beginning of this post (Highly Recommended).

  • VCC of LED to D9 of Arduino.
  • GND of LED to GND of Arduino.

Application

  • Control the brightness.
  • Control the speed of motors.
  • Identify the interrupts in the processor.

Arduino Code

This example shows how to fade an LED on pin 9 using the analogWrite() function. The analogWrite() function uses PWM, so if you want to change the pin you’re using, be sure to use another PWM capable pin. On most Arduino, the PWM pins are identified with a “~” sign, like ~3, ~5, ~6, ~9, ~10 and ~11. This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Fade */ int led = 9; // the PWM pin the LED is attached to 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, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // set the brightness of pin 9: analogWrite(led, 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 delay(30); }

Download All Important Files for this project from the link given below