top of page
Writer's pictureSanskruti Ashtikar

Electronic Toll Collection System Using 8051 Microcontroller

Updated: 2 days ago

Introduction


An Electronic Toll Collection (ETC) system automates the process of collecting tolls from vehicles on highways or toll roads. It enhances the efficiency of toll collection, reduces congestion, and minimizes the need for manual intervention. This article explores the design and implementation of an ETC system using the 8051 microcontroller, RFID technology, and basic display and control components.





Components Required


  1. 8051 Microcontroller: The central processing unit of the project.

  2. RFID Reader and Tags: For vehicle identification and toll processing.

  3. LCD Display: To show toll amount and transaction status.

  4. Relay Module: To control the barrier or gate.

  5. Buzzer: For auditory feedback during transactions.

  6. LEDs: To indicate the status of the system (e.g., toll paid or unpaid).

  7. Power Supply: To provide necessary voltage to the circuit.

  8. Programming Cable and Software: For uploading code to the microcontroller.

  9. Resistors, Capacitors, and other Passive Components: For building the supporting circuitry.


Working Principle


The ETC system uses an RFID reader to scan RFID tags on vehicles, which contain unique identification numbers. The microcontroller processes the scanned ID, checks it against a database of registered vehicles, and determines the appropriate toll amount. The system then displays the amount and status on an LCD, activates a relay to open or close a barrier, and provides feedback through a buzzer and LEDs.


Circuit Design


  1. Microcontroller (8051): The main controller interfacing with the RFID reader, LCD, relay, buzzer, and LEDs.

  2. RFID Reader: Connected to the microcontroller via UART for scanning RFID tags.

  3. LCD Display: Shows the toll amount and transaction status.

  4. Relay Module: Controls the barrier or gate mechanism.

  5. Buzzer and LEDs: Provide visual and auditory feedback.


Circuit Diagram

Here's a simplified connection outline:

  • 8051 Microcontroller Pins:

  • P0: Connected to the LCD data lines.

  • P1: LCD control lines (RS, RW, EN).

  • P2.0: Connected to the relay module for the barrier.

  • P2.1: Connected to the buzzer.

  • P2.2: Connected to a green LED (for successful transactions).

  • P2.3: Connected to a red LED (for failed transactions).

  • RXD (P3.0) and TXD (P3.1): Connected to the RFID reader.


Software Implementation


  1. Initializing I/O Ports: Set up ports for controlling the LCD, relay, buzzer, and LEDs.

  2. UART Communication: Read data from the RFID reader using the UART.

  3. Toll Processing: Determine the toll amount based on the scanned RFID tag.

  4. Display Update: Show the toll amount and transaction status on the LCD.

  5. Barrier Control: Activate the relay to open or close the barrier.

  6. Feedback Mechanism: Use the buzzer and LEDs to provide feedback.



#include <reg51.h>
#include <stdio.h>
#include <string.h>
#define LCD_PORT P0
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P1^2;
sbit RELAY = P2^0;
sbit BUZZER = P2^1;
sbit GREEN_LED = P2^2;
sbit RED_LED = P2^3;
void delay(unsigned int time);
void lcd_init(void);
void lcd_cmd(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_string(char *str);
void uart_init(void);
void uart_tx(char data);
char uart_rx(void);
void process_toll(char *id);
char registered_ids[5][12] = {
    "1234567890AB",
    "0987654321CD",
    "112233445566",
    "AABBCCDDEEFF",
    "FFEEDDCCBBAA"
};
void main(void) {
    char tag[12];
    unsigned char i;
    lcd_init(); // Initialize LCD
    uart_init(); // Initialize UART
    lcd_string("Electronic Toll");
    delay(2000);
    lcd_cmd(0x01); // Clear LCD display
    while (1) {
        lcd_cmd(0x01); // Clear LCD display
        lcd_string("Scan your RFID");
        lcd_cmd(0xC0); // Move to second line
        // Read RFID tag
        for (i = 0; i < 12; i++) {
            tag[i] = uart_rx();
        }
        tag[12] = '\0'; // Null-terminate the string
        process_toll(tag); // Process the toll for the read ID
    }
}


// Function to initialize LCD
void lcd_init(void) {
    lcd_cmd(0x38); // 8-bit mode, 2 lines, 5x7 matrix
    lcd_cmd(0x0C); // Display ON, cursor OFF
    lcd_cmd(0x06); // Increment cursor
    lcd_cmd(0x01); // Clear display
    delay(10);
}
// Function to send command to LCD
void lcd_cmd(unsigned char cmd) {
    LCD_PORT = cmd; // Send command to data pins
    RS = 0; // Command mode
    RW = 0; // Write operation
    EN = 1; // Enable pulse
    delay(1);
    EN = 0;
}
// Function to send data to LCD
void lcd_data(unsigned char data) {
    LCD_PORT = data; // Send data to data pins
    RS = 1; // Data mode
    RW = 0; // Write operation
    EN = 1; // Enable pulse
    delay(1);
    EN = 0;
}
// Function to display string on LCD
void lcd_string(char *str) {
    int i;
    for (i = 0; str[i] != '\0'; i++) {
        lcd_data(str[i]);
    }
}
// Function to initialize UART
void uart_init(void) {
    TMOD = 0x20; // Timer1 in Mode2
    TH1 = 0xFD; // Baud rate 9600
    SCON = 0x50; // 8-bit UART mode
    TR1 = 1; // Start Timer1
}
// Function to transmit data via UART
void uart_tx(char data) {
    SBUF = data; // Load data into UART buffer
    while (TI == 0); // Wait until transmission is complete
    TI = 0; // Clear transmission interrupt flag
}
// Function to receive data via UART
char uart_rx(void) {
    while (RI == 0); // Wait until data is received
    RI = 0; // Clear reception interrupt flag
    return SBUF; // Return received data
}
// Function to process the toll based on the read ID
void process_toll(char *id) {
    unsigned char i;
    bit access_granted = 0;
    for (i = 0; i < 5; i++) {
        if (strcmp(id, registered_ids[i]) == 0) {
            access_granted = 1;
            break;
        }
    }


    if (access_granted) {
        lcd_cmd(0x01); // Clear LCD display
        lcd_string("Toll: $1.00");
        RELAY = 1; // Open barrier
        GREEN_LED = 1; // Turn on green LED
        delay(5000); // Keep barrier open for 5 seconds
        RELAY = 0; // Close barrier
        GREEN_LED = 0; // Turn off green LED
    } else {
        lcd_cmd(0x01); // Clear LCD display
        lcd_string("Toll: $0.00");
        RED_LED = 1; // Turn on red LED
        BUZZER = 1; // Sound buzzer
        delay(2000); // Keep buzzer on for 2 seconds
        BUZZER = 0; // Turn off buzzer
        RED_LED = 0; // Turn off red LED
    }
}
// Delay function
void delay(unsigned int time) {
    int i, j;
    for (i = 0; i < time; i++)
        for (j = 0; j < 1275; j++);
}

Explanation


  1. UART Communication: The RFID reader communicates with the 8051 microcontroller using UART. The uart_init, uart_tx, and uart_rx functions handle initialization and data transmission/reception.

  2. Toll Processing: The process_toll function checks if the scanned RFID tag is in the list of registered IDs. If it matches, the barrier opens, and the toll amount is displayed. If it does not match, access is denied, and a buzzer sounds.

  3. Display Messages: The LCD displays the toll amount and transaction status. The lcd_init, lcd_cmd, lcd_data, and lcd_string functions handle LCD initialization and data display.

  4. Barrier and Feedback Control: The relay controls the barrier or gate mechanism. The buzzer and LEDs provide feedback about the transaction status.





Conclusion


Implementing an Electronic Toll Collection system using the 8051 microcontroller offers a practical approach to automating toll collection and vehicle management. The project demonstrates the integration of RFID technology with microcontroller-based systems and highlights how to manage real-time transactions and access control. This system can be extended with additional features such as dynamic toll calculation, integration with payment gateways, or remote monitoring for comprehensive toll management.


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



0 views0 comments

Related Posts

See All

Comments


bottom of page