0% found this document useful (0 votes)
44 views7 pages

51a5b56d-2fe2-4d1e-8732-38d9b12231f7

Uploaded by

api-727411508
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)
44 views7 pages

51a5b56d-2fe2-4d1e-8732-38d9b12231f7

Uploaded by

api-727411508
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/ 7

LAB 5: Arduino Lab

ENGR 217 – Sec 501


Adel Mohamed

Team Members:
Karim Youssef
Saif Al-Mohannadi
Salahudin Abu-Munshar (Team Manager)
Mohammad Musmar

Texas A&M University at Qatar


Science Program

Abstract: This report delved into a detailed analysis of the Arduino microcontroller's design. The focus was on
creating a functional traffic light system employing basic components like a breadboard, LEDs, and resistors,
in conjunction with the Arduino board and its software tools. At the core of this setup was the microcontroller,
an integrated circuit customized for specific electronic tasks. We established connections between individual
LEDs and the Arduino using cables. Using Arduino software, we programmed a sequence mimicking traffic
light patterns through the 'blink' feature. The timings for these patterns were meticulously adjusted and verified
using a timer to ensure accuracy. The entire system was successfully set up with active high configurations for
both input and output signals.
Introduction:
Keywords: Arduino, Microcontroller, LED’s, Traffic Lights, Breadboard _

1.Introduction and Objectives:


In this lab, the focus was on Arduino microcontrollers, widely integrated into various systems for enhanced
functionality. The objective of this experiment was to gain a comprehensive understanding of Arduino's circuit
design and programming capabilities. This involved a systematic approach to creating a dual traffic light
system that alternates movement periodically. The objectives encompassed several key steps, starting with
running a basic blink code using the internal LED and progressing to more complex tasks such as integrating
external LEDs, programming specific blinking sequences, constructing individual traffic lights with calibrated
timings, and optimizing the code for efficiency.
2.Equipment & Components:

During this lab, the essential items required to construct the traffic light system were:

• Lab computer equipped with the Arduino IDE application.


• Arduino UNO rev.3 board, which utilizes the ATmega328P microcontroller.
• A Solderless Breadboard for connecting the circuit
• A USB-to-USB connector to connect the Arduino board to the local machine
• LEDs (green, yellow, and red colors).
• 330 Ω, 1⁄2 watt resistors
• Jumper’s wires
• A stopwatch to time the intervals of blinking LEDs
3.Approach:

The initial step of the lab procedure was to open a Lab computer equipped with the Arduino IDE application
and run the Arduino program which was set up using Board: Arduino/Genuino Uno and Port: COM6. Then, a
circuit that connects the Arduino board, LED, and resistor was created and a new Arduino code was written
and modified based on the created circuit and based on the location in which the pins were placed. The initial
aim was to establish a connection between the Arduino board and the computer using a USB cable. When the
connection is successful, a green LED on the board confirms it.

Subsequently, we adhere to the project objectives to construct a two-road traffic light system. The next step
was to adjust the delay time. This was done and edited based on the following times provided in (Table 1):
3000ms, 5000ms, and 10000ms, and the corresponding time in seconds were recorded in the same table. Based
on the findings in Table 1, we found that the delay time in Arduino code represents a time in milliseconds(ms),
therefore, by using the method of dimensional analysis, Experiment 2 was conducted by converting 0.5s to
(ms), and the new time in (ms) was placed in the delay () function.
Moving onto experiment 3, the LED was tasked and set to blink in a specific manner, therefore, for each given
time in experiment 3, and by converting the times in (s) to (ms) the code was modified and experiment 3 was
accomplished. For experiment 4, to simulate the traffic light system in Qatar, green and yellow LEDs were
added to the circuit and were placed in pins 10 and 1, respectively. Moreover, two resistors and jumper wires
were added to the circuit connection between the Arduino and the breadboard, and the code was modified. For
experiment 5, the same code as experiment 4 was updated using a “for”loop.

4.Results:
Table 1 - Results Table Representing Delay Time in code in Milliseconds compared to
Real Interval Time and Time Measured in Seconds
Delay Time in Code (MilliSeconds) Real Time Interval (Seconds) Actual Time Measured (Seconds)
3000 3 3.05
5000 5 4.95
10000 10 9.98

5.Questions:

Q1: Never connect an LED directly to the power supply pins (5 V). Why?

It is very important to avoid directly connecting any LED to a 5V power supply port on the Arduino. The
reason for this precaution is because excessive current flow, which can occur if not properly monitored, can
potentially cause damage to both the LED and the Arduino circuit board. To avoid this risk, LEDs are typically
connected in series with a low-watt resistor. This resistor
Figure 1 - Code for experiment 1 (3000ms)

Figure 2 - Code for experiment 1 (3000ms)

Figure 3 - Code for experiment 1 for 5000 ms


Q2: If we want the LED to blink for every 0.5 seconds, what change should be made to the code in Section 2.3,
step 7?

To get the LED to blink every half second `delay(500)` was used, this was the change made in the code instead
of using `delay(3000)`, `delay(5000)`, and `delay(10000)` that was used in the previous part of the experiment.

Figure 4 - Code for Experiment 2 for the pattern


The above code example initializes an LED to alternate between 500 milliseconds of on time and 500
milliseconds of off time continually. This is accomplished by using a variable named "LED," which is defined
in the code. The setup section of the code, defined on lines 28 to 36, uses the pinMode() method to set the LED
pin as an output. Finally, the code tells the LED to cycle through 500 milliseconds of on and off states while it
is in the loop.

Q3: Suppose we want the LED to blink with the following pattern: it stays on for 1 second, stays off for 1
second, then stays on for 2 seconds, then stays off for 2 seconds, and then repeats. Write the modified Arduino
code sketch to implement this pattern for the blinking LED.

Figure 5 - Code for Experiment 3 for the Blinking Pattern

In the above code, an LED is configured to turn on for one second, turn off for one second, and then repeat the
cycle of turning on for two seconds and off for two seconds. This behavior is achieved by a straightforward
implementation technique. The desired LED pattern is produced by this code, which generates a visual signal
that alternates between 1- and 2-second intervals of illumination and darkness.
Q4: Write an Arduino sketch that will simulate traffic light system in Qatar roads using Green, yellow, and red
LEDs.
Initially all the LEDs are OFF then the traffic light follows the following steps:
Step 1: Green LED ON for 5 sec, yellow LED OFF, and red LED OFF.
Step 2: Green LED is blinking (On/Off) 3 times for 3 sec, yellow LED OFF, and red LED OFF. Step 3: Green
LED OFF, yellow LED is blinking 3 times for 3 sec, and red LED OFF.
Step 4: Green LED OFF, yellow LED OFF, and red LED ON for 5 sec.

Figure 6 - Code for Experiment 4 of Traffic Light Simulation


The code above was employed to create a simulation of a traffic light based on the instructions provided in the
lab guidelines. In the initial lines (1 to 3), variables GLED, YLED, and RLED were declared for the green
(GLED), yellow (YLED), and red (RLED) LEDs respectively. The subsequent lines (5 to 10) configured these
LEDs as outputs using pinMode(). The main part of the program (lines 11 to 50) operates in a loop to control
the LEDs. It utilizes digitalWrite() to switch the LEDs on (HIGH) and off (LOW), combined with delay() to
establish the duration for which the LEDs remain on or off.
Initially, the green LED is activated for 5 seconds (lines 14 to 17), while the yellow and red LEDs remain
inactive. Then, the green LED starts to blink, toggling between off and on states, each lasting 1 second,
repeating this pattern three times (lines 20 to 31). The green LED is subsequently turned off in line 33. Similar
to the blinking pattern of the green LED, the yellow LED blinks with the same interval and cycle (lines 35 to
46). Finally, the red LED is turned on for 5 seconds, as indicated in lines 48 to 50

Figure 7 - Picture of in-class Arduino uno board

Q5: Update the code in experiment 4 using for statement to repeat the block of LEDS blinking:
Figure 8 - Code for Experiment 5 of Traffic Light Simulation using For Loops

For experiment 5, The initial approach for simulating a traffic light was less efficient because it involved
manually repeating the same commands to control the LED pattern. In contrast, a more efficient solution is
employed for loops, which are designed to run a sequence of actions for a specified number of iterations. In
this case, all the loops needed to run three times, which is why the conditions within the for statements utilized
the variable 'i.' This variable started at 1, incremented with each iteration, and the loops terminated when 'i'
reached 3.

You might also like