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.
Arduino UNO
HC-SR04 Ultrasonic Sensor
IR Sensor
16X2 LCD
SIM900A
RFID-RC522
I2C Module
5V Battery
Servo
5V connected to:
GND connected to:
D3 connected to:
D2 connected to:
A4 connected to:
A5 connected to:
D13 connected to:
D12 connected to:
D11 connected to:
D10 connected to:
D9 connected to:
D7 connected to:
D6 connected to:
D5 connected to:
D4 connected to:
negative connected to:
positive connected to:
#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