Traffic Light Controller

Building a traffic light controller is a practical electronics project that can help you understand microcontroller programming and control systems. In this project, we will create a basic traffic light controller using an Arduino microcontroller. The controller will simulate the sequence of a traffic light intersection with red, yellow, and green lights for two directions. Here’s how to build it:

Components you’ll need:

Arduino board (e.g., Arduino Uno)
Breadboard and jumper wires
LEDs (Red, Yellow, Green for each direction)
Resistors (220-330 ohms)
Pushbuttons (for pedestrian crossing simulation)
Power supply (e.g., USB cable for Arduino)
Circuit Connections:

Connect LEDs for the North-South direction:

Red LED to digital Pin 2
Yellow LED to digital Pin 3
Green LED to digital Pin 4
Connect LEDs for the East-West direction:

Red LED to digital Pin 5
Yellow LED to digital Pin 6
Green LED to digital Pin 7
Connect a pushbutton for simulating a pedestrian request:

Connect one terminal of the pushbutton to digital Pin 8.
Connect the other terminal of the pushbutton to GND.
Connect a 10k ohm resistor from Pin 8 to +5V to act as a pull-up resistor.
Arduino Code:

Upload the following Arduino code to your Arduino board using the Arduino IDE:

const int redNS = 2;
const int yellowNS = 3;
const int greenNS = 4;
const int redEW = 5;
const int yellowEW = 6;
const int greenEW = 7;
const int pedestrianButton = 8;

void setup() {
pinMode(redNS, OUTPUT);
pinMode(yellowNS, OUTPUT);
pinMode(greenNS, OUTPUT);
pinMode(redEW, OUTPUT);
pinMode(yellowEW, OUTPUT);
pinMode(greenEW, OUTPUT);
pinMode(pedestrianButton, INPUT_PULLUP);
}

void loop() {
// North-South traffic
digitalWrite(redNS, HIGH);
digitalWrite(greenEW, HIGH);
delay(5000); // Green for NS, Red for EW

if (digitalRead(pedestrianButton) == LOW) {
// Pedestrian request
digitalWrite(greenEW, LOW);
delay(1000); // Pedestrian red
digitalWrite(yellowEW, HIGH);
delay(3000); // Pedestrian warning
digitalWrite(yellowEW, LOW);
}

digitalWrite(redNS, LOW);
digitalWrite(yellowNS, HIGH);
delay(2000); // Yellow for NS

// East-West traffic
digitalWrite(yellowNS, LOW);
digitalWrite(redEW, HIGH);
delay(5000); // Red for NS, Green for EW

digitalWrite(redEW, LOW);
digitalWrite(greenEW, HIGH);
delay(5000); // Green for EW

digitalWrite(greenEW, LOW);
digitalWrite(yellowEW, HIGH);
delay(2000); // Yellow for EW
digitalWrite(yellowEW, LOW);
}
Circuit Implementation:

Connect the components as per the circuit diagram and the connections described above.

Power the Arduino using a USB cable or an appropriate power supply.

The code provided simulates a basic traffic light sequence for the North-South and East-West directions. It also includes a pedestrian request button. When the button is pressed, it allows pedestrians to cross safely.

Upload the code to the Arduino.

Usage:

Observe the traffic light sequence and test the pedestrian request button. The LEDs will change according to the predefined traffic light timing, allowing you to simulate a basic traffic intersection.

This project can be expanded by adding more features, such as timing adjustments, sensors for vehicle detection, and synchronization between multiple traffic lights at an intersection. It’s a great way to learn about control systems and microcontroller programming while creating a practical and educational project.