Build an Arduino Automated Toll Gate System (RFID + IR)

Published: (December 28, 2025 at 02:44 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

🚗 Introduction

In an era where automation is revolutionising everyday systems, building an Automatic Toll Gate System with Arduino is both a practical and educational project. Designed to remove manual toll collection, this system uses simple sensors and RFID technology to create a smart, contactless tolling solution ideal for hobbyists, students, and makers.

Automatic Toll Gate Overview

📈 How It Works: Step‑by‑Step

1. Vehicle Detection

An infrared (IR) sensor mounted at the entrance detects when a vehicle approaches. This triggers the Arduino to begin the toll process.

2. RFID Verification

The system waits for the vehicle’s RFID card to be scanned. Each RFID card holds a unique identifier and a simulated balance stored in Arduino memory.

3. Card Validation

Once scanned:

  • The Arduino checks whether the RFID tag matches known cards.
  • It verifies if there’s sufficient balance to pay the toll.
  • If the balance is adequate, the toll amount is deducted.
  • Unauthorized or low‑balance cards trigger a denied‑access signal (red LED).

4. Gate Operation

Successful validation triggers:

  • The green LED to illuminate.
  • The servo motor to swing the gate open (≈ 90°).
  • After the vehicle clears the exit IR sensor, the gate closes again, and the system resets for the next vehicle.

Gate operation diagram

LED Indicators

  • Green LED → D7
  • Red LED → D6
  • Both LEDs share ground.

IR Sensors

  • Entry IR → D2
  • Exit IR → D3
  • Both sensors connect to 5 V and ground.

Servo Motor

  • Servo signal → D5
  • 5 V power & ground → common rail

Wiring layout

💻 Arduino Code Explained

The sketch is organized into clear sections.

// Libraries
#include 
#include 
#include 

// Define pins, objects, and variables here
// ...

void setup() {
  Serial.begin(9600);
  SPI.begin();                // Init SPI bus
  rfid.PCD_Init();            // Init RFID reader
  pinMode(entryIRPin, INPUT);
  pinMode(exitIRPin, INPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  servo.attach(servoPin);
  servo.write(closedAngle);  // Start with gate closed
}

void loop() {
  // 1. Wait for vehicle entry (IR sensor)
  if (digitalRead(entryIRPin) == LOW) {
    // 2. Look for RFID card
    if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
      // 3. Validate card ID and balance
      //    (compare with stored IDs, deduct toll, etc.)
      // 4. Control LEDs and servo
      //    - Green LED on, servo opens
      //    - After exit IR triggers, close gate and reset
    }
  }
}

The code initializes serial monitoring, SPI communication, the RFID reader, I/O pins, and the servo. In the main loop it:

  1. Waits for the entry IR signal.
  2. Scans for a new RFID card.
  3. Checks the card ID against predefined tags, verifies balance, and updates LEDs/servo accordingly.
  4. Closes the gate when the exit IR sensor is triggered and resets for the next vehicle.

🛠 Troubleshooting Tips

  • RFID not detecting cards?
    Ensure the RFID reader receives proper 3.3 V power and that the wiring matches the SPI pin layout.

  • Servo jitter or no motion?
    Verify the servo has sufficient current supply and that the signal pin is correctly defined.

  • IR sensor too sensitive or erratic?
    Adjust the sensor position and consider adding small delays in the code to debounce false triggers.

🚀 Future Enhancements

  • Add an LCD display to show balance and status messages.
  • Integrate Wi‑Fi (ESP32/ESP8266) for cloud logging of transactions.
  • Develop a mobile app for real‑time balance checks and notifications.
  • Store transaction logs on an SD card or in a remote database.

🏁 Conclusion

The Automatic Toll Gate System Project Using Arduino is a powerful beginner‑friendly project that showcases how microcontrollers and sensors can automate real‑world processes like toll collection. From detecting vehicles to processing RFID payments and controlling gates, this project blends hardware and software in a fun learning experience.

Explore further enhancements such as LCD status displays or IoT connectivity to make your system even smarter!

Back to Blog

Related posts

Read more »