Arduino Project: Traffic Light Controller
1. Introduction
This project demonstrates a simple Traffic Light Controller using an Arduino. It simulates the working of a standard traffic light using Red, Yellow, and Green LEDs. The controller turns each LED ON and OFF in a specific sequence with appropriate delays to mimic real traffic lights.
2. Components Required
· Arduino Uno:
Microcontroller board based on the ATmega328P.
· Red LED:
Represents the STOP signal in the traffic light.
· Yellow LED:
Represents the GET READY signal.
· Green LED:
Represents the GO signal.
· Resistors (3 x 220 ohm):
To limit the current for each LED.
· Breadboard:
For constructing the circuit.
· Jumper Wires:
For connecting the components on the breadboard.
3. Circuit Diagram
Connect the components as follows:
- Connect the Red LED anode to digital pin 2 via a 220Ω resistor and the
cathode to GND.
- Connect the Yellow LED anode to digital pin 3 via a 220Ω resistor and the
cathode to GND.
- Connect the Green LED anode to digital pin 4 via a 220Ω resistor and the
cathode to GND.
4. Arduino Code
void setup() {
pinMode(2, OUTPUT); // Red LED
pinMode(3, OUTPUT); // Yellow LED
pinMode(4, OUTPUT); // Green LED
}
void loop() {
digitalWrite(2, HIGH); // Red ON
delay(5000); // Wait 5 seconds
digitalWrite(2, LOW); // Red OFF
digitalWrite(3, HIGH); // Yellow ON
delay(2000); // Wait 2 seconds
digitalWrite(3, LOW); // Yellow OFF
digitalWrite(4, HIGH); // Green ON
delay(5000); // Wait 5 seconds
digitalWrite(4, LOW); // Green OFF
digitalWrite(3, HIGH); // Yellow ON
delay(2000); // Wait 2 seconds
digitalWrite(3, LOW); // Yellow OFF
}
5. Explanation
In the setup() function, digital pins 2, 3, and 4 are configured as OUTPUTs for Red, Yellow, and Green LEDs respectively. In the loop(), the Red LED lights up for 5 seconds to indicate STOP. Then the Yellow LED lights for 2 seconds to indicate GET READY. Next, the Green LED turns ON for 5 seconds to indicate GO. Finally, the Yellow LED lights up again for 2 seconds before repeating the cycle.