Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO-Based Automated Toll Booth with RFID, Ultrasonic Sensor, and GSM Module

Image of Arduino UNO-Based Automated Toll Booth with RFID, Ultrasonic Sensor, and GSM Module

Circuit Documentation

Summary

This circuit is designed to function as an automated toll booth system. It utilizes an Arduino UNO microcontroller to interface with various sensors and modules, including an RFID reader, ultrasonic sensor, IR sensor, servo motor, LCD display, GSM module, and an I2C module. The system detects vehicles, reads RFID cards for toll payment, and sends SMS notifications upon successful transactions.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • 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
  2. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  3. IR Sensor

    • Description: Infrared sensor for object detection.
    • Pins: out, gnd, vcc
  4. 16X2 LCD

    • Description: 16x2 character LCD display.
    • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
  5. SIM900A

    • Description: GSM module for SMS communication.
    • Pins: GND, DB9-3 (RXD), DB9-2 (TXD), 5V, 3VR, 5VR, 3VT, 5VT, VCC, Ring, RESTART, RESET, STATUS
  6. RFID-RC522

    • Description: RFID reader module.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  7. I2C Module

    • Description: I2C communication module.
    • Pins: SCL, SDA, VCC, GND
  8. 5V Battery

    • Description: Power supply.
    • Pins: positive, negative
  9. Servo

    • Description: Servo motor for gate control.
    • Pins: gnd, vcc, pulse

Wiring Details

Arduino UNO

  • 5V connected to:

    • RFID-RC522 VCC (3.3V)
    • Servo vcc
    • SIM900A VCC
    • I2C Module VCC
    • HC-SR04 Ultrasonic Sensor VCC
    • IR Sensor vcc
  • GND connected to:

    • RFID-RC522 GND
    • SIM900A GND
    • Servo gnd
    • I2C Module GND
    • HC-SR04 Ultrasonic Sensor GND
    • IR Sensor gnd
  • D3 connected to:

    • SIM900A 5VT
  • D2 connected to:

    • SIM900A 5VR
  • A4 connected to:

    • I2C Module SDA
  • A5 connected to:

    • I2C Module SCL
  • D13 connected to:

    • RFID-RC522 SCK
  • D12 connected to:

    • RFID-RC522 MISO
  • D11 connected to:

    • RFID-RC522 MOSI
  • D10 connected to:

    • RFID-RC522 SDA
  • D9 connected to:

    • RFID-RC522 RST
  • D7 connected to:

    • HC-SR04 Ultrasonic Sensor ECHO
  • D6 connected to:

    • HC-SR04 Ultrasonic Sensor TRIG
  • D5 connected to:

    • Servo pulse
  • D4 connected to:

    • IR Sensor out

5V Battery

  • negative connected to:

    • SIM900A GND
  • positive connected to:

    • SIM900A 5V

Code Documentation

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

// Pin Definitions
#define RST_PIN 9
#define SS_PIN 10
#define TRIG_PIN 6
#define ECHO_PIN 7
#define IR_PIN 4
#define SERVO_PIN 5
#define PAYMENT_BUTTON_PIN 2
#define RECHARGE_BUTTON_PIN 3

MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo gateServo;
LiquidCrystal_I2C lcd(0x27, 16, 2);

// GSM Module Pins
#define GSM_RX_PIN 8   // Changed to Pin 8
#define GSM_TX_PIN 9   // Changed to Pin 9
SoftwareSerial gsmSerial(GSM_RX_PIN, GSM_TX_PIN);

// Predefined RFID UID and Wallet Balances
const String validUIDs[] = {"F3E45216", "A1B2C3D4"}; // Add more RFID tags here
float walletBalances[] = {100.0, 50.0};             // Corresponding wallet balances
float tollFee = 10.0;                               // Fixed toll fee
const float rechargeAmount = 50.0;                 // Fixed recharge amount
const String phoneNumber = "+8801743648510";       // Recipient phone number

// Function Prototypes
bool detectVehicle();
String getCardID();
void openGate();
int findCardIndex(String cardID);
bool processPayment(int cardIndex);
void rechargeWallet(int cardIndex);
bool isButtonPressed(int pin);
void sendSMS(String message);
void checkGSM();

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  
  gsmSerial.begin(9600); // GSM baud rate (adjust if necessary)

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Toll Booth Ready");

  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(IR_PIN, INPUT);
  pinMode(PAYMENT_BUTTON_PIN, INPUT_PULLUP); // Payment button (not used anymore)
  pinMode(RECHARGE_BUTTON_PIN, INPUT_PULLUP); // Recharge button

  gateServo.attach(SERVO_PIN);
  gateServo.write(0); // Gate closed
  
  checkGSM(); // Check if GSM module is responding
}

void loop() {
  // Detect Vehicle with Ultrasonic Sensor
  if (detectVehicle()) {
    lcd.setCursor(0, 0);
    lcd.print("Vehicle Detected ");
    delay(500);

    // RFID Card Scan
    if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
      String cardID = getCardID();
      int cardIndex = findCardIndex(cardID);
      lcd.setCursor(0, 1);
      if (cardIndex != -1) {
        lcd.print("Card Valid      ");
        delay(1000);

        // Automatically process payment after valid card scan
        if (processPayment(cardIndex)) {
          openGate();
          sendSMS("Your toll fee is paid. Thank you."); // Send SMS on successful payment
        } else {
          lcd.setCursor(0, 1);
          lcd.print("Payment Failed  ");
          delay(2000);
        }
      } else {
        lcd.print("Access Denied   ");
        delay(2000);
      }
    }
    mfrc522.PICC_HaltA(); // Halt RFID communication
    lcd.clear();
  }

  // Check if the recharge button is pressed
  if (isButtonPressed(RECHARGE_BUTTON_PIN)) {
    lcd.clear();
    lcd.print("Place Card to");
    lcd.setCursor(0, 1);
    lcd.print("Recharge...");

    if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
      String cardID = getCardID();
      int cardIndex = findCardIndex(cardID);
      if (cardIndex != -1) {
        rechargeWallet(cardIndex);
      } else {
        lcd.setCursor(0, 1);
        lcd.print("Invalid Card    ");
        delay(2000);
      }
    }
    mfrc522.PICC_HaltA();
    lcd.clear();
    lcd.print("Toll Booth Ready");
  }
}

// Function Definitions
bool detectVehicle() {
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, HIGH);
  long duration = pulseIn(ECHO_PIN, HIGH);
  int