The Blink Sketch

Blink!

In this tutorial we will see what the blink example sketch is, and how useful it can actually be. We will also see how to personalize it so that you can be sure it was your sketch that loaded into the Arduino. To do this tutorial, all you need is your Arduino, or Arduino clone, or other compatible board and the example program.

What does it do?

The blink sketch blinks the LED on pin 13. That's all it does - nothing more.

What use is that..?

More useful than about any other program. The first thing you do at any sign of trouble with programming, or running a program, is upload the blink sketch to prove that the process works. It tests your IDE, compiler, uploader, cables, and of course, the Arduino. If you can't upload the blink sketch, and see it blinking your LED, you can't upload anything and get it to work.

int LED = 13;

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(LED, OUTPUT);
}
void loop() {
  digitalWrite(LED, HIGH);   // turn the LED on
  delay(1000);               // wait for one second
  digitalWrite(LED, LOW);    // turn the LED off
  delay(1000);               // wait for one second
}
    

How it works.

The program first sets the LED pin, usually pin 13, to output. Then it enters the loop, forever turning the LED on, sleeping for 1000 milliseconds (1 second), tuning the LED off and sleeping again. It is very simple. If you successfully upload this code to the Arduino the LED will blink, assuming nothing is interfering with pin 13. If it doesn't blink, it is time to look at the error messages in the IDE.

Why personalize it?

Many Arduino clones ship with the blink sketch already burned into them. If it is already blinking, and you upload the blink sketch, and it is still blinking, how do you know it is your blink sketch? Because you have modified yours!

To personalize it, you just need to change the blink from the default, so you can recognize it. One way to do that is to change it to blink twice each time it comes on. To do that, change the code as seen below.

int LED = 13;

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(LED, OUTPUT);
}
void loop() {
  digitalWrite(LED, HIGH);   // turn the LED on
  delay(333);                // wait for one third second
  digitalWrite(LED, LOW);    // turn the LED off
  delay(333);                // wait for one third second
  digitalWrite(LED, HIGH);   // turn the LED on
  delay(333);                // wait for one third second
  digitalWrite(LED, LOW);    // turn the LED off
  delay(1000);               // wait for one second
}
    

The light will blink twice, then stay dark for one second, repeating forever. You can change the routine to just blink either faster or slower by changing the "delay(1000)" to another value. Remember there are 1000 counts per second.

Now when you upload the blink sketch you can be sure it is your code running on the Arduino!

Notes:

On most modern Arduinos the LED is on pin 13. Some clones have the LED on other pins, and some earlier models, such as the NG, had no LED at all.

If your Arduino does not have an LED on pin 13, you can add one externally by soldering a 1kΩ resistor to the anode (long lead) of an LED, and plugging the resistor into pin 13 and the other LED lead into the "GND" pin next to it.

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.