Two-Way Traffic Light System Using Two Arduino UNO Boards

by DESHBOT in Circuits > Arduino

16 Views, 0 Favorites, 0 Comments

Two-Way Traffic Light System Using Two Arduino UNO Boards

WhatsApp Image 2026-09-23 at 11.14.32 AM.jpeg

The objective of this project is to create a two-way traffic light system using two Arduino UNO boards. The two boards communicate with each other using TX and RX serial communication.

The system controls two traffic light modules so that when one side has a green signal, the opposite side has a red signal.

Supplies

des 1.jpeg
uno.jpeg
WhatsApp Image 2026-09-07 at 12.33.00 PM.jpeg
WhatsApp Image 2026-09-23 at 11.14.44 AM.jpeg

2 x Deshbot shield

2 × Arduino UNO/Nano

2 × Traffic light modules

Jumper wires

Traffic Light Connections

WhatsApp Image 2026-09-23 at 11.21.23 AM.jpeg


UNO 1 – Traffic Signal 1

Traffic ModuleArduino UNO 1

Red - A0

Yellow - A1

Green - A2

GND - GND

UNO 2 – Traffic Signal 2

Traffic ModuleArduino UNO 2

Red - A0

Yellow - A1

Green - A2

GND - GND

UNO-to-UNO Communication

The two Arduino boards communicate using their hardware serial pins.

UNO 1UNO 2

TX (D1) - RX (D0)

RX (D0) - TX (D1)

GND - GND

TX is connected to RX because one board's transmitted data must be received by the other board.

Working Principle

WhatsApp Image 2026-09-23 at 11.21.37 AM.jpeg


The system operates two traffic signals in opposite phases.

Phase 1

Traffic Signal 1:

🟢 Green

Traffic Signal 2:

🔴 Red

Signal 1 allows traffic to move while Signal 2 stops traffic.

Phase 2

After 5 seconds, Signal 1 changes to yellow.

🟡 Signal 1

Signal 2 changes to green.

🟢 Signal 2

Phase 3

Signal 2 remains green for the required time while Signal 1 remains stopped.

After the cycle, the signals change again.

The Arduino boards communicate through TX/RX to coordinate the traffic lights.

Timing

The basic timing used in the project is:

SignalTime

Green

5 seconds

Yellow

2 seconds

Red

Depends on opposite signal

The cycle continuously repeats.

Example

SIGNAL 1 SIGNAL 2

0–5 sec 🟢 🔴

5–7 sec 🟡 🟢

Next 🔴 🟢

Next 🟢 🔴

This creates an alternating traffic flow.

Communication

Serial communication is used to send commands between the two Arduino boards.

For example, UNO 1 can send:

S1_GREEN

The second UNO receives the command and sets its traffic light to red.

Another command can tell the second UNO to change to green.

Conclusion


This project demonstrates a simple two-way traffic light control system using two Arduino UNO boards. The boards communicate using TX, RX, and GND, allowing the two traffic signals to operate in opposite phases. It demonstrates basic traffic control, timing, and serial communication between microcontrollers.

Codes

UNO 1 code


#define RED A0
#define YELLOW A1
#define GREEN A2

void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);

Serial.begin(9600);
}

void loop() {

// SIGNAL 1 GREEN
// SIGNAL 2 RED
digitalWrite(RED, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, HIGH);

Serial.println("S1_GREEN");

delay(5000);

// SIGNAL 1 YELLOW
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);

Serial.println("S1_YELLOW");

delay(2000);
}

UNO 2 code


#define RED A0
#define YELLOW A1
#define GREEN A2

void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);

Serial.begin(9600);

// Start with Signal 2 RED
digitalWrite(RED, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, LOW);
}

void loop() {

if (Serial.available()) {

String command = Serial.readStringUntil('\n');
command.trim();

if (command == "S1_GREEN") {

// Signal 1 GREEN
// Signal 2 RED

digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}

if (command == "S1_YELLOW") {

// Signal 1 YELLOW
// Signal 2 GREEN

digitalWrite(RED, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, HIGH);

delay(5000);

// Signal 2 YELLOW
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);

delay(2000);

// Signal 2 RED
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
}