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.

Objective

Prerequisite

  • Basic understanding of LED

Requirement

Following is all materials I use for this tutorial.

  • Arduino Uno R3
  • LED

You can change the Arduino board to higher specification if you like. The LED I use will emit red light as it is powered by electricity.

You also need an USB A to B cable for upload our program to our Arduino.

Circuit

Here is the circuit image, created using Fritzing.

Blinking LED

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.

ExampleCircuit_sch

Code

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

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:

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

and turn it off by:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">