Arduino Project: Simple Blinking LED

Blink LED, like what it should be, we make certain LED blinking. We can define “blinking” as continuous condition switching between ON and OFF condition. This is the simplest project we can do for Arduino.

Circuit

To build the circuit, attach the LED as shown in the figure. Attach the long leg of an LED (positive leg or anode) to pin 13. Attach the short leg (negative leg or cathode) to the ground (GND). On Arduino Uno, there is also a built in status LED which connected to pin 13. When our Arduino running successfully, both status LED and external LED will start to blink.

We don’t need extra resistor for this project, but make sure you are using pin 13. If you do connect it to other pin, it might be destroyed. The reason is that pin 13 has an internal resistor that other pins don’t have which limit current to our LED.

Code

Let’s see what code we use for this project and discuss it later.

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

constunsignedintLED_PIN=13;

constunsignedintPAUSE=500;

voidsetup(){

pinMode(LED_PIN,OUTPUT);

}

voidloop(){

digitalWrite(LED_PIN,HIGH);

delay(PAUSE);

digitalWrite(LED_PIN,LOW);

delay(PAUSE);

}

Notice that we define two constant here, LED_PIN which is pin we use, and PAUSE for the delay interval which is 500 ms.

The heart of this project is pin 13. We use this pin as output pin. Therefore we initialize pin 13 as an output pin with the statement:

Arduino

1

pinMode(LED_PIN,OUTPUT);

Next in the main loop, we turn the LED on by:

Arduino

1

digitalWrite(LED_PIN,HIGH);

and turn it off by:

Arduino

1

digitalWrite(LED_PIN,LOW);

And we now know that digitalWrite() function is used to output signal on a pin.

The delay() command is used to tell Arduino to do nothing for given time. In our case, we make Arduino wait for 500 miliseconds.

Result

LED is blinking.

Why it Works

There are two condition of logic in circuit, HIGH and LOW. Some microcontrollers might define HIGH and LOW difference, but in Arduino Uno we have HIGH logic as 5V and LOW logic as 0V. If you know boolean value, yes this is boolean value with HIGH is true and LOW is false.

The LED we use is active-high LED, which means it can turn on when it is given HIGH voltage.