Door Lock System using Optical Fingerprint reader and  RC522 RFID with LCD Display

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

    • Arduino uno
/pre>
  • RC522 RFID kit
  • 
    
  • 1-channel 5V relay module
  • 
    Optical Fingerprint reader sensor
    
    
    
  • 12V/2A SOLENOID ELECTROMAGNETIC LOCK
  • 
    
  • I2C LCD 16x2
  • 
    
    
    
    
    
  • External 12V DC supply
  • 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.

    This Shows the reading process on how to capture the output for fingerprint.
    This sensor is connected to any microcontroller or system with TTL serial, and send packets of data to take photos, detect prints, hash and search. You can also enroll new fingerprints directly . Up to 162 fingerprints can be stored in the onboard FLASH memory.

    RFID module

    RFID means radio-frequency identification. RFID uses electromagnetic fields to transfer data over short distances. RFID is useful to identify people, to make transactions and others.
    The RFID tags included in the kit are 1 white card-type tag, and 1 keychain type tag. The tag is placed a few centimeters from the reader in order to make a reading. This RFID system operates at 3.3V and has a frequency of 13.56 MHz.

    I2C LCD module

    This is a 16×2 LCD display screen with I2C interface. It uses only 4 pins the SCL,SDA,VCC and GND when interfacing with an Arduino. The advantage in using this is to save digital/analog pins on your microcontroller.
    .
    This solenoid lock operates at 12V, with maximum current of 2A. Useful for doors and cabinets etc. as safety lock.

    Hardware Set-up

    This is the pinout for the Fingerprint Sensor.
    This is the actual setup of the door lock system .
    Ror this set -up we need an external 12V supply to power the Solenoid Lock

    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.

    Once it indicates “Stored”, your fingerprint is now enrolled.
    To test if the fingerprint scanner can really detect your fingerprint, go to:
    File→Examples→Adafruit_Fingerprint→fingerprint example and upload it to your Arduino.
    Open up the serial monitor at 9600 baud and when prompted place your finger against the sensor. You should see the above.
    “Confidence” is a score number (from 0 to 255) that indicates how good of a match the print is,. The higher the value, the better match we have.

    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. 

    This is how to get your UID card number Go to Files —-> Examples —–> MFRC522 —–> DumpInfo and upload to your Arduino then scan your card take note of your Cad UID number to use it later .

    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).

    This the actual system demonstration . Testing the RFID card and the Fingerprint reader simultaneously with the Solenoid lock .

    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

    The post Door Lock System using Optical Fingerprint reader and RC522 RFID with LCD Display appeared first on CreateLabz.

    Arduino unoFingerprint sensorI2cI2c 1602 lcdKnowledgebaseRfid reader kitSecurity systemSolenoid lock

    Leave a comment

    All comments are moderated before being published