This week's assignment is about Embedded Networking and Communications. I am using an Arduino UNO to create an RFID Door Lock System.Itβs a fun and secure way to unlock the door.
An RFID Door Lock System
RFID uses electromagnetic waves in the radio frequency spectrum for communication and data transfer. RFID tags are used in many industries and we can find them in product tags from stores to security access cards. RFID tags can expedite the checkout and can be used for antitheft measures.
Components of an RFID System An RFID system typically consists of several main components, each playing a different role in the system.
Component | Description |
---|---|
RFID Tag | Used to store and transmit information. |
RFID Reader | Reads the data from the RFID tag by emitting radio waves. It communicates with a microcontroller or computer. |
Antenna | Transmits and receives radio waves between the RFID tag and reader, influencing the system's range and performance. |
Middleware | Software that manages and processes the data between the RFID system and application, facilitating communication with the database. |
Software | Used to process and manage the data from RFID tags and integrate it into applications (e.g., security, inventory management). |
Database | Stores the RFID tag information and related data, enabling real-time updates and retrieval of relevant data for processing. |
Power Supply | Provides necessary power for the RFID system, especially for active tags and readers. |
The RC522 RFID is a popular RFID reader/writer module that communicates with microcontrollers like Arduino. It uses the MFRC522 chip and supports reading and writing of 13.56 MHz RFID cards/tags.
RC522 RFID Module Pins and Descriptions
Pin | Description |
---|---|
SDA / SCL | I2C Communication pins: Data (SDA) and Clock (SCL). |
SS / SCK / MOSI / MISO | SPI Communication pins: Slave Select (SS), Clock (SCK), Master Out Slave In (MOSI), and Master In Slave Out (MISO). |
RX / TX | UART Communication pins for serial data transmission. |
IRQ | Interrupt signal from the module to indicate RFID tag detection. |
GND | Ground pin that needs to be connected to the GND pin on the Arduino. |
RST | Reset pin for the module. |
VCC | Supply pin for the module. The supply voltage ranges from 2.5V to 3.3V and must be connected to the 3.3V pin on the Arduino. |
RC522 RFID Reader/Writer Module|Parts&Circuit Diagram
RFID Module & Arduino Uno Board & RFID Key Tag & Relay Module & I2C LCD1602 & Breadboard & Jumper Wires
RFID Module | Arduino Uno |
---|---|
3.3V | 3.3V |
GND | GND |
RST | 2 |
SDA (SS) | 10 |
MOSI | 11 |
MISO | 12 |
SCK | 13 |
IRQ | 7 |
I2C LCD1602 | Arduino Uno |
---|---|
GND | GND |
VCC | 5V |
SDA | A4 |
SCL | A5 |
Relay Module | Arduino Uno |
---|---|
SIG | 8 |
VCC | 5V |
GND | GND |
MFRC522
.Notes:Place the RFID key tag near the center of the reader
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 2
MFRC522 rfid(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
Serial.println("Scan RFID Card...");
}
void loop() {
if (!rfid.PICC_IsNewCardPresent()) {
return;
}
if (!rfid.PICC_ReadCardSerial()) {
return;
}
Serial.print("Card ID: ");
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
rfid.PICC_HaltA();
}
β π‘ Serial Debugging: Viewing scanned card IDs in the Serial Monitor.
Card ID 1: 73 B2 63 D
Card ID 2: D3 E1 5C A3
Serial Monitor Output | Possible Issue | Suggested Solution |
---|---|---|
β ERROR: RFID module not detected | Wiring issue or incorrect power supply | ensure standard SPI pins and 3.3V power are used |
No card detected | No RFID card detected near reader | Try a different RFID card, adjust scanning angle, or ensure the card is 13.56MHz. |
Failed to read card | Read failure due to card or hardware issue | Try another card, adjust timing (add delay), or test another RFID module. |
Card ID: xx xx xx xx | Success | π RFID card read successfully. Use this ID for verification logic. |
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 2
#define RELAY_PIN 8
MFRC522 rfid(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte allowedUID[4] = {0x73, 0xB2, 0x63, 0xD};
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
lcd.init();
lcd.backlight();
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
lcd.setCursor(0, 0);
lcd.print("Welcome !");
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
return;
}
bool isAuthorized = true;
for (byte i = 0; i < rfid.uid.size; i++) {
if (rfid.uid.uidByte[i] != allowedUID[i]) {
isAuthorized = false;
}
}
if (isAuthorized) {
digitalWrite(RELAY_PIN, HIGH);
lcd.setCursor(0, 1);
lcd.print("Welcome home !");
delay(2000);
digitalWrite(RELAY_PIN, LOW);
} else {
lcd.setCursor(0, 1);
lcd.print("Unknown Guy !");
delay(2000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome !");
rfid.PICC_HaltA();
}
Run Steps
Run Results
At the beginning, we can see "Welcome!" displayed on the I2C LCD1602.
Swipe Card 1, and the relay's normally open contact will activate. The LCD will display:
After two seconds, it will return to displaying "Welcome!".
Swipe Card 2, and if the ID is incorrect, the relay's normally open contact will deactivate. The LCD will display:
After two seconds, it will return to displaying "Welcome!".
This project demonstrates how RFID technology can be used for access control. The combination of an RFID reader, LCD display, and relay allows for a secure and user-friendly door lock system.
Tools β Board
and select your Arduino Uno.Tools β Port
and select the correct port COM5.Tools β Serial Monitor
.(shift+alt+M)