Fading led using Arduino Uno

Fade LED aruino uno
Share this blog with others!

Hello everyone, welcome to my new blog which is our Second project #2 (Fading LED Using Arduino UNO ). In this blog, we are going to make fading of the LED Using Arduino Uno. Let’s puts some LED and Resistor to work.

In this project, we will use the Red LED and one resistor to make our project perfect.

 

Differing LED brightness with modulation of pulse-width

Instead of turning LEDs turn on and off using digitalWrite, we can determine the brightness level of the LED by adjusting pulse width modulation to time between each LED turning on and off. Before going to our project(Fading Led Using Arduino Uno), first, know what is (PWM) Pulse Width Modulation signal is a process used by digital sources to produce an analog signal. A PWM signal is made up of two key components specifying its behavior: a duty cycle and a frequency.

25% Duty Cycle
25% Duty Cycle
source:https://knowledge.ni.com
50% Duty Cycle
50% Duty Cycle
source:https://knowledge.ni.com
75% Duty Cycle
75% Duty Cycle
source: knowledge.ni.com

Fading Led Using Arduino Uno Algorithm

Before starting to write the algorithm of our project first know what is an algorithm. The algorithm is a step-by-step method, which specifies a series of instructions to be executed to get the desired output in a certain order. 

Algorithms are usually generated independently of the underlying languages, i.e. in more than one programming language, an algorithm may be implemented.

So, start writing the algorithm of our project . Before going onto the algorithm part you should have a clear understanding of what is an Arduino UNO and basics parts.

  • Turn on LED 1
  • Wait for a second.
  • Start Fading from (0-225)
  • Turn off LED 1
  • Wait for a second
  • Repeat indefinitely.

Required Components For Fading Led Using Arduino Uno

  1. 1 LED
  2. 1 Resistor
  3. Wires
  4. Arduino
  5. USB Cable

Arduino Code For Fading Led

// Project 3 - Demonstrating PWM
int d = 3;
void setup()
{
 pinMode(3, OUTPUT); // LED control pin is 3, a PWM capable pin
}
void loop()
{
 for ( int a = 0 ; a < 256 ; a++ )
 {
 analogWrite(3, a);
 delay(d);
 }

 for ( int a = 255 ; a >= 0 ; a-- )
 {
 analogWrite(3, a);
 delay(d);
 }
 delay(1000);
}

In void setup() at the digital, I/O pins are set to outputs because we want them to send current to the LED on demand. We specify when to turn LEDs using the digitalWrite() function in the void loop() section of the sketch.

Use Variables

In a computer program, data is stored using variables. For instance, in Project ( Fading Led Using Arduino Uno)   we used the delay(1000) feature to hold the LED Turns on and use the d variable for hold the full function for a second.

Fading LED Using Arduino Uno
fig 1. Fading LED Using Arduino Uno

Now let’s build the circuit. A circuit layout can be described in several ways. For this project ( Fading LED Using Arduino Uno ), we are using a physical layout diagram similar to the one shown in the above figure 1.

By comparing the wiring diagram with the sketched functions, You should start making sense of the circuit. When we use for example analogWrite(3, a), a 5 V high-voltage PWM pin, 3 flows through, The current-limiting resistor, the anode through the LED, and then the anode Cathode, and finally back to the GND socket in Arduino to complete the circuit. Then by using analogWrite(3, a) the current stops and the LED turns off.

Working Explanation Of Fading Led Using Arduino Uno

Attach your Arduino now, and upload your sketch from the Arduino IDE. After a second the LED should start glowing.

However, if nothing happens then remove the USB cable immediately From Arduino and verify that the sketch has been typed correctly. 
Fix a mistake, and upload the sketch again If your sketch matches exactly and the LED still doesn’t glow check your wiring on the breadboard. If you wanted to modify this sketch to make the LEDs cycle more quickly, you would need to blink after each delay(500).

The LED on digital pin 3 shows a “breathing effect” like the  Cycle of duty rises and decreases. That is, the LED will turn on, 

Increase in luminosity until fully illuminated, and then reverse. 

There is a better way.if you want to see the stimulation of the project. Click here https://www.tinkercad.com/things/iJ9UXLmDyYM.


Share this blog with others!

Leave a Comment

Your email address will not be published. Required fields are marked *