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

Arduino UNO Based Traffic Light Control System with GPS and GSM Integration

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Traffic Light Control System with GPS and GSM Integration

Circuit Documentation

Summary

This circuit is designed to control a traffic light system with an Arduino UNO microcontroller at its core. It interfaces with a GPS module (GPS NEO 6M) and a GSM module (Sim800l) to receive the location of an ambulance and control the traffic lights accordingly. The traffic lights are represented by three LEDs (red, yellow, and green), each with a corresponding resistor to limit the current. The Arduino UNO controls the LEDs based on the ambulance's proximity to the traffic light and sends a message to the ambulance using the GSM module when the light is green.

Component List

Arduino UNO

GPS NEO 6M

Sim800l

LED: Two Pin (red)

LED: Two Pin (green)

LED: Two Pin (yellow)

Resistor (150 Ohms)

Resistor (100 Ohms)

Wiring Details

Arduino UNO

GPS NEO 6M

Sim800l

LEDs (Red, Yellow, Green)

Resistor (150 Ohms)

Resistor (100 Ohms)

Documented Code

#include <SoftwareSerial.h>

// Pins for GPS and GSM
SoftwareSerial gpsSerial(4, 3);  // RX, TX for GPS
SoftwareSerial gsmSerial(7, 6);  // RX, TX for GSM

// Traffic light LEDs
int redLED = 8;
int yellowLED = 9;
int greenLED = 10;

// Variables for GPS
String ambulanceLatitude, ambulanceLongitude;
float distanceThreshold = 100.0;  // Distance in meters

// Function to calculate distance (replace with your formula if necessary)
float calculateDistance(float lat1, float lon1, float lat2, float lon2) {
  // Use Haversine formula to calculate distance (in meters)
  // Simplified here for brevity, can use libraries like TinyGPS
  return 0; // Replace with actual calculation
}

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  gpsSerial.begin(9600);
  gsmSerial.begin(9600);
  
  // Initialize traffic light pins
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);

  // Set initial state (Red light on)
  digitalWrite(redLED, HIGH);
  digitalWrite(yellowLED, LOW);
  digitalWrite(greenLED, LOW);
}

void loop() {
  // Get GPS data from ambulance
  if (gpsSerial.available()) {
    ambulanceLatitude = gpsSerial.readStringUntil(',');
    ambulanceLongitude = gpsSerial.readStringUntil('\n');
    
    // Dummy coordinates for the traffic light location
    float trafficLightLat = 30.123456;
    float trafficLightLon = 31.123456;
    
    // Calculate distance between ambulance and traffic light
    float distance = calculateDistance(trafficLightLat, trafficLightLon, ambulanceLatitude.toFloat(), ambulanceLongitude.toFloat());

    // Check if ambulance is within range
    if (distance < distanceThreshold) {
      // Turn Green light ON and Red light OFF
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);
      
      // Send message to the ambulance
      sendMessageToAmbulance();
    } else {
      // Turn Red light ON and Green light OFF
      digitalWrite(redLED, HIGH);
      digitalWrite(greenLED, LOW);
    }
  }
}

void sendMessageToAmbulance() {
  // Send a GSM message to the ambulance indicating the green light
  gsmSerial.println("AT+CMGF=1");  // Set GSM to text mode
  delay(1000);
  gsmSerial.println("AT+CMGS=\"+123456789\"");  // Replace with ambulance phone number
  delay(1000);
  gsmSerial.println("Traffic light is green, you can pass!");  // Message
  delay(100);
  gsmSerial.write(26);  // Send CTRL+Z to end the message
  delay(1000);
}

This code is designed to run on the Arduino UNO microcontroller. It initializes two software serial ports for communication with the GPS and GSM modules, sets up the pins for the traffic light LEDs, and enters a loop where it reads GPS data to determine the ambulance's proximity to the traffic light. If the ambulance is within a certain distance, it switches the traffic light to green and sends a message to the ambulance.