MAES - Lab - Experiment 3
MAES - Lab - Experiment 3
Introduction: The objective of this experiment is to get familiarized with Timers and use
them for the implementation of a traffic control system.
Timer: Every electronic component of a sequential logic circuit works on a time base. This
time base helps to keep all the work synchronized. Without a time, base, devices would have
no idea as to when to perform particular actions. Thus, the timer is an important concept in
the field of electronics.
A timer/counter is a piece of hardware built into the Arduino controller. It is like a clock and
can be used to measure time events. A timer is a register whose value increases/decreases
automatically.
In AVR, timers are of two types: 8-bit and 16-bit timers. In an 8-bit timer, the register used is
8-bit wide whereas, in a 16-bit timer, the register width is 16 bits. This means that the 8-bit
timer is capable of counting 2 8=256 steps from 0 to 255. Similarly, a 16-bit timer is capable
of counting 216=65536 steps from 0 to 65535.
Experimental setup:
Apparatus:
● Arduino Uno/ Arduino Mega
● LED lights (YELLOW, RED, and GREEN)
● Resistors (220 ohms)
void setup() {
//define pins connected to LEDs as outputs
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
//set up timer
TCCR0A = 0b00000000;
TCCR0B = 0b00000101; //setting pre-scaler for timer clock
TCNT0=0;
}
© Dept. of EEE, Faculty of Engineering, American International University-Bangladesh (AIUB)
Experiment 3 Lab Manual
void loop() {
1) Include all codes and scripts into the lab report following the writing template
mentioned in appendix A of Laboratory Sheet Experiment 3.
2) Implement this system using an online simulation platform www.tinkercad.com.
3) Configure the system to have delays for outputs according to your ID. Consider the
last three digits from your ID (if your ID is XX-XXABC-X then consider A for the
RED light, B for the YELLOW LED, and C for GREEN LED). Include the program
and results within your lab report.
Reference(s):
1) https://www.arduino.cc/.
2) ATMega328 manual
3) https://www.avrfreaks.net/forum/tut-c-newbies-guide-avr-timers
4) http://maxembedded.com/2011/06/avr-timers-timer0/
© Dept. of EEE, Faculty of Engineering, American International University-Bangladesh (AIUB)