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

Arduino UNO RFID-Based Parking Access Control with IR Sensors and Servo Gate

View and Edit Project In Cirkit DesignerImage of Arduino UNO RFID-Based Parking Access Control with IR Sensors and Servo Gate

Circuit Documentation

Summary of the Circuit

This circuit is designed to manage a parking system with an RFID-based entry control, vehicle type detection, and parking space monitoring. It uses an Arduino UNO as the central microcontroller to interface with various sensors and peripherals, including IR sensors for vehicle detection, an RFID reader for access control, a servo motor to operate a gate, a buzzer for audible alerts, and an I2C LCD for displaying information.

Component List

Arduino UNO

RFID-RC522

IR Sensors

Servo

16x2 I2C LCD

MKE-S04 IR Infrared Flame Sensor

Buzzer

Wiring Details

Arduino UNO

RFID-RC522

IR Sensors

Servo

16x2 I2C LCD

MKE-S04 IR Infrared Flame Sensor

Buzzer

Documented Code

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

// Pin Definitions
#define RST_PIN 9 // Reset Pin for RFID
#define SS_PIN 10 // Slave Select Pin for RFID
#define BUZZER_PIN 3 // Buzzer Pin
#define SERVO_PIN 5 // Servo Motor Pin for Gate
#define LED_PIN 6 // LED for indication

// IR Sensor Pins (5 for 2-wheelers, 3 for 3-wheelers, 2 for 4-wheelers)
int IR_SENSOR_PINS[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; 
int laneIRSensorPins[] = {12, 13, A0}; // IR sensors in the dedicated lane

int parkingSpots[3] = {5, 3, 2}; // Available parking spots for 2W, 3W, 4W

// RFID Setup
MFRC522 rfid(SS_PIN, RST_PIN); // Create MFRC522 instance

// LCD Setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD with I2C address 0x27

// Servo Setup
Servo gateServo;

// Variables for traffic monitoring
int vehicleCountLane = 0; // Vehicle count in the lane
int trafficDensity = 0; // Traffic density (0: low, 1: medium, 2: high)
unsigned long lastTimeChecked = 0;
unsigned long trafficCheckInterval = 5000; // Interval to check traffic density (5 seconds)

// Define valid RFID tags
String validRFIDTag[] = {"123456789", "987654321", "112233445"};  // Example valid RFID tags

void setup() {
  // Initialize LCD
  lcd.begin(16, 2);  // 16 columns, 2 rows (standard for most LCDs)
  lcd.backlight();

  // Initialize RFID
  SPI.begin();
  rfid.PCD_Init();

  // Initialize Buzzer
  pinMode(BUZZER_PIN, OUTPUT);

  // Initialize IR sensor pins
  for (int i = 0; i < sizeof(IR_SENSOR_PINS) / sizeof(IR_SENSOR_PINS[0]); i++) {
    pinMode(IR_SENSOR_PINS[i], INPUT);
  }

  // Initialize Lane IR sensor pins
  for (int i = 0; i < sizeof(laneIRSensorPins) / sizeof(laneIRSensorPins[0]); i++) {
    pinMode(laneIRSensorPins[i], INPUT);
  }

  // Initialize Servo
  gateServo.attach(SERVO_PIN);
  gateServo.write(0); // Close gate initially

  // Start with displaying welcome message
  lcd.setCursor(0, 0);
  lcd.print("Welcome to Parking");
  delay(2000);
  lcd.clear();
}

void loop() {
  // Check for RFID tag
  if (rfid.PICC_IsNewCardPresent()) {
    if (rfid.PICC_ReadCardSerial()) {
      String rfidTag = "";
      for (byte i = 0; i < rfid.uid.size; i++) {
        rfidTag += String(rfid.uid.uidByte[i], HEX);
      }
      rfidTag.toUpperCase();

      // Validate RFID tag
      if (isValidRFID(rfidTag)) {
        // Identify vehicle type and guide to parking
        int vehicleType = getVehicleType(rfidTag); // 1=2-wheeler, 2=3-wheeler, 3=4-wheeler
        guideToParking(vehicleType);

        // Control gate
        gateServo.write(90); // Open gate
        delay(5000); // Give time to pass
        gateServo.write(0); // Close gate

      } else {
        // Invalid RFID
        triggerBuzzer();
      }
    }
  }

  // Detect parking space occupancy (check IR sensor status)
  checkParkingStatus();

  // Monitor traffic flow in the lane and update traffic density
  monitorTrafficFlow();

  // Wait for next RFID scan
  delay(1000);
}

bool isValidRFID(String tag) {
  for (int i = 0; i < sizeof(validRFIDTag) / sizeof(validRFIDTag[0]); i++) {
    if (validRFIDTag[i] == tag) {
      return true;
    }
  }
  return false;
}

int getVehicleType(String rfidTag) {
  // Logic to determine vehicle type based on RFID tag (could be from database)
  if (rfidTag == "123456789") return 1; // 2-wheeler
  if (rfidTag == "987654321") return 2; // 3-wheeler
  return 3; // 4-wheeler
}

void guideToParking(int vehicleType) {
  // Display parking guidance on LCD
  lcd.clear();
  if (vehicleType == 1) {
    lcd.print("2-Wheeler Park A");
    if (parkingSpots[0] > 0) {
      parkingSpots[0]--;
    }
  } else if (vehicleType == 2) {
    lcd.print("3