Table of Contents
Project Overview
This smart door lock combines two authentication methods for enhanced security: fingerprint biometrics and RFID cards. Users can unlock the door using either method, or require both for high-security areas.
- Dual authentication: Fingerprint OR RFID
- Store up to 164 fingerprints
- Support multiple RFID cards
- Solenoid lock control via relay
- LCD status display
- Access log via Serial
- Admin mode for enrollment
Components Required
- Arduino Uno/Nano: Main microcontroller
- Optical Fingerprint Sensor (R307): Biometric authentication
- RC522 RFID Module: Card/tag reader
- 5V Solenoid Lock: Electromagnetic lock mechanism
- Relay Module: Control solenoid lock
- 16x2 LCD Display: User interface (I2C preferred)
- RFID Cards/Tags: For authentication
- Breadboard & Jumper Wires: For connections
- 5V Power Supply: For solenoid lock
- Push Button: For admin mode activation
Wiring Diagram
Connect all components to the Arduino:
Fingerprint Sensor (R307)
- VCC → 5V
- GND → GND
- Tx → Pin 2 (Software Serial Rx)
- Rx → Pin 3 (Software Serial Tx)
RC522 RFID Module
- 3.3V → 3.3V (Do NOT use 5V!)
- GND → GND
- RST → Pin 9
- SDA → Pin 10
- MOSI → Pin 11
- MISO → Pin 12
- SCK → Pin 13
Relay Module (Solenoid Lock)
- VCC → 5V
- GND → GND
- IN → Pin 7
- COM → 5V Power Supply
- NO → Solenoid Lock (+)
LCD Display (I2C)
- VCC → 5V
- GND → GND
- SDA → A4
- SCL → A5
Admin Button
- One leg → Pin 8
- Other leg → GND
Solenoid locks draw significant current (500mA+). Use a separate 5V power supply for the lock, not the Arduino's 5V pin. Connect grounds together for common reference.
Fingerprint Sensor Setup
First, enroll fingerprints using the Adafruit fingerprint library:
Install Libraries
// In Arduino IDE: Sketch → Include Library → Manage Libraries
// Search and install:
- Adafruit Fingerprint Sensor Library
- MFRC522 by GithubCommunity
- LiquidCrystal_I2C by Frank de Brabander
Enroll Fingerprints
Use the example sketch enroll from the Adafruit library:
File → Examples → Adafruit Fingerprint Sensor → enroll
// Upload and open Serial Monitor
// Follow prompts to place finger twice
// Note the ID number assigned (0, 1, 2, ...)
- Enroll the same finger multiple times (different IDs) for better recognition
- Clean the sensor surface before enrollment
- Use consistent finger placement
- Enroll fingers in different positions (slight rotations)
RFID Reader Setup
Read and store RFID card UIDs:
#include <MFRC522.h>
#include <SPI.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Scan RFID card to read UID...");
}
void loop() {
if (mfrc522.PICC_IsNewCardPresent() &&
mfrc522.PICC_ReadCardSerial()) {
String uid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
uid += String(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("Card UID: ");
Serial.println(uid);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
delay(2000);
}
}
Complete Arduino Code
Integrate both authentication methods:
#include <Adafruit_Fingerprint.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
// Pin definitions
#define FINGERPRINT_RX 2
#define FINGERPRINT_TX 3
#define RFID_RST 9
#define RFID_SS 10
#define RELAY_PIN 7
#define ADMIN_BUTTON 8
// Initialize components
SoftwareSerial fingerprintSerial(FINGERPRINT_RX, FINGERPRINT_TX);
Adafruit_Fingerprint fingerprint = Adafruit_Fingerprint(&fingerprintSerial);
MFRC522 mfrc522(RFID_SS, RFID_RST);
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Authorized users (add your IDs here)
int authorizedFingerprints[] = {0, 1, 2};
String authorizedRFID[] = {"a1b2c3d4", "e5f6g7h8"};
int numFingerprints = 3;
int numRFID = 2;
void setup() {
Serial.begin(9600);
// Initialize fingerprint sensor
fingerprint.begin(57600);
if (fingerprint.verifyPassword()) {
Serial.println("Fingerprint sensor found");
}
// Initialize RFID
SPI.begin();
mfrc522.PCD_Init();
Serial.println("RFID reader initialized");
// Initialize relay
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Lock engaged
// Initialize button
pinMode(ADMIN_BUTTON, INPUT_PULLUP);
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Smart Door Lock");
lcd.setCursor(0, 1);
lcd.print("Ready...");
delay(2000);
lcd.clear();
}
void loop() {
// Check for admin button
if (digitalRead(ADMIN_BUTTON) == LOW) {
adminMode();
delay(500);
}
// Check fingerprint
int fingerID = getFingerprintID();
if (fingerID >= 0 && isFingerprintAuthorized(fingerID)) {
unlockDoor("Fingerprint");
logAccess("Fingerprint", fingerID);
delay(5000);
}
// Check RFID
String rfidUID = getRFID();
if (rfidUID != "" && isRFIDAuthorized(rfidUID)) {
unlockDoor("RFID");
logAccess("RFID", rfidUID);
delay(5000);
}
lcd.setCursor(0, 0);
lcd.print("Waiting... ");
lcd.setCursor(0, 1);
lcd.print("Scan or Touch ");
}
int getFingerprintID() {
uint8_t p = fingerprint.getImage();
if (p != FINGERPRINT_OK) return -1;
p = fingerprint.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = fingerprint.fingerFastSearch();
if (p == FINGERPRINT_OK) {
return fingerprint.fingerID;
}
return -1;
}
String getRFID() {
if (mfrc522.PICC_IsNewCardPresent() &&
mfrc522.PICC_ReadCardSerial()) {
String uid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
uid += String(mfrc522.uid.uidByte[i], HEX);
}
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return uid;
}
return "";
}
bool isFingerprintAuthorized(int id) {
for (int i = 0; i < numFingerprints; i++) {
if (authorizedFingerprints[i] == id) return true;
}
return false;
}
bool isRFIDAuthorized(String uid) {
for (int i = 0; i < numRFID; i++) {
if (authorizedRFID[i] == uid) return true;
}
return false;
}
void unlockDoor(String method) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access Granted!");
lcd.setCursor(0, 1);
lcd.print(method);
digitalWrite(RELAY_PIN, LOW); // Unlock
Serial.print("UNLOCKED via ");
Serial.println(method);
}
void logAccess(String method, int id) {
Serial.print(millis());
Serial.print(" - ");
Serial.print(method);
Serial.print(": ");
Serial.println(id);
}
void adminMode() {
lcd.clear();
lcd.print("Admin Mode");
Serial.println("Admin mode activated");
// Add enrollment logic here
}
Security Considerations
Physical Security
- Use a secure enclosure for electronics
- Install backup power (battery)
- Add tamper detection switch
- Use security screws
Digital Security
- Store authorized IDs in EEPROM, not code
- Implement failed attempt limits
- Add timeout between attempts
- Log all access attempts
- Consider adding WiFi for remote alerts
- This system is for educational purposes
- For real security, use commercial-grade locks
- Always have a mechanical key backup
- Don't rely solely on electronic locks for high-security areas
Troubleshooting
Fingerprint Not Recognized
- Clean sensor surface
- Re-enroll fingerprints
- Check wiring (Tx/Rx swapped?)
- Verify power supply (5V stable)
RFID Not Reading
- Ensure 3.3V power (not 5V)
- Check SPI connections
- Move card closer to reader
- Remove metal objects nearby
Solenoid Not Activating
- Check separate power supply
- Verify relay connections
- Test relay with simple LED first
- Ensure common ground
Next Steps
Enhance your smart lock with these features:
- Add WiFi connectivity for remote monitoring
- Integrate with home automation (Home Assistant)
- Add keypad for PIN code backup
- Implement mobile app control
- Add camera for access photos
- Send notifications on unauthorized attempts
Related Articles:
Smart Home Temperature Monitoring |
Smart Lighting with Alexa
Useful Tools:
All IoT Tools |
MAC Vendor Lookup