Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Based Smart Traffic Light System with NRF24L01 Wireless Communication

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Smart Traffic Light System with NRF24L01 Wireless Communication

Smart Traffic Lights System for Prioritizing Emergency Vehicles

Summary

This document provides a detailed overview of a smart traffic lights system designed to prioritize emergency vehicles. The system uses multiple Arduino Nano microcontrollers, NRF24L01 wireless modules, traffic lights, and other components to detect emergency vehicles and change traffic lights accordingly. The system is powered by 5V batteries and includes resistors and a DIP switch for additional functionality.

Component List

Arduino Nano

NRF24L01

DIP Switch 4 Position

Traffic Light

5V Battery

Resistor

Wiring Details

Arduino Nano

NRF24L01

Traffic Light

5V Battery

Resistor

DIP Switch 4 Position

Code Documentation

Arduino Nano (Instance 1)

/*
 * Smart Traffic Lights System for Prioritizing Emergency Vehicles
 * This code controls a set of traffic lights connected to an Arduino Nano.
 * The system prioritizes emergency vehicles by changing the traffic lights
 * to green when an emergency vehicle is detected.
 */

// Pin definitions for traffic lights
const int greenLight1 = 2;
const int yellowLight1 = 3;
const int redLight1 = 4;
const int greenLight2 = 5;
const int yellowLight2 = 6;
const int redLight2 = 9;
const int greenLight3 = A0;
const int yellowLight3 = A1;
const int redLight3 = A2;
const int greenLight4 = A3;
const int yellowLight4 = A4;
const int redLight4 = A5;

// NRF24L01 pin definitions
const int CE_PIN = 7;
const int CSN_PIN = 8;

void setup() {
  // Initialize traffic light pins as outputs
  pinMode(greenLight1, OUTPUT);
  pinMode(yellowLight1, OUTPUT);
  pinMode(redLight1, OUTPUT);
  pinMode(greenLight2, OUTPUT);
  pinMode(yellowLight2, OUTPUT);
  pinMode(redLight2, OUTPUT);
  pinMode(greenLight3, OUTPUT);
  pinMode(yellowLight3, OUTPUT);
  pinMode(redLight3, OUTPUT);
  pinMode(greenLight4, OUTPUT);
  pinMode(yellowLight4, OUTPUT);
  pinMode(redLight4, OUTPUT);

  // Initialize NRF24L01 pins
  pinMode(CE_PIN, OUTPUT);
  pinMode(CSN_PIN, OUTPUT);

  // Initialize serial communication
  Serial.begin(9600);

  // Initialize NRF24L01 (add your NRF24L01 initialization code here)
}

void loop() {
  // Check for emergency vehicle signal (add your signal detection code here)
  bool emergencyVehicleDetected = false; // Placeholder for actual detection logic

  if (emergencyVehicleDetected) {
    prioritizeEmergencyVehicle();
  } else {
    normalTrafficOperation();
  }
}

void prioritizeEmergencyVehicle() {
  // Turn all traffic lights to red except the one for emergency vehicle
  digitalWrite(redLight1, HIGH);
  digitalWrite(yellowLight1, LOW);
  digitalWrite(greenLight1, LOW);
  digitalWrite(redLight2, HIGH);
  digitalWrite(yellowLight2, LOW);
  digitalWrite(greenLight2, LOW);
  digitalWrite(redLight3, HIGH);
  digitalWrite(yellowLight3, LOW);
  digitalWrite(greenLight3, LOW);
  digitalWrite(redLight4, LOW);
  digitalWrite(yellowLight4, LOW);
  digitalWrite(greenLight4, HIGH);
}

void normalTrafficOperation() {
  // Normal traffic light sequence (add your traffic light sequence code here)
  // Example: Green -> Yellow -> Red for each traffic light
  digitalWrite(greenLight1, HIGH);
  delay(5000);
  digitalWrite(greenLight1, LOW);
  digitalWrite(yellowLight1, HIGH);
  delay(2000);
  digitalWrite(yellowLight1, LOW);
  digitalWrite(redLight1, HIGH);
  delay(5000);
  digitalWrite(redLight1, LOW);

  digitalWrite(greenLight2, HIGH);
  delay(5000);
  digitalWrite(greenLight2, LOW);
  digitalWrite(yellowLight2, HIGH);
  delay(2000);
  digitalWrite(yellowLight2, LOW);
  digitalWrite(redLight2, HIGH);
  delay(5000);
  digitalWrite(redLight2, LOW);

  digitalWrite(greenLight3, HIGH);
  delay(5000);
  digitalWrite(greenLight3, LOW);
  digitalWrite(yellowLight3, HIGH);
  delay(2000);
  digitalWrite(yellowLight3, LOW);
  digitalWrite(redLight3, HIGH);
  delay(5000);
  digitalWrite(redLight3, LOW);

  digitalWrite(greenLight4, HIGH);
  delay