Blinking LED Project

___________________________

Introduction

LED stands for Light-Emitting Doide and is a special type of doide which shines only if it is connected in forward bias. That is, the long pin of LED is connected to the positive terminal of the power supply and the short pin is connected to negative terminal of the power supply. To prevent the LED from being damaged as a result of excess current, a resistor should be connected in series to the LED in the circuit. Resistors restrict the flow of electricity and the level of restriction depends on the value of the resistor.

The Raspberry pi just like any computer can execute instructions with incredible amount of speed. We can use this ability to switch on and off devices like the LED, creating the blinking effect.


Materials

  1. Aduino Uno
  2. USB-to-serial cable
  3. 470Ω resistor
  4. Two Jumper wires
  5. LED
  6. Breadboard

Procedure

■ Connect the resistor across the middle area of the breadboard

■ Connect the long leg of the LED to the column containing one leg of the resistor and the short leg of the LED to the negative horizontally-link path of the breadboard.

■ Connect the other leg of the resistor to pin 13 of the arduino using a jumper wire

■ Use ther jumper wire to connect the short leg of the LED to the arduino ground GND


Connection for the circuit



Code

■ Create a new file in Arduino IDE, and call your sketch (arduino code) LED.ino or whatever you want.

■ Connect the Arduino to a computer with the USB-to-serial cable.

■ Type in the following code and click the Compile and Upload button on the IDE. Remember to choose the appropriate port (for example, COM6 or COM7) for the Arduino to avoid any errors while uploading.


int led = 13;

void setup() {
  pinMode(led, OUTPUT);
}

void loop() {
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
}

■ If the circuit is wired correctly the LED will be seen blinking indefinitely.



Explaining the code

■ The first part of the sketch defines which Arduino pin is connected to LED.


int led = 13;

■ The second part of the sketch defines the Arduino pin 13 as an output pin and runs once


void setup() {
  pinMode(led, OUTPUT);
}

■ The last part of the sketch runs the instructions within the void loop() function indefinitely. It turns on the LED, wait for 1 second and turns it off continuously.

     
void loop() {
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
}



The video below will show you how to carry out this project