Lab 1 Precsion Engineering
Lab 1 Precsion Engineering
Objective:
Using 3 LED’s (red, yellow and green) build a traffic light that Illuminates the green LED for 5
seconds Illuminates the yellow LED for 2 seconds Illuminates the red LED for 5 seconds repeats
the sequence Note that after each illumination period the LED is turned off!
Theory:
Components Required
220-ohm resistors
A breadboard
Connecting wires
Red, yellow and green LEDs
Arduino Uno
Procedure:
1. LED Connections:
Connect the longer leg (anode, positive) of the red LED to a current-limiting
resistor.
Connect the other end of the resistor to pin 5 on the Arduino.
Connect the shorter leg (cathode, negative) of the red LED to the ground (GND) pin
on the Arduino.
Repeat this process for the yellow LED (pin 9) and green LED (pin 8), each
connected to their respective pin on the Arduino and a current-limiting resistor with the shorter
leg connected to the GND pin.
2. Arduino Connection:
Click the 'Upload' button in the Arduino IDE to upload the code to the Arduino
board.
1|Page
Once the code is uploaded and the hardware connections are correctly set up, the LEDs should
start displaying the traffic light sequence as specified in the code. Adjust the pin numbers in the
code if you've connected the LEDs to different pins on the Arduino board.
Code:
Code for the Arduino Traffic Light:
int greenLED = 8; // Pin for the green LED
int yellowLED = 9; // Pin for the yellow LED
int redLED = 10; // Pin for the red LED
void setup() {
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
}
void loop() {
// Green LED ON for 5 seconds
digitalWrite(greenLED, HIGH);
delay(5000); // 5000 milliseconds = 5 seconds
digitalWrite(greenLED, LOW);
2|Page
digitalWrite(redLED, LOW);
}
Result:
Conclusion:
By following the outlined steps, the traffic light sequence using an Arduino Uno and three LEDs
(red, yellow, and green) was successfully implemented. The provided code controls the LEDs to
simulate a standard traffic light pattern:
1. Green LED is illuminated for 5 seconds, indicating "Go."
2. Yellow LED lights up for 2 seconds, signaling "Prepare to stop."
3. Red LED remains on for 5 seconds, indicating "Stop."
This sequence repeats continuously, creating a functional traffic light simulation. Double-
checking the connections and ensuring the correct upload of the code to the Arduino board are
crucial to achieving the desired behavior. Adjusting pin numbers in the code to match the
physical connections may be necessary if LEDs are connected to different pins on the Arduino
board.
3|Page