Arduino LED Blink Project : Getting start to IoT Projects

486
Arduino LED Blink Project

Last Updated on

Arduino LED Blink Project:

This example shows the simplest thing you can do with an Arduino to see physical output: it blinks the on-board LED.

 

Hardware Required

  • Arduino Board
  • LED
  • 220 ohm resistor

Arduino LED Blink Circuit 

This example uses the built-in LED that most Arduino boards have. This LED is connected to a digital pin and its number may vary from board type to board type. To make your life easier, we have a constant that is specified in every board descriptor file. This constant is LED_BUILTIN and allows you to control the built-in LED easily. Here is the correspondence between the constant and the digital pin.

 

If you want to light an external LED with this sketch, you need to build this circuit, where you connect one end of the resistor to the digital pin correspondent to the LED_BUILTIN constant.

Connect the long leg of the LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the negative leg, called the cathode) to the GND. In the diagram below we show an UNO board that has D13 as the LED_BUILTIN value.

The value of the resistor in series with the LED may be of a different value than 220 ohm; the LED will lit up also with values up to 1K ohm.

Schematic:

Arduino-LED-Blink-circuit

Image credit: Arduino

Code :

After you build the circuit plug your Arduino or Genuino board into your computer, start the Arduino Software (IDE) and enter the code below. You may also load it from the menu File/Examples/01.Basics/Blink . The first thing you do is to initialize LED_BUILTIN pin as an output pin with the line

pinMode(LED_BUILTIN, OUTPUT);

In the main loop, you turn the LED on with the line:

digitalWrite(LED_BUILTIN, HIGH);

This supplies 5 volts to the LED anode. That creates a voltage difference across the pins of the LED, and lights it up. Then you turn it off with the line:

digitalWrite(LED_BUILTIN, LOW);

That takes the LED_BUILTIN pin back to 0 volts, and turns the LED off. In between the on and the off, you want enough time for a person to see the change, so the delay() commands tell the board to do nothing for 1000 milliseconds, or one second. When you use the delay() command, nothing else happens for that amount of time

 

Arduino LED Blink Program:

/*

Blink

Turns on an LED on for one second, then off for one second, repeatedly.

 

Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO

it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to

the correct LED pin independent of which board is used.

If you want to know what pin the on-board LED is connected to on your Arduino model, check

the Technical Specs of your board  at https://www.arduino.cc/en/Main/Products

 

This example code is in the public domain.

 

modified 8 May 2014

by Scott Fitzgerald

 

modified 2 Sep 2016

by Arturo Guadalupi

 

modified 8 Sep 2016

by Colby Newman

*/

 

 

// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin LED_BUILTIN as an output.

pinMode(LED_BUILTIN, OUTPUT);

}

 

// the loop function runs over and over again forever

void loop() {

digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

delay(1000);                       // wait for a second

digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

delay(1000);                       // wait for a second

}

 

Information and Program credit: www.arduino.cc

 

Recommended next arduino Project : Arduino Base LED bargraph “

LEAVE A REPLY

Please enter your comment!
Please enter your name here