You are on page 1of 7

CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

Lab 1
BLINKING LEDs

INTRODUCTION
The first program every programmer learns consists in writing enough code to make their code
show the sentence “Hello World!” on screen. The blinking LED is the “Hello World!” of physical computing.
A LED is a small light (it stands for “light emitting diode”) that works with relatively liitle power.
The Arduino board has one built-in on digital pin 13 that turns ON when the pin is set HIGH and turns OFF
when it is LOW. Its LED already blinks when connected to a USB plug. This is because Arduino boards are
generally shipped with the 'Blink' sketch pre-installed. LEDs are powerful lights that are used in many
different applications. LEDs are mostly used for two things: illumination and indication.
This activity will help us to power up Arduino and examine how each LED is lit differently. LEDs
have polarity, which means they will only light up if the legs are properly oriented. To make this project
possible, the students should make sure that the materials to be used are available.

OBJECTIVES

1. To execute blinking LEDs using Arduino IDE and the corresponding board
2. To know the importance of resistors in a circuit
3. To light up to ten LEDs
4. To familiarize the codes for blinking LED

MATERIALS

1 Arduino UNO board with USB cable


10 LEDs (red)
10 Resistors (270Ω)
11 Jumper wires (black, blue, white, red)
1 long breadboard
1 laptop

PROCEDURES

1. Insert the 10 LEDs.

Note: LEDs are polarized. The shorter of the two legs indicates the negative terminal while
the other leg is positive.
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

2. Connect the 270-ohm resistors below the cathode pins of the 10 LEDs.
The breadboard has signs for positive (power) and negative (ground) connections. Place
the resistors on the breadboard, with one leg on the negative column (gnd) of the breadboard
and the other leg in a different hole located somewhere else on the breadboard as shown in
the diagram below.

3. Connect the 10 jumper wires (white,blue,red) to the anode pins of the LEDs.
4. Plug in the 10 jumper wires to the Arduino UNO board in digital I/O pin number
2,3,4,5,6,7,8,9,10 and 11.
5. Connect a black jumper wire from GND to the negative rail on the breadboard.

Blinking LEDs circuit diagram

6. Open up the Arduino IDE.


7. Program the Arduino UNO.
Encode or copy then edit the code for this section.

8. Plug the Arduino UNO board into the laptop with a USB cable.
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

9. Upload onto board.


Make sure the serial port is set. In this case, COM4 and the correct board is selected, that
is Arduino UNO is selected from the dropdown menu at the top left corner of the Arduino
application. Then upload the code unto the board by clicking upload at the top left corner.
10. Monitor the Arduino board and the circuit. The LEDs should be blinking.

RESULTS and DISCUSSION

Here is an example of the code of blinking LED:

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

void loop()
{
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
}

To light up 10 LEDs, make sure every LED is connected to every pin on the Arduino board. In the
software, just add 9 more LED numbers in the definition. Then, edit the code to command the Arduino.

Here is the code of blinking LEDs that we encode in the sketch:


void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

void loop()
{
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(5,0);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,1);
digitalWrite(9,0);
digitalWrite(10,1);
digitalWrite(11,0);
delay(1000);
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(5,1);
digitalWrite(6,0);
digitalWrite(7,1);
digitalWrite(8,0);
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,1);
delay(1000);
digitalWrite(11,0);
delay(100);
digitalWrite(10,1);
delay(200);
digitalWrite(9,0);
delay(100);
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

digitalWrite(8,1);
delay(200);
digitalWrite(7,0);
delay(100);
digitalWrite(6,1);
delay(200);
digitalWrite(5,0);
delay(100);
digitalWrite(4,1);
delay(200);
digitalWrite(3,0);
delay(100);
digitalWrite(2,1);
delay(200);
digitalWrite(2,0);
delay(100);
digitalWrite(3,1);
delay(200);
digitalWrite(4,0);
delay(100);
digitalWrite(5,1);
delay(200);
digitalWrite(6,0);
delay(100);
digitalWrite(7,1);
delay(200);
digitalWrite(8,0);
delay(100);
digitalWrite(9,1);
delay(200);
digitalWrite(10,0);
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

delay(100);
digitalWrite(11,1);
delay(200);

The key to blink an LED lies in changing the parameter in () for the 'delay' command to turn it on
for a second and off for one second, repeatedly.

Connecting the board and LEDs to pin 11 to pin 2 chronologically of the Arduino
including the ground.
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

Uploading the sketch and monitoring the output.

REFERENCES

https://www.arduino.cc/en/Tutorial/Blink
http://www.instructables.com/id/Arduino-Tutorial-Flicker-a-LED/?ALLSTEPS

You might also like