STEMpedia
Published © CC BY

DIY Electronic Locker Using Fingerprint Sensor

This project helps you make your own Fingerprint Locker that frees you from the hassle of keeping track of countless locks and their keys.

AdvancedFull instructions provided4 hours1,130
DIY Electronic Locker Using Fingerprint Sensor

Things used in this project

Hardware components

evive
STEMpedia evive
×1
Optical Fingerprint Read Sensor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
LilyPad Rainbow LED (strip of 7 colors)
SparkFun LilyPad Rainbow LED (strip of 7 colors)
×1
Hinge
×1
Solenoid Lock
×1
M3 Bolts and Nuts
×1
Thick Cardboard
×1
Color Chart Paper
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Diagram

Here, connection for the LED, the Fingerprint Sensor, and the Solenoid Lock is given.

Code

Arduino Code for all the 3 modes

Arduino
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>     // We are going to read and write PICC's UIDs from/to EEPROM
#include<evive.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define number_of_pixel 4

void(* resetFunc)(void) =0;

int lockbuttongnd = 28;
int lockbuttoncontrol = 29; 
int lockenable=44;
uint16_t id;
int pot = A9;

SoftwareSerial mySerial(11, 12);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

Adafruit_NeoPixel strip = Adafruit_NeoPixel(number_of_pixel, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // put your setup code here, to run once:

   Serial.begin(9600);

    // initialization  for for 12 v solenoid switch
  pinMode(lockenable,OUTPUT);
  pinMode(lockbuttongnd,OUTPUT);
  pinMode(lockbuttoncontrol,OUTPUT);
    
  analogWrite(lockenable,255);
  digitalWrite(lockbuttongnd,LOW);
  digitalWrite(lockbuttoncontrol,LOW);

  strip.begin();
  for(unsigned int i=0;i<4;i++)
  {
    strip.setPixelColor(i,strip.Color(210,0,0));
  }
  strip.show();

   tft_init(INITR_BLACKTAB);
  tft.setRotation(1);
  tft.fillScreen(ST7735_BLACK);

  tft.setCursor(25,10);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.print("STEMpedia");

   tft.setCursor(28,35);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("ELECTRONICS SAFE");
  tft.setCursor(15,55);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.print("SELECT YOUR MODE");
  

   tft.setCursor(15,70);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("SLIDESW1(UP)  :AC MODE ");
   tft.setCursor(15,80);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("SLIDESW2(DOWN):EN MODE");
   tft.setCursor(15,90);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("SLIDESW2(DOWN):ED MODE");

  tft.setCursor(15,100);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("AC : ACCESS CONTROL");
   tft.setCursor(15,110);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("EN : ENROLL ");
   tft.setCursor(15,120);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("ED : EMPTY DATABASE");
  
  finger.begin(57600);

   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");

}

void loop() {
  // put your main code here, to run repeatedly:

     if(digitalRead(40)==HIGH)
         {
           clean();
           Serial.println(" access control mode");
           tft.setCursor(20,55);
           tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
           tft.setTextSize(1);
           tft.print(" ACCESS CONTROL MODE ");

           tft.setCursor(30,85);
           tft.setTextColor(ST7735_RED,ST7735_BLACK);
           tft.setTextSize(1);
           tft.print(" PUT YOUR FINGER");

  
          while(1)
             {
                getFingerprintIDez();
                delay(50);
             }
          }
     else if(digitalRead(41)==HIGH)
             {
                Serial.println(" enroll mode ");
                while(1)
                    {
                          clean();
                          tft.setCursor(30,55);
                          tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
                          tft.setTextSize(1);
                          tft.print(" ENROLL MODE ");

                          tft.setCursor(5,110);
                          tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
                          tft.setTextSize(1);
                          tft.print("slidswitch2(up) : confirm");

                          tft.setCursor(10,80);
                          tft.setTextColor(ST7735_RED,ST7735_BLACK);
                          tft.setTextSize(2);
                          Serial.println("Ready to enroll a fingerprint!");
                          Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
                            
                              id = readnumber();
                              if (id == 0) 
                                 {
                                     // ID #0 not allowed, try again!
                                     return;
                                 }
                              Serial.print("Enrolling ID #");
                              Serial.println(id);
                              clean();
                              tft.setCursor(30,55);
                              tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
                              tft.setTextSize(1);
                              tft.print(" ENROLL MODE ");
                              tft.setCursor(30,85);
                              tft.setTextColor(ST7735_RED,ST7735_BLACK);
                              tft.setTextSize(1);
                              tft.print(" PUT YOUR FINGER");
  
                              while (!getFingerprintEnroll());
 
                       }
                  }
    else if(digitalRead(43)==HIGH)
            {
                 while(1)
                    {
                         Serial.println(" empty mode ");
                         finger.emptyDatabase();
                          clean();
                              tft.setCursor(30,55);
                              tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
                              tft.setTextSize(1);
                              tft.print("EMPTY DATABASE MODE ");
                              tft.setCursor(30,85);
                              tft.setTextColor(ST7735_RED,ST7735_BLACK);
                              tft.setTextSize(1);
                              tft.print("DATABASE IS NOW EMPTY");
                              delay(3000);
                              resetFunc();
    
                   }
            }

  

}

 uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 

  return finger.fingerID;
}

// 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)  return -1;
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  clean();
  
  tft.setCursor(20,70);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.setTextSize(1.5);
  tft.print(" ACCESS GRANTED ");
    for(unsigned int i=0;i<4;i++)
  {
    strip.setPixelColor(i,strip.Color(0,210,0));
  }
  strip.show();
   digitalWrite(lockbuttoncontrol,HIGH);
   delay(3000);
   digitalWrite(lockbuttoncontrol,LOW);
   resetFunc();
   

  
  return finger.fingerID; 
}

// --------------------- enroll functions--------------------------------------------------------------------------------------------------------------------------------

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  Serial.println("Remove finger");
  clean();
  tft.setCursor(30,55);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(" ENROLL MODE ");
  tft.setCursor(30,85);
  tft.setTextColor(ST7735_RED,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(" REMOVE YOUR FINGER");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
   clean();
  tft.setCursor(30,55);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(" ENROLL MODE ");
   tft.setCursor(20,85);
  tft.setTextColor(ST7735_RED,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("PLACE SAME FINGER AGAIN");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);
  
  p = finger.createModel();
  if (p == FINGERPRINT_OK) 
     {
            Serial.println("Prints matched!");
           
            
  }
  else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  }
  else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
     clean();
  tft.setCursor(30,55);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(" ENROLL MODE ");
   tft.setCursor(30,85);
  tft.setTextColor(ST7735_RED,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("TRY AGAIN");
  delay(3000);
   resetFunc();
    return p;
  }
  else {
    Serial.println("Unknown error");
    return p;
  }   
  
  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
     clean();
            tft.setCursor(30,55);
            tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
            tft.setTextSize(1);
            tft.print(" ENROLL MODE ");
            tft.setCursor(30,85);
            tft.setTextColor(ST7735_RED,ST7735_BLACK);
            tft.setTextSize(1);
            tft.print("SUCCESS");
            delay(3000);
             resetFunc();
 
 } 
 else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
     
    return p;
  } 
  else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    
    return p;
  } 
  else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
   
    return p;
  } 
   else {
    Serial.println("Unknown error");
   
    return p;
  }   
}

uint16_t readnumber(void) {
  uint16_t num = 0;
       while(!(digitalRead(42)==HIGH))
          {
              num = analogRead(pot);
              num = map(num ,0,1023,1,9);
              tft.setCursor(80,80);
              tft.print(num);
              delay(10);
           }
           return num;
  
}
void clean()
{
  tft.fillScreen(ST7735_BLACK);

  tft.setCursor(25,10);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.print("STEMpedia");

   tft.setCursor(28,35);
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("ELECTRONICS SAFE");
}

evive Library

C/C++
No preview (download only).

Credits

STEMpedia
42 projects • 171 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.

Comments