The Arduino Microcontroller: Part Two

Part 2: Blinky Light!

Okay, now we're going to make this Arduino thing do something. Naturally, the first thing one is supposed to do with a microcontroller is make an LED blink (cause just making it turn on isn't that fun).

For part 2 you'll need the following;

For our first excursion into blinky lights, fire up the Arduino IDE. It should look something like this:

Arduino IDE

Got that? Good. Make sure the correct board and serial port are selected in the Tools menu. Hit File->New to create a new, blank sketch. Then type or copy/paste the following into the large text area.


// blink onboard LED
int ledPin = 13;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}


In this sketch we set the variable "ledPin" to reference I/O pin number 13. The "setup()" routine is required in Arduino programming, and is used for various initialization procedures. In this case we set "ledPin" (pin 13) to be an Output pin (provide signal, not read it). The "loop()" is where things happen in Arduino, and will be run every cycle of the microcontroller, in a loop (hence it's name). Here we set ledPin to HIGH (turn it on), wait a second (delay(microseconds)), set ledPin LOW (turn it off), and wait another second. Then the cycle starts over again, until power is lost.

Now click "Sketch->Verify/Compile", or click the compile button in the IDE.

IDE Compile button

After it has finished compiling, click "File->Upload to I/O Board", or hit the Upload button in the IDE.

IDE Upload button

Once the TX/RX lights on your Arduino quit flashing your sketch is finished uploading. Wait a second or two, and... BAM! One of the surface mount LEDs is flashing on and off, every second.

Wow. A blinking light. Thanks a lot Rudolph.

That was so entertaining I'm not even going to supply a video. So where does that leave us? Part Three: More Blinky Lights!