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

Arduino UNO RFID-Controlled Traffic Light and Barrier System

View and Edit Project In Cirkit DesignerImage of Arduino UNO RFID-Controlled Traffic Light and Barrier System

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a barrier system using an RFID reader, a servo motor, and a traffic light. The system is managed by an Arduino UNO microcontroller. The RFID reader is used to grant access, the servo motor operates the barrier, and the traffic light indicates the status of the barrier.

Component List

  1. RFID-RC522

    • Description: RFID reader module
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  2. Tower Pro SG90 Servo

    • Description: Servo motor for barrier control
    • Pins: Signal, +5V, GND
  3. Arduino UNO

    • Description: Microcontroller board
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  4. Traffic Light

    • Description: Traffic light module with three LEDs
    • Pins: Green, Yellow, Red, GND

Wiring Details

RFID-RC522

Tower Pro SG90 Servo

Arduino UNO

Traffic Light

Documented Code

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

// Define pins
#define RST_PIN 9
#define SS_PIN 10
#define RED_LED 7
#define GREEN_LED 6
#define YELLOW_LED 8
#define SERVO_PIN 3
#define VEHICLE_SENSOR_PIN 2 // Sensor to detect vehicle crossing

// RFID setup
MFRC522 rfid(SS_PIN, RST_PIN);

// Servo setup
Servo barrierServo;

// Authorized UID (modify with your RFID tag UID)
byte authorizedUID[] = {0xDE, 0xAD, 0xBE, 0xEF};

void setup() {
  // Initialize serial monitor
  Serial.begin(9600);

  // Initialize SPI and RFID module
  SPI.begin();
  rfid.PCD_Init();
  Serial.println("RFID Barrier System Initialized");

  // Setup LEDs
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(YELLOW_LED, OUTPUT);
  digitalWrite(RED_LED, HIGH);  // Red light on initially
  digitalWrite(GREEN_LED, LOW);
  digitalWrite(YELLOW_LED, LOW);

  // Setup vehicle sensor
  pinMode(VEHICLE_SENSOR_PIN, INPUT);

  // Setup servo
  barrierServo.attach(SERVO_PIN);
  barrierServo.write(0); // Barrier initially closed
}

void loop() {
  // Look for RFID cards
  if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
    // Check if the scanned card UID matches the authorized UID
    if (isAuthorized(rfid.uid.uidByte, rfid.uid.size)) {
      Serial.println("Access Granted");

      // Yellow light on to indicate processing
      digitalWrite(YELLOW_LED, HIGH);
      delay(1000);

      // Green light on, red light off
      digitalWrite(YELLOW_LED, LOW);
      digitalWrite(GREEN_LED, HIGH);
      digitalWrite(RED_LED, LOW);

      // Open the barrier
      barrierServo.write(90); // Adjust angle as needed

      // Wait for vehicle to cross
      while (digitalRead(VEHICLE_SENSOR_PIN) == LOW) {
        delay(100); // Polling vehicle sensor
      }

      // Close the barrier after vehicle crosses
      delay(1000); // Optional delay to ensure complete crossing
      barrierServo.write(0);

      // Restore light status
      digitalWrite(GREEN_LED, LOW);
      digitalWrite(RED_LED, HIGH);
    } else {
      Serial.println("Access Denied");

      // Flash red light
      for (int i = 0; i < 3; i++) {
        digitalWrite(RED_LED, LOW);
        delay(200);
        digitalWrite(RED_LED, HIGH);
        delay(200);
      }
    }

    // Halt communication with RFID card
    rfid.PICC_HaltA();
  }
}

// Function to check if UID matches the authorized UID
bool isAuthorized(byte *uid, byte uidSize) {
  if (uidSize != sizeof(authorizedUID)) {
    return false;
  }

  for (byte i = 0; i < uidSize; i++) {
    if (uid[i] != authorizedUID[i]) {
      return false;
    }
  }

  return true;
}

This code initializes the RFID reader, servo motor, and traffic light. It continuously checks for RFID cards and grants access if the card UID matches the authorized UID. The traffic light and servo motor are used to control the barrier and indicate the status of the system.