You are on page 1of 4

Lab Report 02

Objective:

Modify Task 1 to have an advanced green (blinking green LED) for 3 seconds before
illuminating the green LED for 5 seconds.

Theory:

 Arduino Uno: The microcontroller used to control the traffic light sequence.
 LEDs (Red, Yellow, Green): Light-emitting diodes used to simulate the traffic signal
lights.
 220-ohm Resistors: Current-limiting resistors to protect the LEDs when connected to the
Arduino.
 Breadboard and Connecting Wires: To build the circuit connections between the
LEDs, resistors, and Arduino.

Components Required:
 220-ohm resistors
 A breadboard
 Connecting wires
 Red, yellow and green LEDs
 Arduino Uno

Procedure:
1. LED Connections: Connect the LEDs to specific digital pins on the Arduino Uno along
with 220-ohm resistors. Red LED to pin 4, Yellow LED to pin 3, and Green LED to pin
2. Ensure proper polarity, connecting the shorter leg (cathode) to the GND pin.
2. Arduino Connection: Establish a connection between the Arduino Uno and your
computer using a USB cable. Open the Arduino IDE on the computer and select the
appropriate board and port.
3. Code Implementation: Utilize the Arduino IDE to write the code for the traffic light
sequence. The code specifies the actions for each LED pin: green, yellow, and red,

1|Page
indicating the traffic light phases. To create an "advanced green" phase, introduce a loop
that blinks the green LED for 3 seconds before a solid green illumination for 5 seconds.
4. Uploading Code: Upload the developed code to the Arduino board via the Arduino
IDE. Verify that the LED connections correspond to the assigned pins in the code.
5. Observation: Once uploaded, observe the traffic light sequence. The green LED will
exhibit an "advanced green" phase by blinking for 3 seconds before continuing with the
standard sequence of yellow and red lights.

Code for the Arduino Traffic Light:


int greenLED = 2; // Pin for the green LED
int yellowLED = 3; // Pin for the yellow LED
int redLED = 4; // Pin for the red LED

void setup() {
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
}

void loop() {
// Blinking Green LED for 3 seconds (Advanced Green)
for (int i = 0; i < 6; i++) { // Loop for 3 seconds (6 cycles x 500ms)
digitalWrite(greenLED, HIGH);
delay(500); // 500 milliseconds ON
digitalWrite(greenLED, LOW);
delay(500); // 500 milliseconds OFF
}

// Green LED ON for 5 seconds


2|Page
digitalWrite(greenLED, HIGH);
delay(5000); // 5000 milliseconds = 5 seconds
digitalWrite(greenLED, LOW);

// Yellow LED ON for 2 seconds


digitalWrite(yellowLED, HIGH);
delay(2000); // 2000 milliseconds = 2 seconds
digitalWrite(yellowLED, LOW);

// Red LED ON for 5 seconds


digitalWrite(redLED, HIGH);
delay(5000); // 5000 milliseconds = 5 seconds
digitalWrite(redLED, LOW);
}

Result:

3|Page
Result For Blinking Lights:

 Added a for loop to create a blinking effect for the green LED. The loop runs for 3
seconds by executing 6 cycles of 500 milliseconds each (500ms ON, 500ms OFF).
 After the blinking "advanced green" phase, the code continues with the previous
sequence:
 Green LED ON for 5 seconds, Yellow LED ON for 2 seconds, and Red LED ON for 5
seconds.
Upload this modified code to the Arduino board, ensuring the LED connections correspond to
the correct pin assignments in the code. This modification will introduce a blinking green LED
for 3 seconds before transitioning to a solid 5-second green illumination within the traffic light
sequence.

Conclusion:
In conclusion, the modified traffic light sequence successfully achieved the objective of
introducing an "advanced green" phase, enriching the simulated traffic signal's functionality and
mimicking real-world traffic conditions more effectively.

4|Page

You might also like