0% found this document useful (0 votes)
13 views12 pages

MES Lab 2 - Abir

The lab report details Experiment #03 conducted at American International University-Bangladesh, focusing on familiarization with Arduino microcontroller timers, LED blink tests, and a simple traffic control system using Timer0. The objectives include understanding Arduino timers, implementing LED blinking, and creating a traffic light system, supported by hardware and simulation results. The report concludes with a discussion on the advantages of using timers over delay functions in microcontroller programming.

Uploaded by

Abir Rahman999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

MES Lab 2 - Abir

The lab report details Experiment #03 conducted at American International University-Bangladesh, focusing on familiarization with Arduino microcontroller timers, LED blink tests, and a simple traffic control system using Timer0. The objectives include understanding Arduino timers, implementing LED blinking, and creating a traffic light system, supported by hardware and simulation results. The report concludes with a discussion on the advantages of using timers over delay functions in microcontroller programming.

Uploaded by

Abir Rahman999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH

Faculty of Engineering

Lab Report
Experiment # 03
Experiment Title: Familiarization with the Timers of an Arduino Microcontroller
Board, the study of LED blink test, and implementation of a simple traffic control
system using its Timer0 function.
Date of Perform: 03 March 2025 Date of Submission: 18 March 2025
Course Title: MICROPROCESSOR AND EMBEDDED SYSTEMS LAB
Course Code: EEE 4318 Section: I
Semester: Spring 2024-25 Degree Program: BSc in EEE
Course Teacher: Dr. Md. Rukonuzzaman
Declaration and Statement of Authorship:
1. I/we hold a copy of this Assignment/Case Study, which can be produced if the original is lost/damaged.
2. This Assignment/Case Study is my/our original work and no part of it has been copied from any other student’s work or from any other source except
where due acknowledgment is made.
3. No part of this Assignment/Case Study has been written for me/us by any other person except where such collaboration has been authorized.
by the concerned teacher and is acknowledged in the assignment.
4. I/we have not previously submitted or currently submitting this work for any other course/unit.
5. This work may be reproduced, communicated, compared, and archived to detect plagiarism.
6. I/we permit a copy of my/our marked work to be retained by the Faculty Member for review by any internal/external examiners.
7. I/we understand that Plagiarism is the presentation of the work, idea, or creation of another person as though it is your own. It is a form of cheating and is a
very serious academic offense that may lead to expulsion from the University. Plagiarized material can be drawn from, and presented in, written, graphic, and
visual forms, including electronic data, and oral presentations. Plagiarism occurs when the origin of the source is not appropriately cited.
8. I/we also understand that enabling plagiarism is the act of assisting or allowing another person to plagiarize or copy my/our work.

* Student(s) must complete all details except the faculty use part.
** Please submit all assignments to your course teacher or the office of the concerned teacher.

Group # 07

Sl No Name ID PROGRAM SIGNATURE


1 Md. Abidur Rahman Bhuiyan 21-45575-5 BSc in EEE
2 Fahim Faysal 21-45558-3 BSc in EEE
3 Ritom Saha 21-45560-3 BSc in EEE
4 BSc in EEE
5 BSc in EEE
6

Faculty use only


FACULTY COMMENTS
Marks Obtained

Total Marks

1
Table of Contents

Experiment Title 3
Objectives 3
Equipment List 3
Circuit Diagram 4
Code/Program 5
Hardware Output Results 6
Experimental Output Results 7
Simulation Output Results 8
Answers to the Questions in the Lab Manual 9
Discussion 12
References 12

2
Experiment Title: Familiarization with the Timers of an Arduino Microcontroller Board, the study of
LED blink test, and implementation of a simple traffic control system using its Timer0 function.

Objectives:
The objectives of this experiment are to-
1. Familiarize with the Arduino microcontroller
2. Familiarize with Timers in Arduino microcontroller
3. Implement Timer0 function in the programing
4. Implement a simple circuit to make an LED light blink using the Timer0 function
5. Implement a simple traffic control system using the Timer0 function

Equipment List:
1. Arduino IDE (2.0.1 or any recent version)
2. Arduino Microcontroller board
3. LED lights (Red, Green, and Yellow)
4. Three 100 resistors
5. Jumper wires

Circuit Diagram:
The Arduino platform is made up of the following components.

Fig. 1 Experimental Setup of Blink Test using an Arduino Microcontroller Board

3
Fig. 2 Experimental Setup of a Traffic Control System using an Arduino Microcontroller Board

Code/Program:
The following is the code for the implementation of the LED blink test with the necessary code
explanation:

// Pin numbers are defined by the corresponding LED colors


#define RED_PIN 10
// The delay amounts are declared in ms; 5 s = 1000 ms
int red_on = 2000;
// Declaring the timer function to count 5 ms of delay instead of calling the
delay function
int delay_timer (int milliseconds){
int count = 0;
while(1)
{
if(TCNT0 >= 16) // Checking if 1 millisecond has passed
{
TCNT0=0;
count++;
if (count == milliseconds) //checking if required milliseconds delay has
passed
{
count=0;
break; // exits the loop
}
}
}
return 0;
}
void setup() {
//define pins connected to LEDs as outputs

4
pinMode(RED_PIN, OUTPUT);
//set up the timer using timer registers
TCCR0A = 0b00000000;
TCCR0B = 0b00000101; //setting pre-scaler for timer clock
TCNT0 = 0;
}
void loop() {
//to make the red LED turned on
digitalWrite(RED_PIN, HIGH);
delay_timer(red_on);
//turning off the red LED
digitalWrite(RED_PIN, LOW);
delay_timer(red_on);
}

The following is the code for the implementation of a simple traffic control system with the necessary code
explanation:

// Pin numbers are defined by the corresponding LED colors


#define RED_PIN 8
#define YELLOW_PIN 10
#define GREEN_PIN 12
//Define the delays for each traffic light color
int red_on = 6000; //5 s delay
int green_on = 3000; //7 s delay
int yellow_blink = 500; //5 s delay
// Declaring the timer function to count 1 ms of delay instead of calling the
delay function
int delay_timer (int milliseconds){
int count = 0;
while(1)
{
if(TCNT0 >= 16) // Checking if 1 millisecond has passed
{
TCNT0 = 0;
count++;
if (count == milliseconds) //checking if required milliseconds delay has
passed
{
count = 0;
break; // exits the loop
}
}
}
return 0;
}
void setup() {
//Define pins connected to LEDs as outputs
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);

5
//Set up the Timer0
TCCR0A = 0b00000000;
TCCR0B = 0b00000101; //setting pre-scaler for timer clock
TCNT0 = 0;
}
void loop() {
//to make the green LED turned on
digitalWrite(GREEN_PIN, HIGH);
delay_timer(green_on);
//to make the green LED turned off
digitalWrite(GREEN_PIN, LOW);
//for turning the yellow LED on and off for 4 times
for(int i = 0; i < 4; i = i+1)
{
digitalWrite(YELLOW_PIN, HIGH);
delay_timer(yellow_blink);
digitalWrite(YELLOW_PIN, LOW);
delay_timer(yellow_blink);
}
//to make the red LED turned on
digitalWrite(RED_PIN, HIGH);
delay_timer(red_on);
//to make the red LED turned off
digitalWrite(RED_PIN, LOW);
}

Hardware Output Results:


Here is the hardware implementation of the LED blink test and implement simple traffic control system
test and the necessary explanation of the implementation:

Fig.3 Hardware implementation for the blink test

Explanation: In the following implementation, a jumper wire was connected at the pin 8 of the Arduino
Uno board. The wire was then connected on the breadboard. The anode of an LED light was connected

6
with the wire connected with pin 8. The cathode of the LED light was connected with a 100 Ω resistor.
The following resistor was then connected with the Ground (GND) of the Arduino Uno board. The
Arduino Uno board was connected with a PC to compile and import necessary codes.

Here is the hardware implementation of Traffic Light System and the necessary explanation of the
implementation:

Fig.4 Hardware circuit diagram for the traffic light system

Explanation: In the following experiment, jumper wires were connected from pin 8, 10 and 12 of the
Arduino Uno board to the anodes of the RED, YELLOW and GREEN LED consecutively. Three 100
Ω resistors were connected at each cathode of all the LEDs. Jumper wires were then connected at the
negative common row of the breadboard. A jumper wire was connected then with the Ground (GND)
of the Arduino Uno board from the common negative of the breadboard. The Arduino Uno board was
connected with a PC to compile and import necessary codes.

Experimental Output Results:


Here are results of the light blink test and the necessary explanation of the results:

Fig.5 LED is ON in Light Blink Test

7
Fig.6 LED is OFF in Light Blink Test

Explanation: When the code is implemented and the loop () function starts, the code implements a
digital write operation on the microcontroller and provides a high voltage at the pin 8 as output. Hence,
the LED, that was connected at pin 8 turns ON (Fig,5). A delay occurs afterwards for a certain time.
This time was defined in milliseconds. According to the code that was implemented, a 2000 millisecond
delay occurs after the light is turned ON. Then, another digital write operation occurs and the pin 8 was
set to LOW as output. Therefore, the LED turns OFF (Fig. 6). Another 2000 milliseconds delay occurs
after the LED was set to low. The delay operation was executed by using delay_timer () function in the
loop () function. Thus, these results were happening one by one until the microcontroller was turned off
or removed from the power source.

Here are results of the Traffic Light System and the necessary explanation of the results:

Fig.7 GREEN LED is ON in Traffic Light System

8
Fig.8 YELLOW LED is ON in Traffic Light System

Fig.9 RED LED is ON in Traffic Light System

Explanation: When the code is implemented and the loop () function starts, the code implements a digital
write operation on the microcontroller and provides a high voltage at the pin 12 as output. As a result,
the green light turns ON (Fig.7). Then the light stayed on for 3000 milliseconds due to the delay function
called ‘green_on’. After that, the light turned off as a digital write was performed on the microcontroller
and output at 12 was low. Then, a for loop was introduced in the code which made the microcontroller
blink the yellow loght 4 times with an interval of 500 milliseconds (Fig.8) for the delay caused by the
value set on ‘yellow_blink’. When the yellow LED blinked for 4 times, then the red LED turns ON
(Fig.9). It turned off after 6000 millisecond which was set in the ‘red_on’ variable and was used a delay
function. All the operations kept occurring as all of the codes were performed in a loop.

Simulation Output Results:


Here are the simulation output results of Light Blink Test on Proteus simulation and explanation:

9
Fig.10 LED is ON in Light Blink Test on Proteus Simulation

Fig.11 LED is OFF in Light Blink Test on Proteus Simulation

Explanation: In this simulation, an Arduino Uno Board, Resistor and LED was configured according
to the hardware implementation that was performed. The program was made in the Arduino IDE was
verified. As a result, a HEX file was generated. The following HEX file was implemented in the
Proteus simulation for operation related instructions of the simulation. Afterwards, the simulation was
performed and the results that were obtained were noted and compared with the hardware results.

Here are the simulation output results of the Traffic Light System on Proteus simulation and
explanation:

Fig.12 Green LED is ON in Traffic Light System on Proteus Simulation


10
Fig.13 Yellow LED is ON in Traffic Light System on Proteus Simulation

Fig.14 Red LED is ON in Traffic Light System on Proteus Simulation

Explanation: In this simulation, an Arduino Uno Board, Resistor, RED, GREEN and YELLOW LEDs
were configured according to the hardware implementation that was performed. The program was made
in the Arduino IDE was verified. As a result, a HEX file was generated. The following HEX file was
implemented in the Proteus simulation for operation related instructions of the simulation. Afterwards,
the simulation was performed and the results that were obtained were noted and compared with the
hardware results.

Answers to the Questions in the Lab Manual:


3) Configure the system to have delays for outputs according to my ID is 21-45575-3. Consider the last
three digits from my ID is 575, (So 5 s delay for the RED LED, 7 s delay for the YELLOW LED, and 5 s
delay for GREEN LED). Include the program and results within my lab report.

Discussion:
In the following experiment, various simple and complex systems were designed like in the previous
experiments that were observed. In the previous experiment, a delay() function was used to initiate a pause
in the program to generate certain behaviors in the designed systems. But according to various

11
documentation and discussion that observed, this function has some drawbacks. This function causes a
halt in the microcontroller which pauses all the operation in a controller. Hence, various operations that
might need to run as a certain delay was happening may get interrupted. Timers in the microcontroller
was the solution to this problem. Although there are multiple timers that are available in a microcontroller,
Timer0 was observed in this experiment. According to various documentations and sources, Timers in
Arduino microcontroller boards are hardware components that allow precise timing and synchronization
of events. They provide a way to generate interruptions or trigger actions at specific intervals. By
understanding the related topics regarding timers, the ways and methods of leveraging their capabilities
to control the timing of various projects effectively were observed. This Timer0 function was used in the
LED blink test and Traffic Control System. The results of using this Timer0 function were observed and
noted down. The methodology of writing the code using this function was also observed and implemented
accordingly in the systems that were developed in this experiment. Overall, it can be said that, we got to
familiarize ourself with timers, observe LED blink tests and a simple traffic control system using the
Timer0 function provide a solid foundation for using timers effectively in future Arduino projects. Thus,
this experiment would help to control timing, synchronize events and create more advanced applications
that require precise timing control. Therefore, it can be said that the objectives of this experiment were
observed and achieved.

References:
[1] Circuit Digest Website, [Online: March 21, 2022], [Cited: June 10, 2023] Available:
https://circuitdigest.com/article/everything-you-need-to-know-about-arduino-uno-board-hardware
[2] All About Circuits, Introduction to Microcontroller Timers: Periodic Timers [Online: June 15, 2022],
[Cited: June 17, 2023] Available:
https://www.allaboutcircuits.com/technical-articles/introduction-to-microcontroller-timers-periodic-
timers/
[3] Arduino CC Website, [Online] [Cited: June 10, 2023] Available:
https://docs.arduino.cc/hardware/uno-rev3
[4] Microchip Developer, Timer0 [Online: 2021], [Cited: 18 June, 2023] Available:
https://microchipdeveloper.com/8bit:timer0
[5] AIUB Microprocessor and Embedded Systems Lab Manual 3

12

You might also like