Feb 122011
 

One of the first and simplest sketches to run on your Arduino is to make an LED blink. If this is your first time using Arduino, read through our “Arduino basics: getting started” article.

Connecting the Arduino and LED

Connect your Arduino to your computer using a USB cable. The power light should come on.

1) Place your LED and a 470 ohm resistor in series (a breadboard will help). Always use resistors with LEDs for safety purposes, and remember that the LED cathode points toward Ground.

2) Connect jumper wires to pins 13 and Gnd on the digital side of the Arduino

3) Open the arduino IDE and type in the following code:

void setup() {
    pinMode(13, OUTPUT);
}
void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

4) Press the upload button in the IDE to send the code to your Arduino. It should automatically start running it!

Video of the LED blinker in action

(includes code explanation):

.

Modify the LED blink sketch:

  • You can change the blink rate by changing the delay!
  • You may have also noticed a little yellow LED on the board that blinks in time with your LED. That little LED is wired to pin 13 and is used for testing purposes. If you want to avoid it, use a different pin (such as pin 12). But remember to modify the code (see below)
void setup() {
    pinMode(12, OUTPUT);
}
void loop() {
  digitalWrite(12, HIGH);
  delay(500);
  digitalWrite(12, LOW);
  delay(500);
}

The above code is modified to use pin 12 (instead of pin 13) and to only delay for 500 ms. Try your own variations!