MES Lab 2 - Abir
MES Lab 2 - Abir
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
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.
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:
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:
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);
}
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:
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.
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:
8
Fig.8 YELLOW 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.
9
Fig.10 LED is ON 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:
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.
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