Using a Fingerprint sensor and 3X4 keypad together On Single Arduino

I have a project were I am controlling a set of locks with a fingerprint sensor and 3X4 keypad and Mobile App. I have Tried Running them but both of them Only run when their sketch is compiled or uploaded. Cant Run both together by uploading both the sketches on a single arduino device. Can You please help me to let me know that i can run both together on a single device or i have to buy another arduino and upload diffrent sketches on them? or can i combine both the codes to run at a time where i can use fingerprint and keypad together?

I am uploading both of my codes Fingerprint and Keypad Respectively
Waiting for your response

FingerPrint Sesnor Program.txt (3.47 KB)

In case not run 2.txt (873 Bytes)

post code in-line using code tags please. hard to Read attachments from mobile phone

also define what you are trying to achieve. if there is a sequence of events or whatever that needs to happen, then you need to build a state machine (for example) to handle the sequence of events and wait for the keypad or fingerprint at the right time

using code tags please...

--> add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

Finger Print Code

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

SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("fingertest");
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);





  // 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);
    }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again

{
  getFingerprintIDez();
  delay(50);            //don't ned to run this at full speed.
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
}

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;
  }
  {digitalWrite(11, HIGH);
  delay(3000);
  digitalWrite(11, LOW);
  Serial.print("Not Found"); 
  Serial.print("Error"); 
  return finger.fingerID;
 }

  // 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);   
  
  }   }

Keypad Code

<Keypad.h>
char* password = "123";  // change the password here, just pick any 3 numbers
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};


byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int Lock = 13;


void setup()
{


pinMode(Lock, OUTPUT);
LockedPosition(true);
}


void loop()
{
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
LockedPosition(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
digitalWrite(Lock, LOW);
}
else
{
digitalWrite(Lock, HIGH);
}
}

I have attached relay finger print, and keypad with my ardiuno device and the relay is attached with a solenoid 12 v door lock, i want my door lock to work whenever i use my finger print or password diffrently , means the door should open weather i want it to open using my fingerprint or keypad .

OK so those are basic examples doing one thing. they show you how to access the capability.

you are using the same pins for two intents

here pin 2 and 3 are used for the fingerprint sensor

SoftwareSerial mySerial(2, 3); // mySerial is a stupid name
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

and in the keypad you use pin 2 and 3 againbyte colPins[COLS] = { 5, 4, 3, 2 };

(please edit your old post above to add the tags, it looks ugly at the moment and make a loonnnnng web page)

so whats the solution for this can you please help? What i have to do i have no idea should i use another ardino device for using the pin 2,3 diffrent times or should i change the code , please help

change the pins of the keypad to something else and connect that way....

for the code, it seems this function

// returns -1 if failed, otherwise returns ID #
int checkFingerPrint()
{
  uint8_t r = finger.getImage();
  if (r != FINGERPRINT_OK)  return -1;

  r = finger.image2Tz();
  if (r != FINGERPRINT_OK)  return -1;

  r = finger.fingerFastSearch();
  if (r != FINGERPRINT_OK)  return -1;

  // found a match!
  return finger.fingerID ; // with confidence of finger.confidence
}

would test a finger print and return something different than -1 if a fingerprint is found.

that probably could help

1. Connect your Keypad with UNO as per following diagram (Fig-1) without using DPin-2 and DPin-3 but DPin-12 and DPin-11 instead.
KBLX.png
Figure-1:

2. The revised Keypad program (your's one) is given below. Upload it and check that the Keypad/sketch is working as it was working before.

<Keypad.h>
char* password = "123";  // change the password here, just pick any 3 numbers
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};


byte rowPins[ROWS] = { 9, 8, 7, 6 }; //R1R2R3R4
byte colPins[COLS] = { 5, 4, 12, 11 }; //C1C2C3C4
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int Lock = 13;


void setup()
{


  pinMode(Lock, OUTPUT);
  LockedPosition(true);
}


void loop()
{
  char key = keypad.getKey();
  if (key == '*' || key == '#')
  {
    position = 0;
    LockedPosition(true);
  }
  if (key == password[position])
  {
    position ++;
  }
  if (position == 3)
  {
    LockedPosition(false);
  }
  delay(100);
}
void LockedPosition(int locked)
{
  if (locked)
  {
    digitalWrite(Lock, LOW);
  }
  else
  {
    digitalWrite(Lock, HIGH);
  }
}

3. Now merge fingerprint code and keypad code to get a single program.

KBLX.png

Can You Please Merge the codes into a single program in order to run because i am totally new to aurdino and i don't know much about merging or aurdino coding kindly help

Totally new is not a good reason... may be this project is too ambitious for the moment for you

Start with simpler tutorials

Does sketch of Post#8 work with revised Keypad connection?

Can you explain the context of your project? School work?

This Is My university final year project , will be very aprreciated if you can give me the combined code of the connection as provide above

Isn’t that cheating ? Couldn’t you at least give it a try ?

In plain English What would have to be the algorithm for this ?
Try to break it down in simple tasks

Dear that's not cheating the teachers has allowed us to take help from anywhere ,, i have tried my best and still trying since 3 days to solve this problem but can't.

Basically i want my realy to work weather i use my finger print or my pin code , there is no scnerio that what will use first the relay should work on both CASES seprately, can you please combine both codes in such a way that i can run both keypad+ fingerprint whatever i want to use.

byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 11, 10 };

my new pin connection are these for keypad and it work fine sepralety, but i cant run fingerprint and keypad together.

Show us your attempt to merge the code and explain your logic

J-M-L:
Show us your attempt to merge the code and explain your logic

@OP

  1. Open the Keypad sketch.
  2. Open the Fingerprint sketch.
  3. Copy the whole code of Fingerprint sketch.
  4. Bring the cursor at the end of the Keypad sketch.
  5. Paste the copied codes of Step-3

You have got a merged sketch. It will be working or not -- this is a different story.

@golam

thanks for a constructive answer... :slight_smile:

Combine Code

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

SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup1()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("fingertest");
  pinMode(13, OUTPUT);
 
  // 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);
    }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}

void loop1()                     // run over and over again

{
  getFingerprintIDez();
  delay(50);            //don't ned to run this at full speed.
  digitalWrite(13, LOW);
}

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;
  }
  {digitalWrite(13, HIGH);
  delay(3000);
  digitalWrite(13, LOW);
  Serial.print("Not Found"); 
  Serial.print("Error"); 
  return finger.fingerID;
 }

  // 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(13, HIGH);
    delay(3000);
    digitalWrite(13, LOW);
    Serial.print("Found ID #"); Serial.print(finger.fingerID);
    Serial.print(" with confidence of "); Serial.println(finger.confidence);
    
    
  
  }   }
  #include <Keypad.h>
char* password = "123";  // change the password here, just pick any 3 numbers
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};


byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 11, 10 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int Lock = 13;


void setup()
{


pinMode(Lock, OUTPUT);
LockedPosition(true);
}


void loop()
{
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
LockedPosition(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
digitalWrite(Lock, LOW);
}
else
{
digitalWrite(Lock, HIGH);
}
}