Using a Fingerprint sensor and 3X4 keypad together

I have a project were I am controlling a set of locks with a fingerprint sensor and 3X4 keypad. I have combined two sets of code (that work great on their own) into one sketch. The sketch uploads fine and the serial output is correct. The problem lies in that it only runs the sensor that I have coded after void loop first (fingerprint sensor). If iI invert the code it will switch to the other sensor (keypad).
Is there away to join the code so it will run both?

I will attached the combined code for both sensors, fallowed by the individual code for the keypad and fingerprint sensor.
Thanks for the help

Combined code:

#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

#include <Password.h>

#include <Keypad.h>


int getFingerprintIDez();
int led = 13;

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };


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


void setup()  
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("fingertest");
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  keypad.setDebounceTime(100);

  // 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);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  getFingerprintIDez();
}

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!
  digitalWrite(5, HIGH);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(4, LOW);
  delay(25000);
  digitalWrite(5, LOW);
  digitalWrite(13, LOW);

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

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
      Serial.print("Pressed: ");
      Serial.println(eKey);
      switch (eKey){
        case '#': guessPassword(); break;
         default:
               password.append(eKey);
  }
}}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
           Serial.println("VALID PASSWORD "); //
           digitalWrite(5, HIGH);
             delay(1000);
           digitalWrite(4, HIGH);
             delay(1000);
           digitalWrite(4, LOW);
             delay(25000);
           digitalWrite(5, LOW);
         
              password.reset(); //resets password after correct entry
     }else{
           Serial.println("INVALID PASSWORD ");
              password.reset(); //resets password after INCORRECT entry
     }
}

Fingerprint sensor code:

#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

int getFingerprintIDez();
int led = 13;

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("fingertest");
  

  // 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);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  getFingerprintIDez();
}

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!
  digitalWrite(5, HIGH);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(4, LOW);
  delay(25000);
  digitalWrite(5, LOW);
  digitalWrite(13, LOW);

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

Keypad code:

#include <Password.h>

#include <Keypad.h>

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };


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

void setup(){

  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  keypad.setDebounceTime(100);
}

void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
      Serial.print("Pressed: ");
      Serial.println(eKey);
      switch (eKey){
        case '#': guessPassword(); break;
         default:
               password.append(eKey);
  }
}}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
           Serial.println("VALID PASSWORD "); //
           digitalWrite(5, HIGH);
             delay(1000);
           digitalWrite(4, HIGH);
             delay(1000);
           digitalWrite(4, LOW);
             delay(25000);
           digitalWrite(5, LOW);
         
              password.reset(); //resets password after correct entry
     }else{
           Serial.println("INVALID PASSWORD ");
              password.reset(); //resets password after INCORRECT entry
     }
}

Yes, it is possible to do.
However your combination code appears the be wrong, but it also depends on what you want to read first, the finger or the password?

Usually you would check the finger print first then get the password, however you could also do it the other way and get the password first.

What are you trying to do?

I would prefer to run them both at the same time if possible. The fingerprint is for the owner to gain access and the keypad is for others. If that is not possible, would it be possible to run the keypad or press * or # to revert to the fingerprint sensor? # is currently being used to enter the our digit password.
need some direction in what the possibilities are and how to get it done.
Thanks

Your delays will block your code from doing anything until they are done, but this should work.

#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif

#include <Password.h>

#include <Keypad.h>


//int getFingerprintIDez();
int led = 13;
boolean Password_is_valid = false;

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3'      }
  ,
  {
    '4','5','6'      }
  ,
  {
    '7','8','9'      }
  ,
  {
    '*','0','#'      }
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 
  9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 
  12, 11, 10 };


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


void setup()  
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("fingertest");
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  keypad.setDebounceTime(100);

  // 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);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  char eKey = keypad.getKey();
  getFingerprintIDez();
  
  if(Password_is_valid) // check to see if either the finger or password is valid 
    PasswordIsValid();
}

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

  if((finger.getImage() | finger.image2Tz() | finger.fingerFastSearch() ) != FINGERPRINT_OK)
    return -1;
  else
  {
    // found a match!
    Password_is_valid = true;
    Serial.print("Found ID #"); 
    Serial.print(finger.fingerID); 
    Serial.print(" with confidence of "); 
    Serial.println(finger.confidence);
    return finger.fingerID; 
  }
}

//take care of some special events
void keypadEvent(KeypadEvent eKey)
{
  switch (keypad.getState())
  {
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey)
    {
    case '#': 
      guessPassword(); 
      break;
    default:
      password.append(eKey);
    }
  }
}

void guessPassword()
{
  Serial.print("Guessing password... ");
  if (password.evaluate())
  {
    Serial.println("VALID PASSWORD "); //
    Password_is_valid = true;
    password.reset(); //resets password after correct entry
  }
  else
  {
    Serial.println("INVALID PASSWORD ");
    password.reset(); //resets password after INCORRECT entry
  }
}

void PasswordIsValid()
{
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(4, LOW);
  delay(25000);
  digitalWrite(5, LOW);
  
  Password_is_valid = false;
}

Thanks
Uploaded the code. The fingerprint sensor runs, but not the keypad.

delays should not effect anything. The door opens then shut and resets the system with a position reed switch. program is dormant until it resets.

Updated code, try it now.

Both work now!!
just one last tweak. There is about a 4 to 5 second delay between character entry on the key pad. Can this be shortened? Work with now delay with the original keypad only code.

Well being that there are no other delays in your sketch, the 4-5 second delay is coming from the fingerprint scanner library. And the only way to fix that would be to alter the fingerprint library and sorry, I am not going to do that. You would need to talk to the creator of the library and see if there are any ways to make it faster.

OK
I appreciate the help.
I tried to delete the setDebounceTime, but that did not help.
I am allot closer then I was.
I will try the creator of the fingerprint liabrary.
Thanks again!

Does anyone else have any ideas?