Saturday, February 4, 2012

Arduino - Blinking LED

I have been playing with the arduino and followed simple steps to come up with my first blinking LED program. This is a simple example of blinking LED using Arduino. It is like first code example "Hello World" for beginners. We can also use the in-built small LED on the board itself for this experiment.



Hardware:

Arudino Duemilanove
2 pin LED
USB Power cord

Language:
Arduino programming language (based on Wiring) 

Environment:
Processing

How it works: 
As soon as you compile the codes with connected power cord and the LED will start blinking continuously.

Source Code:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain.
*/

void setup() { // initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);

}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

Port:
Attach the long leg of an 2 pin LED (the positive leg, called the anode) to the "resistor" (to prevent blowing off LED). Attach the short leg (the negative leg, called the cathode) to ground.


Enjoy :)