top of page
Writer's pictureSanskruti Ashtikar

RFID Based Access Control System Using 8051 Microcontroller

Introduction


An RFID-based access control system allows only authorized individuals to access restricted areas by using RFID technology. This article explores the design, components, and implementation of an RFID-based access control system using the 8051 microcontroller. The project uses an RFID reader to scan tags, a microcontroller to process the data, and a relay to control access.


Components Required


  1. 8051 Microcontroller: The core processing unit for the project.

  2. RFID Reader and Tags: For reading unique identification numbers.

  3. LCD Display: To display access status messages.

  4. Relay Module: To control the locking mechanism.

  5. Buzzer: To provide auditory feedback for access status.

  6. LEDs: Indicate the status of the system (access granted or denied).

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

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

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


Working Principle


The RFID reader reads the unique ID from an RFID tag and sends it to the 8051 microcontroller. The microcontroller compares the read ID with a list of authorized IDs stored in its memory. If the ID matches, access is granted by activating the relay to unlock the door, and the status is displayed on the LCD. If the ID does not match, access is denied, and the buzzer sounds an alarm.


Circuit Design


  1. Microcontroller (8051): The core of the project, interfaced with the RFID reader, LCD, relay, buzzer, and LEDs.

  2. RFID Reader: Connected to the microcontroller's serial port to read the tag ID.

  3. LCD Display: Shows messages such as "Access Granted" or "Access Denied."

  4. Relay Module: Controls the door locking mechanism.

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


Circuit Diagram

Here's a simplified connection outline:

  • 8051 Microcontroller Pins:

  • P0: Connected to the data lines of the LCD.

  • P1: Control lines for the LCD.

  • P2.0: Connected to the relay module.

  • P2.1: Connected to the buzzer.

  • P2.2 - P2.3: Connected to LEDs.

  • 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. ID Verification: Compare the read ID with a list of authorized IDs.

  4. Access Control Logic: Activate the relay if access is granted, otherwise sound the buzzer.

  5. Display Update: Show the access status on the LCD.


#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 check_access(char *id);
char authorized_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("RFID Access Ctrl");
    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
        check_access(tag); // Check access 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 check access for the read ID
void check_access(char *id) {
    unsigned char i;
    bit access_granted = 0;
    for (i = 0; i < 5; i++) {
        if (strcmp(id, authorized_ids[i]) == 0) {
            access_granted = 1;
            break;
        }
    }
    if (access_granted) {
        lcd_string("Access Granted");
        RELAY = 1; // Activate relay
        GREEN_LED = 1; // Turn on green LED
        delay(5000); // Keep relay activated for 5 seconds
        RELAY = 0; // Deactivate relay
        GREEN_LED = 0; // Turn off green LED
    } else {
        lcd_string("Access Denied");
        BUZZER = 1; // Sound buzzer
        RED_LED = 1; // Turn on red LED
        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 the UART protocol. The uart_init, uart_tx, and uart_rx functions handle the initialization and data transmission/reception.

  2. ID Verification: The check_access function compares the read ID with a list of authorized IDs stored in the microcontroller's memory. If a match is found, access is granted; otherwise, access is denied.

  3. Display Messages: The LCD display is used to show messages such as "Access Granted" or "Access Denied." The lcd_init, lcd_cmd, lcd_data, and lcd_string functions handle the initialization and data display on the LCD.

  4. Relay and Buzzer Control: The relay is activated to unlock the door if access is granted, while the buzzer sounds an alarm if access is denied. LEDs provide visual feedback for the access status.


Conclusion


Building an RFID-based access control system using the 8051 microcontroller is a practical project to learn about interfacing microcontrollers with RFID readers and output devices. The project demonstrates how to use RFID technology for secure access control and how to handle UART communication for reading tag IDs. This system can be further enhanced by adding features such as logging access attempts, integrating with a database for dynamic ID management, or adding wireless communication for remote monitoring and control.


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