Automated Gate System Arduino

The Smart Toll Tax System using RFID and Arduino is developed to automate and simplify the toll collection process, eliminating the need for manual intervention. Conventional toll booths often lead to traffic congestion and delays, especially during peak hours, and are vulnerable to human error. This system utilizes RFID technology integrated with an Arduino to create a contactless and efficient toll management solution. When a vehicle approaches the toll gate, the RFID reader scans its tag. If a valid RFID card is detected, the gate opens automatically, and the message “Access Granted” is displayed on the serial monitor. If the card is unauthorized or absent, the gate remains closed, and the message “Access Denied” is shown. This automated approach speeds up toll processing and ensures that only authorized vehicles are allowed access.
Access Granted:
- Displays "Access Granted" on the Serial monitor.
- Green led turns on signifying The keycard is valid.
- Servo motor turns 90 degrees up opening the "gate".
Access Denied:
- Displays "Access Denied" on the Serial monitor.
- Red led turns on signifying The keycard is invalid.
- Servo motor doesn't turn.
Supplies

Distance Sensor

In order to calculate the amount of distance between an object and the sensor we can use a distance sensor.
It has 4 pins.
- Vcc - 5v
- grnd - ground
- trig - 2 *You can choose any pin make sure to change it in the code
- echo - 3 *You can choose any pin make sure to change it in the code
RFID SENSOR


- Vcc - 3.3V Postive
- Grnd - Negative
- RST/Reset RST - 9
- SPI SS SDA(SS) - 10
- SPI MOSI MOSI - 11
- SPI MISO MISO - 12
- SPI SCK SCK - 13
SERVO


Servo allows the gate to move 180 degrees down or up.
Pins:
- 5v
- Ground
- Signal - pin 5 (PWM)
LIBRARY FOR RFID
To use the RFID you need to install the library for the card in order to get its UID number attached with the sensor.
METHOD 1:
Go to https://www.arduinolibraries.info/libraries/mfrc522.
- Download the library,
- Unzip it
- Drag it into your Arduino library folder
- Go into Arduino - File - Libraries - Scroll down until you find Dump Info
METHOD 2:
Put in this code to receive the id.
Run the code and make sure your RFID sensor is attached with the Arduino correctly.
Upload the code and put your keycard onto the sensor, once done it will display a 8 digit number sequence which you will copy and paste into the code where the comment says "Paste your id here".
Full code:
RFID LIBRARY EXPLANATION
Explanation of RFID Library:
Broken down code (Explained):
Reading the UID of an RFID Card:
Each RFID card or tag contains a unique identifier known as the UID. You can retrieve and display this UID using the MFRC522 library. The following code snippet demonstrates how to read the UID, which can then be used to create a list of authorized cards.
Required Libraries and Setup:
The code relies on the SPI library to use SPI communication and MFRC522 library to work with the RFID module.
- It declares SS_PIN and RST_PIN as the Slave Select and Reset pins of RFID module. Then an instance of mfrc522 object is created in order to control all the operations of RFID.
Setup:
In the setup () routine, the program starts by enabling serial communication and enabling SPI interface. It then makes a call to PCD_Init() to initialize the RFID reader. A bright message is presented to notify the user to bring an RFID tag to close to the reader.
Card detection:
Under the loop () method, the computer program first checks whether a new card in RFID using PICC_IsNewCardPresent (). In the case of the card not being found, the function leaves immediately to avoid any unnecessary processing.
Card selection:
Once a card is detected, PICC_ReadCardSerial() function thus attempts to select it and read its unique identifier (UID). In case this does not happen, the function dies without proceeding further.
Displaying and processing the UID:
Here, the code creates a string variable called content with the conversion of UID into a readable hexadecimal pattern and displaying the content on the Serial Monitor. It traverses all the bytes of the UID and adds them to the content string. This number is the identifier of RFID card.
Control logic:
It is used by the program to ensure that the UID of the card being scanned is equal to a reserved one (BD 31 15 2B). When the UID ends up with the same pair, it prints Authorized access; otherwise it prints Access denied. In this section, you can modify the UID in order to reflect certain cards which you would like to authorize. The delay(3000) instruction pauses the program for 3Second before going on with it.
Explanation: RFID to Components
Distance sensor:
- This checks if an object (likely the RFID card or hand) is within 5 inches of the sensor.
- If true (i.e., close enough), the code proceeds to check the card’s UID.
UID ID Paste:
- This line compares the scanned UID (stored as a string in content) to a specific value ("45 5F AF 15").
- substring(1) skips the first character—often used to remove any leading whitespace or unwanted character.
- If the UID matches, the card is authorized.
Access authorized:
- Prints "Authorized access" to the Serial Monitor.
- Turns on the green LED (gled) to indicate success.
- Waits 3 seconds with delay(3000).
- Prints a blank line (Serial.println();) for spacing/output formatting.
To move the Servo:
- Rotates the servo motor to 90 degrees—this likely unlocks a door or opens a barrier.
- Waits for 3 seconds.
- Then returns the servo to 0 degrees (initial position).
- Turns off the green LED.
Access denied:
If the UID does not match the authorized one:
- Prints "Access denied".
- Waits 3 seconds.
- Blinks the red LED (rled) once: ON for 1.5 seconds, OFF for 1.5 seconds, then ON again.
This visually indicates unauthorized access.
IF your too far away:
If the object is not within 5 inches (inch >= 5):
- Displays "GET CLOSER" on the Serial Monitor.
- Waits 3 seconds before restarting the loop.
- This encourages the user to bring their RFID tag or hand closer to the reader/sensor.
Full CODE
Functionality of the Automated Gate System Using Arduino Uno
Once the hardware is assembled and the code uploaded, the Smart Toll Tax System is ready for operation. Here’s how it functions:
- RFID Card Scanning: When an RFID card is brought near the RFID reader, the system scans the card’s UID and checks it against a list of authorized entries.
- Authorized Card: If the UID matches one from the authorized list, the servo motor activates and opens the toll gate. The green LED turns on signifying "Access Granted". After a 3-second delay, the gate automatically closes.
- Unauthorized Card: If the UID does not match any authorized entries, the gate stays closed, and the red LED turns on signifying "Access Denied".