Skip to content

4. Blinking LED

Armand Emamdjomeh edited this page Sep 23, 2015 · 15 revisions

Congratulations. We've completed a circuit and turned on a light.

Now, we're going to use the same basic setup to make our LED blink, except we're going to connect it to pin 13 on our Arduino. This pin is special because it can output a digital signal (and power) based on code you write and upload with the IDE.

(IDE is an abbreviation for the fancy term "Integrated Development Environment," and we'll be using these three letters a lot today.)

  1. Remove the red wire from the breadboard and the Arduino
  2. Unplug the wire connecting the LED to the "+" row on your breadboard.
  3. Plug the wire into pin 13 on your Arduino, and keep the other end plugged into the row with the positive end of the LED.

Now, launch the Arduino IDE if you haven't already. Go to file > examples > Basics > Blink. That should open up a new window with this example code:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Click the check mark to compile and validate the code, then click the arrow to upload it to your Arduino. It's alive!

What is the code actually doing?

Setup runs once, at the start of the program. Usually, variables are initialized and values set. In this function, we simply start the Serial object, which is helpful for debugging.

In the loop function, the A0 pin (where we have the light plugged in to) is The delay functions control how rapidly the light blinks, try adjusting them lower or higher and uploading the code again.

Next up: Connecting an Audio Sensor »

Clone this wiki locally