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

RFID-Enabled Automated Gate System with Ultrasonic Vehicle Detection

View and Edit Project In Cirkit DesignerImage of RFID-Enabled Automated Gate System with Ultrasonic Vehicle Detection

Circuit Documentation

Summary

This circuit is designed to control access through a gate using an RFID system and monitor the exit using an ultrasonic sensor. The main controller is an Arduino UNO, which interfaces with an RFID-RC522 module for scanning RFID tags, two servo motors for operating the entry and exit gates, and an HC-SR04 ultrasonic sensor for detecting the presence of a vehicle at the exit. The circuit also includes LEDs to indicate the status and a pushbutton for manual input.

Component List

RFID-RC522

Arduino UNO

Servo (x2)

HC-SR04 Ultrasonic Sensor

LED: Two Pin (green)

LED: Two Pin (red)

Pushbutton

Resistor (200 Ohms)

Resistor (220 Ohms)

Wiring Details

RFID-RC522

Arduino UNO

Servo (Entry Gate)

Servo (Exit Gate)

HC-SR04 Ultrasonic Sensor

LED: Two Pin (green)

LED: Two Pin (red)

Pushbutton

Resistor (200 Ohms)

Resistor (220 Ohms)

Documented Code

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

#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN);
Servo gateServo;
Servo exitServo;

// Ultrasonic Sensor pins
const int trigPin = 7;
const int echoPin = 8;
const long maxDistance = 30; // Maximum distance to detect vehicle (in cm)

String authorizedCard = "1234567890"; // Replace this with the actual card UID

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();

  gateServo.attach(6); // Servo pin for gate
  exitServo.attach(5); // Servo pin for exit
  gateServo.write(0); // Initial position (closed gate)
  exitServo.write(0); // Initial position

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  Serial.println("Place your card near the RFID reader...");
}

void loop() {
  // Look for new cards
  if ( !rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial() )
    return;

  String cardID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    cardID += String(rfid.uid.uidByte[i], HEX);
  }

  Serial.print("Card UID: ");
  Serial.println(cardID);

  // Check if card is authorized
  if (cardID.equalsIgnoreCase(authorizedCard)) {
    openGate();
  } else {
    Serial.println("Unauthorized card.");
  }

  // Check for exiting vehicle
  long distance = readUltrasonicDistance();
  if (distance > 0 && distance < maxDistance) {
    openExitGate();
  }

  rfid.PICC_HaltA(); // Halt PICC
}

void openGate() {
  Serial.println("Authorized card detected! Opening gate...");
  gateServo.write(90); // Open the gate by rotating the servo to 90 degrees
  delay(3000); // Keep gate open for 3 seconds
  gateServo.write(0); // Close the gate
  Serial.println("Gate closed.");
}

void openExitGate() {
  Serial.println("Vehicle detected! Opening exit gate...");
  exitServo.write(90); // Open the exit gate by rotating the servo to 90 degrees
  delay(5000); // Keep exit gate open for 5 seconds
  exitServo.write(0); // Close the exit gate
  Serial.println("Exit gate closed.");
}

long readUltrasonicDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long duration = pulseIn(echoPin, HIGH);
  long distance = (duration / 2) / 29.1; // Convert to cm

  return distance;
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the RFID reader and the servo motors, reads RFID tags, and operates the gates accordingly. It also reads the distance from the ultrasonic sensor to detect the presence of a vehicle at the exit gate.