Introduction
Security systems are essential for safeguarding homes, offices, and other premises. An RFID-based security system is a modern and effective solution that uses RFID (Radio Frequency Identification) technology to control access to secure areas. By integrating an RFID reader with a PIC microcontroller, you can create a system that allows access only to authorized users carrying an RFID card or tag. This article will guide you through the design, implementation, and programming of an RFID-based security system using a PIC microcontroller.
Components Required
PIC Microcontroller: PIC16F877A or a similar PIC microcontroller.
RFID Reader Module: 125kHz or 13.56MHz RFID reader compatible with the PIC microcontroller.
RFID Tags/Cards: Matching the frequency of the RFID reader.
LCD Display: 16x2 or similar for displaying system status.
Relay Module: For controlling door locks or other security mechanisms.
Buzzer: To provide audio feedback for access granted or denied.
LEDs: To indicate system status (e.g., power on, access granted/denied).
Power Supply: 5V DC regulated power supply.
Push Buttons: For system reset or manual override.
Connecting Wires, Resistors, and Capacitors: For assembling the circuit.
Enclosure: For housing the components securely.
System Overview
The RFID-based security system operates by reading RFID tags/cards and comparing the unique ID with a stored list of authorized IDs. If the ID is recognized, the system grants access by activating a relay that could control a door lock, and displays a message on the LCD. If the ID is not recognized, the system denies access and optionally sounds a buzzer. The system is designed to be user-friendly, secure, and easily customizable.
Circuit Diagram
Key Connections:
RFID Reader:
VCC to 5V power supply.
GND to ground.
TX (Data Out) to a digital input pin on the PIC (e.g., RC7/RX for UART communication).
LCD Display:
Data pins (D4-D7) connected to PIC port pins (e.g., RD4-RD7).
Control pins (RS, E) connected to PIC pins (e.g., RD0, RD1).
VCC to 5V, GND to ground, VEE to a variable resistor for contrast control.
Relay Module:
Control pin connected to a digital output pin of the PIC (e.g., RB0).
VCC to 5V, GND to ground.
NO (Normally Open) and COM (Common) connected to the door lock circuit.
Buzzer:
Positive pin to a digital output pin of the PIC (e.g., RB1).
Negative pin to ground.
LEDs:
Positive pin of each LED to a digital output pin of the PIC (e.g., RB2 for access granted, RB3 for access denied).
Negative pin to ground through a current-limiting resistor.
Microcontroller Configuration
The PIC microcontroller will handle communication with the RFID reader, process the data, and control the LCD, relay, buzzer, and LEDs. The microcontroller will use its UART module for communication with the RFID reader, making it easier to handle serial data.
Pin Configuration
RC7/RX: Serial input for RFID data.
RB0: Output to control the relay module.
RB1: Output to control the buzzer.
RB2: Output for the access granted LED.
RB3: Output for the access denied LED.
RD0-RD1: Control pins for the LCD.
RD4-RD7: Data pins for the LCD.
Sample Code
Here’s a simplified example code for the RFID-based security system using a PIC microcontroller:
#include <xc.h>
#include "lcd.h"
#define _XTAL_FREQ 4000000
#define RELAY RB0
#define BUZZER RB1
#define LED_GRANT RB2
#define LED_DENY RB3
char rfid[12]; // To store RFID tag/card data
char authorizedIDs[3][12] = {
"1234567890AB", // Example authorized IDs
"9876543210AB",
"A1B2C3D4E5F6"
};
void main(void) {
// Initialize modules
LCD_Init();
UART_Init(9600); // Initialize UART for RFID communication
TRISB = 0x00; // Set PORTB as output
while(1) {
LCD_Clear();
LCD_Set_Cursor(1,1);
LCD_Write_String("Scan RFID Card");
// Read RFID data
for(int i = 0; i < 12; i++) {
rfid[i] = UART_Read(); // Read RFID data from UART
}
rfid[12] = '\0'; // Null-terminate the string
// Check if the RFID is authorized
int authorized = 0;
for(int i = 0; i < 3; i++) {
if(strcmp(rfid, authorizedIDs[i]) == 0) {
authorized = 1;
break;
}
}
if(authorized) {
LCD_Clear();
LCD_Set_Cursor(1,1);
LCD_Write_String("Access Granted");
RELAY = 1; // Activate the relay to unlock the door
LED_GRANT = 1; // Turn on access granted LED
__delay_ms(5000); // Keep door unlocked for 5 seconds
RELAY = 0; // Lock the door
LED_GRANT = 0; // Turn off the LED
} else {
LCD_Clear();
LCD_Set_Cursor(1,1);
LCD_Write_String("Access Denied");
BUZZER = 1; // Sound the buzzer
LED_DENY = 1; // Turn on access denied LED
__delay_ms(2000); // Buzzer and LED on for 2 seconds
BUZZER = 0;
LED_DENY = 0;
}
__delay_ms(1000); // Wait before the next scan
}
}
Working of the System
RFID Tag/Card Detection: The system waits for an RFID tag or card to be scanned. When a tag is brought close to the RFID reader, the reader sends the unique ID of the tag to the PIC microcontroller via UART.
Data Processing: The microcontroller reads the RFID data and compares it with a list of authorized IDs stored in memory.
Access Decision:
Access Granted: If the ID matches an authorized entry, the microcontroller activates the relay, unlocking the door, and lights the access granted LED. The LCD displays "Access Granted" and the buzzer remains silent.
Access Denied: If the ID does not match any authorized entry, the microcontroller activates the buzzer, lights the access denied LED, and displays "Access Denied" on the LCD.
Reset and Wait: After granting or denying access, the system resets and waits for the next RFID scan.
Testing and Calibration
RFID Reader Testing: Test the RFID reader to ensure it correctly reads tags/cards from various distances and angles.
System Response Testing: Verify the system's response time for both authorized and unauthorized tags. Ensure the relay, buzzer, and LEDs activate correctly.
Data Integrity: Ensure the RFID data is read and processed accurately. Verify that authorized IDs are correctly stored and matched.
Power Supply Stability: Test the system's stability under different power conditions to ensure reliable operation.
Additional Features
To enhance the functionality of the RFID-based security system, consider adding:
Real-Time Clock (RTC): Integrate an RTC to log the time and date of each access attempt.
EEPROM Storage: Store authorized IDs in an external EEPROM for easy updating and memory expansion.
Wireless Communication: Add a GSM or Wi-Fi module to send alerts or logs to a remote server or mobile device.
Biometric Integration: Combine RFID with biometric verification (e.g., fingerprint) for enhanced security.
User Interface: Add a keypad or touchscreen for manual input or system configuration.
Conclusion
An RFID-based security system using a PIC microcontroller is a practical and effective solution for controlling access to secure areas. This guide provides a foundation for building a basic system, with opportunities for further enhancements and customization depending on specific security needs.
References
PIC16F877A Datasheet: Microchip
RC522 RFID Module Documentation: Datasheet
MPLAB X IDE: Microchip
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
Comments