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

Arduino UNO-Based RFID and Ultrasonic Sensor Automated Toll Gate with LED Indicators and Buzzer

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based RFID and Ultrasonic Sensor Automated Toll Gate with LED Indicators and Buzzer

Circuit Documentation

Summary

This circuit is designed to control a toll gate system using an Arduino UNO. The system includes an RFID reader for vehicle identification, an ultrasonic sensor for vehicle detection, LEDs for status indication, a buzzer for alerts, a servo motor to control the gate, and a toggle switch for manual override. The Arduino UNO serves as the central controller, interfacing with all the components and executing the control logic.

Component List

  1. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: Red LED for status indication.
    • Purpose: Indicates unauthorized access.
  2. LED: Two Pin (green)

    • Pins: cathode, anode
    • Description: Green LED for status indication.
    • Purpose: Indicates authorized access.
  3. Buzzer

    • Pins: PIN, GND
    • Description: Buzzer for alerting.
    • Purpose: Alerts on unauthorized access.
  4. Tower Pro SG90 Servo

    • Pins: Signal, +5V, GND
    • Description: Servo motor for gate control.
    • Purpose: Opens and closes the gate.
  5. HC-SR04 Ultrasonic Sensor

    • Pins: VCC, TRIG, ECHO, GND
    • Description: Ultrasonic sensor for vehicle detection.
    • Purpose: Detects the presence of a vehicle.
  6. RFID-RC522

    • Pins: SDA, SCK, MOSI, MISO, IRQ, GND, RST, 3.3V
    • Description: RFID reader for vehicle identification.
    • Purpose: Reads RFID tags for vehicle identification.
  7. Toggle Switch

    • Pins: L1, COM, L2
    • Description: Toggle switch for manual override.
    • Purpose: Allows manual control of the gate.
  8. Arduino UNO

    • 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
    • Description: Microcontroller board.
    • Purpose: Central controller for the circuit.
  9. Resistor (200 Ohms)

    • Pins: pin1, pin2
    • Description: Resistor for current limiting.
    • Purpose: Limits current to LEDs.

Wiring Details

LED: Two Pin (red)

LED: Two Pin (green)

Buzzer

Tower Pro SG90 Servo

HC-SR04 Ultrasonic Sensor

RFID-RC522

Toggle Switch

Arduino UNO

Resistor (200 Ohms)

Resistor (200 Ohms)

Code Documentation

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

#define TRIG_PIN 6
#define ECHO_PIN 7
#define SERVO_PIN 11
#define RED_LED_PIN 2
#define GREEN_LED_PIN 4
#define SWITCH_PIN 9
#define BUZZER_PIN 8
#define RST_PIN 3
#define SDA_PIN 10

Servo gateServo;
MFRC522 rfid(SDA_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(SWITCH_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  gateServo.attach(SERVO_PIN);
  gateServo.write(0); // Gate closed
}

void loop() {
  long duration, distance;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1;

  if (distance < 10) { // Vehicle detected
    if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
      Serial.println("RFID tag detected");
      digitalWrite(GREEN_LED_PIN, HIGH);
      digitalWrite(RED_LED_PIN, LOW);
      gateServo.write(90); // Open gate
      delay(5000); // Keep gate open for 5 seconds
      gateServo.write(0); // Close gate
      digitalWrite(GREEN_LED_PIN, LOW);
    } else {
      digitalWrite(RED_LED_PIN, HIGH);
      digitalWrite(GREEN_LED_PIN, LOW);
      digitalWrite(BUZZER_PIN, HIGH);
      delay(1000);
      digitalWrite(BUZZER_PIN, LOW);
    }
  } else {
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, LOW);
  }
  delay(100);
}

This code initializes the components and sets up the pins. In the loop function, it continuously checks for the presence of a vehicle using the ultrasonic sensor. If a vehicle is detected, it checks for an RFID tag. If an authorized RFID tag is detected, it opens the gate and turns on the green LED. If no RFID tag is detected, it turns on the red LED and activates the buzzer. The gate remains open for 5 seconds before closing.