0% found this document useful (0 votes)
11 views8 pages

Lab 4 - MES - Group 8

The lab report details an experiment conducted at American International University-Bangladesh, focusing on familiarizing students with Arduino timers through a digital timer project and a simple traffic control system. The objectives include studying the millis() function, building a sequential LED control system, and understanding Arduino's timer functionality. The report includes experimental results, discussions on the findings, and references for further reading.

Uploaded by

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

Lab 4 - MES - Group 8

The lab report details an experiment conducted at American International University-Bangladesh, focusing on familiarizing students with Arduino timers through a digital timer project and a simple traffic control system. The objectives include studying the millis() function, building a sequential LED control system, and understanding Arduino's timer functionality. The report includes experimental results, discussions on the findings, and references for further reading.

Uploaded by

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

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: 7th November 2024 Date of Submission: 20th


November 2024
Course Title: Microprocessor and Embedded Systems Lab
Course Code: EE4103 Section: J
Semester: Fall 2024-25 Degree Program: BSc in CSE/EEE
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan

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; no part has been copied from any other student’s work or 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 am 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 # 05

Sl No Name ID PROGRAM SIGNATURE


1 Aminul Islam Mahim 22-46183-1 BSc in CSE
2 Nath, Prious Chandra 22-46302-1 BSc in CSE
3 Maesa Anjum 22-46240-1 BSc in CSE
4 MD Motasim Billah 22-46653-1 BSc in CSE

Faculty use only

1
FACULTY COMMENTS
Marks Obtained

Total Marks

Table of Contents
Title 03
Objectives 03
Equipment List 03
Circuit Diagram 03
Code / Program 04
Experimental Output Results (Color Photographs) 06
Simulation Output Results (Color Photographs) 07
Answers to the Questions in the Lab Manual 09
Discussion 09
References 09

2
Title: Study of a Digital Timer using the millis() function of Arduino.

Objective:
The objectives of this experiment are to
1. Study the application of the millis() function of Arduino.
2. Build a digital timer to turn on several LEDs every minute sequentially on an Arduino Microcontroller Board.
3. Know the working duration of a project run by an Arduino’s built-in Timer.
4. Implement a sequential LED light pattern control system using an input switch and an Arduino
Microcontroller Board.
Apparatus:
1) Arduino IDE (2.0.1 or any recent version)
2) Arduino Microcontroller board
3) LED lights (Red, Green, and Yellow- each 2)
4) Six 100  resistors and one 10 k resistor
5) One tilt switch
6) Jumper wires
Circuit Diagram:

Fig:1

Arduino board

3
Code/Program:

const int SwitchPin = 8; // Pin for switch


unsigned long PreviousTime = 0;
int SwitchState = 0;
int PrevSwitchState = 0;
int led = 2;
int r_led = 7;
int cnt = 0; // Counter to switch between behaviors
long interval = 1000; // Interval for LED timing
// Function to turn on the red LED in a backward direction (reverse)
void type_1() {
digitalWrite(r_led, HIGH);
r_led--;
if (r_led < 2) {
r_led = 7; // Reset the red LED pin to 7 when it goes below 2}}
// Function to turn on the regular LED in a forward direction
void type_2() {
digitalWrite(led, HIGH);
led++;
if (led > 7) {
led = 2; // Reset the LED to pin 2 when it exceeds 7 }}
void setup() {
Serial.begin(9600);

4
// Initialize LED pins (2 to 7)
for (int x = 2; x < 8; x++) {
pinMode(x, OUTPUT); }
pinMode(SwitchPin, INPUT_PULLUP); // Switch pin as input with pull-up resistor}
void loop() {
Serial.println(cnt); // Print the counter to serial monitor for debugging
unsigned long CurrentTime = millis();
// Execute the LED behavior based on the counter value
if (CurrentTime - PreviousTime > interval) {
PreviousTime = CurrentTime;
// If counter is even, call type_2 (LED forward), else call type_1 (LED reverse)
if (cnt % 2) {
type_1(); } else {
type_2(); } }
// Read switch state
SwitchState = digitalRead(SwitchPin);
// Check for a button press (falling edge detection)
if (SwitchState != PrevSwitchState) {
// Simple debounce: delay for 50ms to avoid multiple reads
delay(50);
// If the button is pressed (switch is LOW in active-low configuration)
if (SwitchState == LOW) {
cnt++; // Toggle the counter on a button press (flip the LED pattern)

// Reset all LEDs (turn off LEDs)


for (int x = 2; x < 8; x++) {
digitalWrite(x, LOW); }

// Reset the LED pins for the next cycle


led = 2;
r_led = 7;
PreviousTime = CurrentTime; // Reset the timer when switch is pressed }}
// Save the current switch state for the next iteration
PrevSwitchState = SwitchState;}

5
Simulation Result:

Fig:2 all led on

Fig:3 green and red on


6
Fig:4 reverse on

Experimental Output:

a.

b.

7
c.

Discussion:

In this experiment, we explored the utility of the millis() function in Arduino for constructing a digital timer.
Our findings underscored the remarkable accuracy and precision achieved with millis(), vital for tasks
requiring precise timing. Moreover, its non-blocking nature enables concurrent execution of other program
tasks, enhancing overall efficiency. We addressed potential overflow issues through effective handling
mechanisms, ensuring uninterrupted timer operation over extended periods. Practical applications span
various domains, including photography, automation, and IoT projects. Future improvements could focus on
integrating advanced features like interrupts for enhanced functionality and exploring power optimization
strategies. In summary, our study demonstrates the efficacy of millis() in facilitating precise, non-blocking
digital timers, empowering Arduino projects with versatile timing capabilities.

References:
1. https://www.arduino.cc/.
2. https://www.coursera.org/learn/arduino/lecture/ei4ni/1-10-first-glance-at-a-program
3. Jeremy Blue; Exploring Arduino: Tools and Techniques for Engineering Wizardr
4. https://internetofthingsagenda.techtarget.com/
5. AIUB Microprocessor and Embedded Systems Lab Manual 3

You might also like