This is going to be really simple, It is a kind of Hello World Project for beginners. You might have observed LED which fades in and out when your Mac is sleeping.So we are going to make that cool effect using Arduino.
All you need is Arduino, LED, 220ohm resistor, A Breadboard and some wires.
Connect the Components as I mention in below Breadboard Diagram
Now Upload the following Program to Arduino
const int LED = 9;
int i = 0;
void setup() {
pinMode(LED, OUTPUT);
}
void loop(){
for (i = 0; i < 255; i++) { analogWrite(LED, i); delay(10); } for (i = 255; i > 0; i--)
{
analogWrite(LED, i);
delay(10);
}
}
The catch here is We need to take advantage of Analog output pins of Arduino to linearly Fade in and Fade out the LED,Arduino UNO has six analog pins -pin 3,5,6,9,10 and 11.
The syntax analogue output function
analogWrite(LED,128);
The above function assigns the value 128 to LED, The LED should be assigned with any one of the Analog output pin.
Analog output has a range of 0 to 255, which represents the voltage 0 to 5 volt respectively.Thats is if you give 0 as a output the LED will not be given any voltage and If it is 255(max value) the output will be 5 V.So you can calculate the resolution as 5/1256= 0.0195 V.
Isn’t that so simple ? but I would Like you to extend this project by adding some Other cool features.
Ok next time I will bang up with some complex Arduino Projects.