BSEE 3E - Laboratory - Act#1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

TECHNOLOGICAL UNIVERSITY OF THE

PHILIPPINES
Ayala Blvd. Ermita, Manila, 1000, Philippines
College of Engineering
Electrical Engineering Department

Laboratory Activity 1
ACEE12L-M : Microprocessor System Lab

Submitted by:
BSEE 3E-M

Esteron, Marvin Q.

Submitted to:

Engr. Donnie L. Berog


Software
Installation

1. Download the software and install by following the step-by-step


directions at: http://arduino.cc/en/Main/Software

1. Software programs, called sketches are created


using the Arduino IDE.
2. The IDE enables one to create, open, change sketches,
convert these codes into instructions for the Arduino
Hardware to understand.
3. The IDE also uploads/transfers the converted codes into the Arduino
Hardware (via USB cable).
The Integrated Development Environment
(IDE)

1. Compile – converts the program


codes/sketches into instructions that the board understands.

2. Stop - stops the compilation process.

3. Create new Sketch - opens a new window to create a new sketch.

4. Open Existing Sketch - loads a sketch from a file

5. Save Sketch - saves the changes to the sketch

6. Upload to Board - compiles and transmits sketches to board via USB


cable

7. Tab Button – enables one to create multiple files in your sketch.

8. Sketch Editor - write or edit sketches

9. Text Console – shows the IDE status (and displays syntax errors)

10. Line Number – points the line number where syntax error occurred
after compiling.
Setting Up the Arduino Board

Board Set-Up
To power up the board and verify if it is working,
plug in the board to a computer via USB cable and
check if:

• LED power indicator illuminates (green)


• Pin 13 LED flashes ON and OFF
Exercise 5: Basic Circuit 1

 The purpose of basic circuit1 is to demo how to


access power from the board:

1. With a wire, connect 5V power and ground


from the Arduino to
the bread board (see figure above)
2. Apply the established 5V supply to an LED
(use limiting resistor)
3. Plug power into the Arduino (via USB to
computer/battery/PS)
4. The LED should light up. If it doesn’t,
unplug power ,check
connections and try again
Exercise 2: Basic Circuit 2
 The purpose of the basic circuit2 is to demo how
Arduino will be controlling
the LED

1. Modify Basic Circuit 1 by taking the


wire from h3 and connect it to pin 13
of the Arduino. (the default output
pin of a new Arduino board)
2. Write a program to control the LED. Each
program must contain at
least two functions.
Exercise 2: Basic Circuit 2

1. List the codes below in the sketch editor

delays in
milliseconds

Notes on Program Codes


 Codes are case sensitive

 Spaces, tabs, blank lines are collapsed as a single space


 Blocks of code are encapsulated with curly braces ’{’ and ’}’
 Every open parenthesis ’(’ must be closed
by
’)’
 No commas in numbers.
 Each executable program statement must end with a semicolon ’;’.
Exercise 2: Basic Circuit 2

Comments
Additional comments can be used to
dissect the parts of the program codes.
These are ignored by the IDE during
compilation but are useful for the users.
Two forms of comments:
 block comment – enclosed by / * (comments
here!) * /

 single line comment – starts with a //


Activity
1. Change the amount of time the LED is off to 1 second.
(Leaving the amount of time the LED is on at ½ second.)
2. Change the pin to which the LED is connected from pin 13
to pin 2 (Note that both the circuit AND the program must
be changed.)
3. Hook up 8 LEDs to pins 2 through 9 (with limiting resistors)
Modify the code to turn on and off each one in
order.(note: hook them up one additional LED at a time
and make sure the new one works before you add the next
one)
4. Modify no. 3 and use 12 LEDs instead, make them turn on
and off in a pattern similar to a Christmas light- be
creative!

Include comments in your program codes to explain/dissect the


overall program. Have your work checked by your lab
professor…..

// the led will turn on for .5 seconds and turns off with .5
sec delay
Activity 1.1

// C++ code
//
const int Led13_Red = 13;

void setup()
{
pinMode(Led13_Red, OUTPUT);
}
void loop()
{
digitalWrite(Led13_Red, HIGH);
delay(1500);// Wait for 1500 millisecond(s)
digitalWrite(Led13_Red, LOW);
delay(1000);// Wait for 1000 millisecond(s)
}
Activity 1.2

// C++ code
//
const int Led1_Green = 2;

void setup()
{
pinMode(Led1_Green, OUTPUT);
}
void loop()
{
digitalWrite(Led1_Green, HIGH);
delay(600);// Wait for 600 millisecond(s)
digitalWrite(Led1_Green, LOW);
delay(800);// Wait for 800 millisecond(s)

}
Activity 1.3

// C++ code
//
const int Led1_Green = 2;
const int Led2_Red = 3;
const int Led3_Blue = 4;
const int Led4_Orange = 5;
const int Led5_Yellow = 6;
const int Led6_Green = 7;
const int Led7_Red = 8;
const int Led8_Blue = 9;

void setup()
{
pinMode(Led1_Green, OUTPUT);
pinMode(Led2_Red, OUTPUT);
pinMode(Led3_Blue, OUTPUT);
pinMode(Led4_Orange, OUTPUT);
pinMode(Led5_Yellow, OUTPUT);
pinMode(Led6_Green, OUTPUT);
pinMode(Led7_Red, OUTPUT);
pinMode(Led8_Blue, OUTPUT);

void loop()
{
//All delay 1 second
//turn pin Led1_Green HIGH
digitalWrite(Led1_Green, HIGH);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
delay(1300);// Wait for 1300 millisecond(s)

//turn pin Led2_Red HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, HIGH);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)

//turn pin Led3_Blue HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, HIGH);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)

//turn pin Led4_Orange HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, HIGH);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)

//turn pin Led5_Yellow HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, HIGH);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)

//turn pin Led6_Green HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, HIGH);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)
//turn pin Led7_Red HIGH
digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, HIGH);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)

//turn pin Led8_Blue HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, HIGH);
delay(1300);// Wait for 1300 millisecond(s)

//All_LOW and delay 1 second


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
delay(1300);// Wait for 1300 millisecond(s)

}
Activity 1.4

// C++ code
//
const int Led1_Green = 2;
const int Led2_Red = 3;
const int Led3_Blue = 4;
const int Led4_Orange = 5;
const int Led5_Yellow = 6;
const int Led6_Green = 7;
const int Led7_Red = 8;
const int Led8_Blue = 9;
const int Led9_Orange = 10;
const int Led10_Yellow = 11;
const int Led11_Green = 12;
const int Led12_Red = 13;

void setup()
{
pinMode(Led1_Green, OUTPUT);
pinMode(Led2_Red, OUTPUT);
pinMode(Led3_Blue, OUTPUT);
pinMode(Led4_Orange, OUTPUT);
pinMode(Led5_Yellow, OUTPUT);
pinMode(Led6_Green, OUTPUT);
pinMode(Led7_Red, OUTPUT);
pinMode(Led8_Blue, OUTPUT);
pinMode(Led9_Orange, OUTPUT);
pinMode(Led10_Yellow, OUTPUT);
pinMode(Led11_Green, OUTPUT);
pinMode(Led12_Red, OUTPUT);

void loop()
{
//the led will light one after the other
//All delay 0.3 second
//turn pin Led1_Green HIGH and LOW
digitalWrite(Led1_Green, HIGH);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led2_Red HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, HIGH);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led3_Blue HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, HIGH);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led4_Orange HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, HIGH);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led5_Yellow HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, HIGH);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led6_Green HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, HIGH);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led7_Red HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, HIGH);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led8_Blue HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, HIGH);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led9_Orange HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, HIGH);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led10_Yellow HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, HIGH);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led11_Green HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, HIGH);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led12_Red HIGH and LOW


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, HIGH);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led1_Green and Led2_Red HIGH


digitalWrite(Led1_Green, HIGH);
digitalWrite(Led2_Red, HIGH);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//two led will ligth up at the same time


//turn pin Led3_Blue, HIGH and Led4_Orange HIGH
digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, HIGH);
digitalWrite(Led4_Orange, HIGH);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led5_Yellow, HIGH and Led6_Green, HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, HIGH);
digitalWrite(Led6_Green, HIGH);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led7_Red, HIGH and Led8_Blue, HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, HIGH);
digitalWrite(Led8_Blue, HIGH);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)
//turn pin Led9_Orange, HIGH and Led10_Yellow, HIGH
digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, HIGH);
digitalWrite(Led10_Yellow, HIGH);
digitalWrite(Led11_Green, LOW);
digitalWrite(Led12_Red, LOW);
delay(300);// Wait for 300 millisecond(s)

//turn pin Led11_Green, HIGH and Led12_Red, HIGH


digitalWrite(Led1_Green, LOW);
digitalWrite(Led2_Red, LOW);
digitalWrite(Led3_Blue, LOW);
digitalWrite(Led4_Orange, LOW);
digitalWrite(Led5_Yellow, LOW);
digitalWrite(Led6_Green, LOW);
digitalWrite(Led7_Red, LOW);
digitalWrite(Led8_Blue, LOW);
digitalWrite(Led9_Orange, LOW);
digitalWrite(Led10_Yellow, LOW);
digitalWrite(Led11_Green, HIGH);
digitalWrite(Led12_Red, HIGH);
delay(300);// Wait for 300 millisecond(s)

}
Observation:

In Tinkercad, you can simulate a blinking LED using the built-in simulation
feature. In creating a blinking effect on the LED you will simply adjust the delay
time in the program so that you can slowdown or speed up the blinking effect of
the LED and by observing the LED in the simulation, you can confirm that the code
is working properly and that the LED is blinking according to the program.

Conclusion:

In conclusion, an experiment using blinking lights can be used as a teaching


tool to help students understand basic electrical circuits and how they can be used
to control an LED light's behavior. As part of the design process for new products
or projects, it can also be used to determine the best way to use LEDs to provide a
certain visual impact. The purpose of an experiment with blinking lights can change
depending on the environment and objectives, but in general, it is intended to look
into the characteristics of light and how electrical circuits can be used to regulate
and modify it.
References

Arduino CookBook
Recipes to Begin, Expand, and Enhance
Your Projects

By Michael Margolis

Introduction to Arduino
By Alan G. Smith

Arduino online Courses


Windows installations

You might also like