zmankowitz
Published © GPL3+

Door fingerprint sensor lock

Fingerprint sensor that locks/unlocks door with RGB LED and OLED display feedback

AdvancedShowcase (no instructions)2,640
Door fingerprint sensor lock

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
Power MOSFET N-Channel
Power MOSFET N-Channel
520N
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Breadboard (generic)
Breadboard (generic)
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Not sure if this is the same one - mine has four wires (red,green,blue, power)
×1
Fingerprint Sensor
DFRobot Fingerprint Sensor
Mine was from DIYmail
×1
OLED Display, Blue on Black
OLED Display, Blue on Black
mine used i2c
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Drill / Driver, Cordless
Drill / Driver, Cordless
3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Fritzing (full)

Schematic (fingerprint sensor excluded)

Code

Code for master (fingerprint sensor one) page 1/2

C/C++
//Created by Zachary Mankowitz
#include <EEPROM.h>

#include <Servo.h>

 #include <DYE_Fingerprint.h>
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);

DYE_Fingerprint finger = DYE_Fingerprint(&mySerial);

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards   

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
int slaveArd = 6;
void setup()  
{
  pinMode(slaveArd, OUTPUT);
  analogWrite(slaveArd, 0);
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
  display.clearDisplay();
  display.setTextColor(WHITE);
  
                  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
                  
                  servoToggle();
                  
                  //pinMode(10,OUTPUT); //LED
  Serial.begin(9600);
  while (!Serial);
  delay(100);
  Serial.println("\n\nfinger detect test");
 
  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  analogWrite(slaveArd, 0);//rest
  getFingerprintIDez();
  delay(50);            //don't ned to run this at full speed.
}

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! NOT SURE WHAT THIS DOES
  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)  {
    Serial.println("bad");
   analogWrite(slaveArd, 150);//~3v
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("FINGER");
  display.setTextSize(2);
   display.println("INCOREECT");
   display.display();
   //delay(100);
    return -1;
  }
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);

  servoToggle();
               
                  
  return finger.fingerID; 
}

Code for master (fingerprint sensor one) page 2/2

C/C++
void servoToggle(){
  int doorOpen = EEPROM.read(1);
Serial.println(doorOpen);
  if(doorOpen==0){ //locked
    myservo.write(135);
    analogWrite(slaveArd, 100);//~1-2v
  
    display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("Status: UNLOCKED");
  display.setTextSize(3);
   display.println("Come in");
   display.display();
    doorOpen=1;
    EEPROM.write(1,1); // (address,value)
    delay(2000);
  }
  else{
    myservo.write(45);
    analogWrite(slaveArd, 50);//~.5-1v
    
    display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("Status: LOCKED");
  display.setTextSize(1);
   display.println("May be davening or changing");
   display.display();
    doorOpen=1;
    doorOpen=0;
    EEPROM.write(1,0);
    delay(2000);
  }

}

Code for salve(rgb one)

C/C++
upload to the second arduino
//Written by Zack for Engineering Foundations 5/1/2020

int redLED = 6;
int greenLED = 5;
int blueLED = 3;
int redNew = (int)random(0, 255);
int blueNew = (int)random(0, 255);
int greenNew = (int)random(0, 255);
int red, green, blue = 0;
int dataValue;
int count;
int i;
void setup() {
  // put your setup code here, to run once:
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(A0, INPUT);
  pinMode(9,OUTPUT);
  Serial.begin(9600);
  analogWrite(redLED, 0);
  analogWrite(greenLED, 0);
  analogWrite(blueLED, 0);

}

void loop() {
if(i==155){
    i=0;
    count = 0;
  red = redNew;
  green = greenNew;
  blue = blueNew;
  redNew = (int)random(0, 255);
  greenNew = (int)random(0, 255);
  blueNew = (int)random(0, 255);
  }
analogWrite(9,i);
  i++;
  
  Serial.println(i);
  for(int i = 0;i<50;i++){
  dataValue += analogRead(A0);
  }dataValue/=50;
float voltage = dataValue * (5.0 / 1023.0);
 Serial.print(voltage);
 Serial.println("v");

  if(/*at rest*/ (voltage <.5)&&(voltage>=0)){
    rgbFade();
  }
  if(/*doorLocked*/(voltage>=.5)&&(voltage<1)){
    Serial.println("locked");
    setColor(255,0,0);
    red = 255;
    green=0;
    blue=0;
  }
  if(/*door unlocked*/(voltage>=1)&&(voltage<2.5)){
    setColor(0,255,0);Serial.println("unlock");
    red = 0;
    green=255;
    blue=0;
  }
  if(/*incorect finger*/(voltage>=2.5)&&(voltage<3)){
    
    Serial.println("incorrect finger");
    for(int i=0;i<3;i++){
    setColor(255,0,0);
    delay(250);
    setColor(0,0,0);
    delay(250);
    red = 255;
    green=0;
    blue=0;
    }
  }
  delay(100);
}


void whiteFade() {
  Serial.println("White Fade");
  for (int i = 0; i < 255; i++) {
    analogWrite(redLED, i);
    analogWrite(greenLED, i);
    analogWrite(blueLED, i);
    delay(10);
    Serial.println(i);
  }
  for (int i = 255; i > 0; i--) {
    analogWrite(redLED, i);
    analogWrite(greenLED, i);
    analogWrite(blueLED, i);
    delay(10);
    Serial.println(i);
  }
}

void rgbFlash() {
  Serial.println("rgb flash");
  analogWrite(redLED, (int)random(0, 255));
  analogWrite(greenLED, (int)random(0, 255));
  analogWrite(blueLED, (int)random(0, 255));
  delay(500);
}
void rgbFade() {
  Serial.print(red);
  Serial.print(" ");
  Serial.print(green);
  Serial.print(" ");
  Serial.println(blue);
   dataValue = analogRead(A0);
float voltage = dataValue * (5.0 / 1023.0);
  if(voltage<1){
  Serial.println("rgb fade");
  //if(i == 0){
    //------------------------------------
 // }
  if (red < redNew) {
    analogWrite(redLED, red);
    red++;
    delay(10);
  }
  if (red > redNew) {
    analogWrite(redLED, red);
    red--;
    delay(10);
  }
  //--
  if (green < greenNew) {
    analogWrite(greenLED, green);
    green++;
    delay(10);
  }
  if (green > greenNew) {
    analogWrite(greenLED, green);
    green--;
    delay(10);
  }
  //--
  if (blue < blueNew) {
    analogWrite(blueLED, blue);
    blue++;
    delay(10);
  }
  if (blue > blueNew) {
    analogWrite(blueLED, blue);
    blue--;
    delay(10);
  }
  
}
delay(10);
}

void setColor(int red, int green, int blue) {
  Serial.println("set color");
  analogWrite(redLED, red);
  analogWrite(greenLED, green);
  analogWrite(blueLED, blue);
}

Credits

zmankowitz

zmankowitz

0 projects • 2 followers

Comments