Arduino Door lock system using fingerprint and keypad both

In my project i want to build a project that have two layer security . one is keypad password and another is fingerprint . but is problem that both codes of keypad and fingerprint work separately but during the merged code not work properly one sensor work and another not . i don't understand what is issue there because there no any error but not give the output. can you help me out this issue
----code ---
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
//Include Arduino Wire library for I2C
#include <Wire.h>
//Include LCD display library
#include <LiquidCrystal.h>
//Include Keypad library
#include <Keypad.h>
//Length of password +1 for null character
#define Password_Length 8
//Character to hold password input
char Data[Password_Length];
//Password
char Master[Password_Length] = "1234567";
//Pin connect to lock relay input
int lockOutput = 13;
//Pin connect to Alarm
int led =12;
//Counter for charachter entries
byte data_count = 0;
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0;
//Constants for row and column sizes
char customKey;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {4,5, 6, 7}; //connect to the row pinouts of
the keypad
byte colPins[COLS] = {8,9,10,11}; //connect to the column pinouts of
the keypad
//Create keypad object
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins,
colPins, ROWS, COLS );
//Create LCD object
LiquidCrystal lcd(15,14,16,17,18,19); //Parameters: (rs, enable, d4,
d5, d6, d7)
String number;
int s=0,take_fing;
void doorOpen()
{
lcd.clear();
lcd.print("WELOME");
if(finger.fingerID==0)
{
Serial.println("Welcome MR.AMAN ");//i enroled ID no 1 as
Nidhi'sfingerprint, so used this line to display corresponding name
lcd.setCursor(0, 1);
lcd.print("AMAN");
digitalWrite(13,HIGH);
delay(3000);
lcd.clear();
}
if(finger.fingerID==1)
{
Serial.println("Welcome Ms.AMIT");// i enroled ID no 1 as Cinla's
fingerprint, so used this line to display corresponding name
lcd.setCursor(0, 1);
lcd.print("Mr.AMIT");
digitalWrite(13,HIGH);
delay(3000);
lcd.clear();
// more number of user can be add hear
}
}
void doorClose()
{
digitalWrite(13,LOW);
lcd.print("No valid finger");
digitalWrite(12,HIGH);
lcd.setCursor(0, 1);
lcd.print("Alarm");
}
void setup()
{
//Setup LCD with backlight and initialize
// lcd.backlight();
//lcd.init();
lcd.begin(16,2);
Serial.begin(38400);
//Set lockOutput as an OUTPUT pin
pinMode(lockOutput,OUTPUT);
if (finger.verifyPassword())
{
Serial.println("Found fingerprint sensor!");
}
else
{
Serial.println("Did not find fingerprint sensor :(");
lcd.print("Sensor not Found");
while (1);
}
Serial.println("No valid finger found,waiting for valid finger...");
lcd.print("No valid finger");
lcd.setCursor(0,1);
lcd.print("On the Sensor");
}
void loop()
{
//Initialize LCD and Print
lcd.setCursor(0,0);
lcd.print("Enter Password :");
// Look for keypress
customKey = customKeypad.getKey();
if (customKey) {
// Enter keypress into array and increment counter
Data[data_count] = customKey;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
}
// See if we have reached the password length
if (data_count == Password_Length - 1) {
lcd.clear();
if (!strcmp(Data, Master))
{
// Password is correct
lcd.print("Correct");
// Turn on relay for 5 seconds
if(getFingerprintIDez()>=0)
{
doorOpen();
delay(1000);
doorClose();
}
// digitalWrite(lockOutput, HIGH);
// delay(5000);
//digitalWrite(lockOutput, LOW);
}
else
{
// Password is incorrect
lcd.print("Incorrect");
digitalWrite(12,HIGH);
lcd.setCursor(0, 1);
lcd.print("Alarm");
delay(1000);
}
// Clear data and LCD display
lcd.clear();
clearData();
}
}
// fingerprint code
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);
}
// 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);
return finger.fingerID;
}
void clearData() {
// Go through array and clear data
while (data_count != 0) {
Data[data_count--] = 0;
}
return;
}

Read the forum guidelines.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

What Arduino board? I am assuming a Uno or Nano.

Pins 18 & 19 that you use for the LCD are also the A4 and A5 pins that Wire (I2C) uses.
Edit: Wire is not used so this is, probably, not the cause of the issue, but will need addressed if Wire is to be used.

Post a schematic.

Can you tell us what that means? What sensors? Which one works? Which one doesn't?

everyone is going to give you advice you have not asked for. this is not us being rude, this is us expecting you to know preferred forum behavior before you post.

when you post code we expect it to be in code tags - 7th icon from the left above, less than slash greater than.

put the URLs to the libraries you use in the same line as

#include <Keypad.h>

because there are many Keypad.h's and Liquid Crystal.h's, and we need the right one to make things work. like this:

#include <TimeLib.h>                // Time functions  https://github.com/PaulStoffregen/Time

my computer stops compiling at

#include <Keypad.h>

I had to // lines 35,37, and 53 ( I auto format with allman style format - curly brackets { } at the end of lines go one line down, so left brackets end up above their corresponding right bracket - so my line numbers wont match yours: )

//the keypad
byte colPins[COLS] = {8,9,10,11}; //connect to the column pinouts of
//the keypad
//Create keypad object
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins,
colPins, ROWS, COLS );
//Create LCD object
LiquidCrystal lcd(15,14,16,17,18,19); //Parameters: (rs, enable, d4,
d5, d6, d7)
String number;
int s=0,take_fing;
void doorOpen()
{
lcd.clear();
lcd.print("WELOME");
if(finger.fingerID==0)
{
Serial.println("Welcome MR.AMAN ");//i enroled ID no 1 as
//Nidhi'sfingerprint, so used this line to display corresponding name

you seem to have a stray right curly bracket:

lcd.clear();
// more number of user can be add hear
}
}
void doorClose()

and everything related to curly brackets goes pear shaped at void setup:

void setup()
{
//Setup LCD with backlight and initialize
// lcd.backlight();
//lcd.init();
lcd.begin(16,2);
Serial.begin(38400);
//Set lockOutput as an OUTPUT pin
pinMode(lockOutput,OUTPUT);
if (finger.verifyPassword())
{

that bottom { should be a }

if you highlight a bracket, its mate should show up, highlighted in yellow. that first extra } is screwing up everything below it, and the extra { at the bottom of void setup() is a disaster

curly brackets, square brackets, and parentheses create envelopes for blocks of code. every left curly bracket, square bracket, or parenthese must have a corresponding right curly bracket, square bracket, or parenthese

rewrite your code with these things in mind, then come back and ask again

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <Keypad.h>
#include <LiquidCrystal.h>

SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {10,11,A0, A1}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A2,A3,A4, A5}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// 16x2 LCD
#define rs 9
#define en 8
#define d4 7
#define d5 6
#define d6 5
#define d7 4
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

String password = "1234";
String mypassword;

int redled = 12;
int lock = 13;

int counter = 0;
int attempts = 0;
int max_attempts = 3;

void setup(){
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);

pinMode(redled, OUTPUT);
pinMode(lock, OUTPUT);

digitalWrite(redled, LOW);
digitalWrite(lock, LOW);

Serial.println("enter password");
lcd.print("Enter Password:");
}

void loop()
{

keypadfunction();
getFingerprintIDez();
}

void keypadfunction()
{
char key = keypad.getKey();

if (key){
Serial.println(key);
counter = counter + 1;
lcd.setCursor(counter, 1);
lcd.print("*");
}
if (key == '1')
{

mypassword = mypassword + 1;   

}

if (key == '2')

{

mypassword = mypassword + 2;  

}

if (key == '3')
{

mypassword = mypassword + 3; 

}

if (key == '4')
{

mypassword = mypassword + 4;  

}

if (key == '5')
{

mypassword = mypassword + 5;

}

if (key == '6')
{

mypassword = mypassword + 6; 

}

if (key == '7')
{

mypassword = mypassword + 7; 

}

if (key == '8')
{

mypassword = mypassword + 8; 

}

if (key == '9')
{

mypassword = mypassword + 9;

}

             if (key == '0')

{

mypassword = mypassword + 0; 

}

    if (key == '*')

{
Serial.println(mypassword);

if ( password == mypassword )
{
lcd.clear();
lcd.println("Welcome");
lcd.setCursor(0,1);
lcd.println("Fingerprint locker");
//digitalWrite(lock, HIGH);
delay(5000);
//digitalWrite(lock,LOW);
lcd.println("Enter fingerprint");
delay(10000);
mypassword = "";
counter = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.println("Enter password");
}
else
{
Serial.println("wrong");
digitalWrite(lock, LOW);
attempts = attempts + 1;
if (attempts >= max_attempts )
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Locked Out");

digitalWrite(redled, HIGH);
delay(5000);
digitalWrite(redled, LOW);
attempts = 0;

}
mypassword = "";
counter = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wrong Password");
delay(1000);

lcd.setCursor(0,1);
lcd.print("max attempts 3");
delay(1000);

lcd.clear();
lcd.println("Enter password");
lcd.setCursor(0,1);
}

}

}
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!

digitalWrite(12, HIGH);
delay(3000);
digitalWrite(12, LOW);

Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}

now i rewrite the code again , there compile time no error but when i upload the code arduino uno its not works ...

Read the forum guidelines. Post your code in code tags.

Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.

type or paste code here
1 Like

please check this code

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.