Enough blinking! NOW FADE YOUR LED’s. :D

This project is a follow up to the basic blinking tutorials that i had earlier posted.
Here I will fade the LED’s connected to the breadboard.
This project requires you to already have basic breadboarding skills.

HARDWARE REQUIRED :-

Arduino Uno

Breadboard

jumper wires

330 ohm resistors

LED’s

How your Code should look. :-

How your circuit should look like :-

The explanation of the code is given along with the code.

It is highly recommended that you try the previous projects on LED’s and then get your hands on this one.

What you can variate here?

I built this program for a single LED. I will suggest you to build this for two or three LED’s at a time all you will be needing is some more jumper wires, a couple of resistors, LED’s and a little variation to the code mentioned above.

For three LED’s the code will look like something like this :-

int led = 9
int led1 = 10
int led2 = 11;
int brightness = 0; //how bright the led is actually at the beginning
int fadeAmount = 5; //how many point to fade the led by
//the setup routine runs once you press the reset
void setup() {
//declare the pins to be output
pinMode(led, OUTPUT);
pinMode(led1,OUTPUT);
pinMode(led2, OUTPUT);

}

void loop() {
//set the brightness of pins
analogWrite(led,brightness);
analogWrite(led1,brightness);
analogWrite(led2,brightness);
//change brightness for next time through the loop
brightness = brightness + fadeAmount;
//reverse direction of fading at the end of the fade
if(brightness==0 || brightness==255)
{
fadeAmount = -fadeAmount;
}
delay(100);

}

Please note the connection made in the circuit is simple and same as what we did in the blink program.