Overview
This Project aims to implement simple Door lock automation using RFID and Fingerprint reader sensor as key to open the lock. It also uses I2C LCD 16×2 module as its display. All of the component are controlled by Arduino Uno. it also uses relay module that serves as switch to trigger the 12V Solenoid Lock.
Hardware used
/pre>
Software used
Library Used
you can click the library to direct you to the download page.
What is Optical fingerprint reader sensor?
These modules are typically used in safes. There’s a high powered DSP chip that does the image rendering, calculation, feature-finding and searching.
RFID module
I2C LCD module
Hardware Set-up
Software Set-up
To start with, we will enroll fingerprints via Arduino.
In enrolling via Arduino. open Files—>Examples—->Adafruit Fingerprint Sensor Library —–> enroll then upload it to your Arduino.
Code
#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <SPI.h> #include <MFRC522.h> #include <Adafruit_Fingerprint.h> #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above SoftwareSerial mySerial(2, 3); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. LiquidCrystal_I2C lcd(0x27,16,2); String read_rfid; String ok_rfid_1="d09dd8a4"; String ok_rfid_2="deae805c"; int lock = 7; String name1 = "Gabriel"; /* * Initialize. */ void setup() { Serial.begin(9600); // Initialize serial communications with the PC // Print a message to the LCD. lcd.begin(); lcd.backlight(); while (!Serial); // Do nothing if no serial port is opened SPI.begin(); // Init SPI bus finger.begin(57600); // Init Fingerprint mfrc522.PCD_Init(); // Init MFRC522 card digitalWrite(lock,HIGH); pinMode(lock, OUTPUT); lcd.setCursor(1,0); lcd.print("Please Scan "); if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1) { delay(1); } } finger.getTemplateCount(); Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates"); Serial.println("Waiting for valid finger..."); } /* * Helper routine to dump a byte array as hex values to Serial. */ void dump_byte_array(byte *buffer, byte bufferSize) { read_rfid=""; for (byte i = 0; i < bufferSize; i++) { read_rfid=read_rfid + String(buffer[i], HEX); } } void maindsp() { lcd.setCursor(1,0); lcd.print("Please Scan"); } void open_lock() { //Use this routine when working with Relays and Solenoids etc. lcd.setCursor(1,0); lcd.print("Welcome User "); lcd.setCursor(1,1); lcd.print(name1); digitalWrite(lock,LOW); delay(3000); digitalWrite(lock,HIGH); lcd.clear(); return maindsp(); } void NoFingerdetec() { lcd.setCursor(1,0); lcd.print("No match found"); delay(1000); lcd.clear(); } void again() { lcd.setCursor (0,0); lcd.print("Pls. Scan Again"); delay(1000); lcd.clear(); return maindsp(); } void loop() { getFingerprintIDez(); // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) return; // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) return; dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); Serial.println(read_rfid); if (read_rfid==ok_rfid_1) { //ok, open the door. open_lock(); } //Add below as many "keys" as you want else if (read_rfid==ok_rfid_2) { //also ok, open the door open_lock(); } else{ lcd.setCursor(1,0); lcd.print("Access Denied"); delay(1000); lcd.clear(); lcd.setCursor(1,0); lcd.print("Scan Again"); return maindsp(); } } // returns -1 if failed, otherwise returns ID # int getFingerprintIDez() { uint8_t p = finger.getImage(); if (p != FINGERPRINT_OK) return -1; p = finger.image2Tz(); if (p != FINGERPRINT_OK) return -1; p = finger.fingerFastSearch(); if (p != FINGERPRINT_OK) { NoFingerdetec(); again(); return -1; } open_lock(); // found a match! Serial.print("Found ID #"); Serial.print(finger.fingerID); Serial.print(" with confidence of "); Serial.println(finger.confidence); return finger.fingerID; }
This is the code for the entire system .
Code breakdown
#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <SPI.h> #include <MFRC522.h> #include <Adafruit_Fingerprint.h> #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above SoftwareSerial mySerial(2, 3); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. LiquidCrystal_I2C lcd(0x27,16,2); String read_rfid; String ok_rfid_1="d09dd8a4"; String ok_rfid_2="deae805c"; int lock = 7; String name1 = "Gabriel";
This is for initialization of variables and inclusion of libraries.
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); Serial.println(read_rfid);
This routine is to dump a byte array as hex values to Serial.
p = finger.getImage(); if (p != FINGERPRINT_OK) return -1;
This function is to ask the sensor to take an image of the finger pressed on surface. if false it will return the process.
p = finger.image2Tz(); if (p != FINGERPRINT_OK) return -1;
In this function the sensor will convert image to feature template.
p = finger.fingerFastSearch(); if (p != FINGERPRINT_OK) { NoFingerdetec(); again(); return -1;
The sensor will search the current slot 1 fingerprint features to match saved templates. The matching location is stored in (fingerID) and the matching confidence in (confidence).
Conclusion
This system can be used as mini security system for home. It’ also not only limited for door locks or solenoid lock, but you can also use other components or other sensors for your desired output with a little modification of the code.
Reference
- https://www.hackster.io/Heathen_Hacks-v2/rfid-relay-rfid-door-lock-code-rfid-pc-switch-eee1d1
- https://learn.adafruit.com/adafruit-optical-fingerprint-sensor?view=all
- https://www.teachmemicro.com/arduino-rfid-rc522-tutorial/
- https://www.quora.com/How-does-the-biometric-fingerprint-scanner-work
The post Door Lock System using Optical Fingerprint reader and RC522 RFID with LCD Display appeared first on CreateLabz.