I need some help in my fingerprint project

To begin with, this program is should be work by input your fingerprint and then the lock will be open. But you also can registes new fingerprint by type the default password with keypad by input 000, and press D for enter . In the setting there will be a 3 choises, (Enroll, Delete, Change password) Enroll is use for input your new fingerprint. Delete is use for delete the fingerprint that saved. And change password is use to change the default password (000). But i have a problem with the password. The setting will be open when i press D, eventhough i don't input the password (000). Can anyone help me?

#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Adafruit_Fingerprint.h>


#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)

SoftwareSerial mySerial(11, 10);

#else

#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;


LiquidCrystal_I2C lcd(0x27, 16, 2);
int Trig = 0;
int Trig2 = 0;
int Trig3 = 0;
int Trig4 = 0;
int Value = 0;
String pass = "000D";

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' },
  { 'S', '0', 'H', 'D' }
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };  //connect to the row pinouts of the keypad
byte colPins[COLS] = { 5, 4, 3, 2 };  //connect to the column pinouts of the keypad

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

String v_passcode = "";

void setup() {
  Serial.begin(9600);
  while (!Serial)
    ;  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // 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(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x"));
  Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x"));
  Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: "));
  Serial.println(finger.capacity);
  Serial.print(F("Security level: "));
  Serial.println(finger.security_level);
  Serial.print(F("Device address: "));
  Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: "));
  Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: "));
  Serial.println(finger.baud_rate);
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Insert (1 to 10)");
    lcd.setCursor(0, 1);
    lcd.print("To save");
    Serial.println(num);
    char key = keypad.getKey();
    if (key >= '0' && key <= '9')  // it's a digit
    {
      num = num * 10 + (key - '0');
    }

    else if (key == '>') {
      // step clockwise
      num = 0;  // Once the  stepper has stepped, reset Value back  to zero.
    }

    else if (key == '<') {
      // step C-clockwise
      num = 0;  // Once the  stepper has stepped, reset Value back  to zero.
    }
  }
  return num;
}

uint8_t readnumber2(void) {
  uint8_t num = 0;

  while (num == 0) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Insert (1 to 10)");
    lcd.setCursor(0, 1);
    lcd.print("To delete");
    Serial.println(num);
    char key = keypad.getKey();
    if (key >= '0' && key <= '9')  // it's a digit
    {
      num = num * 10 + (key - '0');
    }

    else if (key == '>') {
      // step clockwise
      num = 0;  // Once the  stepper has stepped, reset Value back  to zero.
    }

    else if (key == '<') {
      // step C-clockwise
      num = 0;  // Once the  stepper has stepped, reset Value back  to zero.
    }
  }
  return num;
}

void loop() {
  Serial.println(Value);
  while (Value == 1) {
    Serial.println(v_passcode);
    char key = keypad.getKey();
    lcd.clear();
    if (key != NO_KEY) {
      Serial.println("Ini didalem");

      //Serial.println(key);

      v_passcode = v_passcode + key;
      Serial.println(v_passcode);
      if (key == 'D') {
        String pass = "000D";
        String v_passcode = "";
        Serial.println("Validate the Password");
        if (v_passcode == pass) {
          Serial.println("Access Granted");
          lcd.setCursor(1, 0);
          lcd.print("1. Enroll");
          lcd.setCursor(1, 1);
          lcd.print("2. Delete    ->");
          Trig = Trig + 1;
          Serial.println(Trig);
          v_passcode = "";
          while (Trig == 1) {
            key = keypad.getKey();
            Serial.println(key);
            if (key == 'A') {
              Trig = 0;
            }
            if (key == 'H') {
              lcd.clear();
              lcd.setCursor(1, 0);
              lcd.print("3. Set Password");
              lcd.setCursor(1, 1);
              lcd.print("            <-");
            }
            if (key == 'S') {
              lcd.clear();
              lcd.setCursor(1, 0);
              lcd.print("1. Enroll");
              lcd.setCursor(1, 1);
              lcd.print("2. Delete    ->");
            }
            if (key == '1') {
              lcd.clear();
              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);

              while (!getFingerprintEnroll())
                ;
              Serial.print("Enrolling ID #");
              Serial.println(id);
              ;
              Trig = 0;
            } else if (key == '2') {
              Serial.println("Please type in the ID # (from 1 to 127) you want to delete...");
              uint8_t id = readnumber2();
              if (id == 0) {  // ID #0 not allowed, try again!
                return;
              }
              Serial.print("Deleting ID #");
              Serial.println(id);
              deleteFingerprint(id);
              Trig = 0;
            } else if (key == '3') {
              lcd.clear();
              Trig2 = Trig2 + 1;
              lcd.setCursor(1, 0);
              lcd.print("Input Password");
              while (Trig2 == 1) {
                key = keypad.getKey();
                Serial.println(key);
                if (key != NO_KEY) {
                  v_passcode = v_passcode + key;
                  pass = v_passcode;
                  lcd.clear();
                  lcd.setCursor(1, 0);
                  lcd.print(v_passcode);
                  Serial.println(v_passcode);
                  if (key == 'A') {
                    lcd.clear();
                    v_passcode = "";
                  }
                  if (key == 'D') {
                    lcd.setCursor(1, 0);
                    lcd.print("Password Set!");
                    delay(1000);
                    Trig2 = 0;
                    Trig = 0;
                    pass != "000D";
                    v_passcode = "";
                  }
                }
              }
            }
          }
        } 
        else {
          Serial.println("Access Denied");
          v_passcode = "";
          delay(1000);
        }
      }
    }
  }
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      char key = keypad.getKey();
      if (key) {
        Value = 1;
      }
      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.fingerSearch();
  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;
}



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

uint8_t deleteFingerprint(uint8_t id) {
  uint8_t p = -1;

  p = finger.deleteModel(id);

  if (p == FINGERPRINT_OK) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Deleted!");
    delay(1000);
    Serial.println("Deleted!");
    lcd.clear();
    Value = 0;
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not delete in that location");
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
  } else {
    Serial.print("Unknown error: 0x");
    Serial.println(p, HEX);
  }

  return p;
}


uint8_t getFingerprintEnroll() {
  int p = -1;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Place your");
  lcd.setCursor(0, 1);
  lcd.print("finger");
  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:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Error");
      delay(1000);
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Error");
      delay(1000);
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Remove Finger");
  Serial.println("Remove finger");
  delay(2000);
  lcd.clear();
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID ");
  Serial.println(id);
  p = -1;
  lcd.clear();
  lcd.print("Place same");
  lcd.setCursor(0, 1);
  lcd.print("finger again");
  Serial.println("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:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Error");
      delay(1000);
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Error");
      delay(1000);
      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) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Failed!");
    delay(1000);
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID ");
  Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Done!");
    delay(2000);
    lcd.clear();
    Serial.println("Stored!");
    Value = 0;
  } 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;
  }

  return true;
}

Brother i think you should look up your if conditions in the loop section because your first if clause closes after the else part so the rest . I don't know how each conditions should work .But the code you Provided would not work until you press "D" other than would go to false part. I'll think arranging the condition statements should solve your problem
Problem part


void loop() {
  Serial.println(Value);
  while (Value == 1) {
    Serial.println(v_passcode);
    char key = keypad.getKey();
    lcd.clear();
    if (key != NO_KEY) {
      Serial.println("Ini didalem");

      //Serial.println(key);

      v_passcode = v_passcode + key;
      Serial.println(v_passcode);
      if (key == 'D') {
        String pass = "000D";
        String v_passcode = "";
        Serial.println("Validate the Password");
        if (v_passcode == pass) {
          Serial.println("Access Granted");
          lcd.setCursor(1, 0);
          lcd.print("1. Enroll");
          lcd.setCursor(1, 1);
          lcd.print("2. Delete    ->");
          Trig = Trig + 1;
          Serial.println(Trig);
          v_passcode = "";
          while (Trig == 1) {
            key = keypad.getKey();
            Serial.println(key);
            if (key == 'A') {
              Trig = 0;
            }
            if (key == 'H') {
              lcd.clear();
              lcd.setCursor(1, 0);
              lcd.print("3. Set Password");
              lcd.setCursor(1, 1);
              lcd.print("            <-");
            }
            if (key == 'S') {
              lcd.clear();
              lcd.setCursor(1, 0);
              lcd.print("1. Enroll");
              lcd.setCursor(1, 1);
              lcd.print("2. Delete    ->");
            }
            if (key == '1') {
              lcd.clear();
              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);

              while (!getFingerprintEnroll())
                ;
              Serial.print("Enrolling ID #");
              Serial.println(id);
              ;
              Trig = 0;
            } else if (key == '2') {
              Serial.println("Please type in the ID # (from 1 to 127) you want to delete...");
              uint8_t id = readnumber2();
              if (id == 0) {  // ID #0 not allowed, try again!
                return;
              }
              Serial.print("Deleting ID #");
              Serial.println(id);
              deleteFingerprint(id);
              Trig = 0;
            } else if (key == '3') {
              lcd.clear();
              Trig2 = Trig2 + 1;
              lcd.setCursor(1, 0);
              lcd.print("Input Password");
              while (Trig2 == 1) {
                key = keypad.getKey();
                Serial.println(key);
                if (key != NO_KEY) {
                  v_passcode = v_passcode + key;
                  pass = v_passcode;
                  lcd.clear();
                  lcd.setCursor(1, 0);
                  lcd.print(v_passcode);
                  Serial.println(v_passcode);
                  if (key == 'A') {
                    lcd.clear();
                    v_passcode = "";
                  }
                  if (key == 'D') {
                    lcd.setCursor(1, 0);
                    lcd.print("Password Set!");
                    delay(1000);
                    Trig2 = 0;
                    Trig = 0;
                    pass != "000D";
                    v_passcode = "";
                  }
                }
              }
            }
          }
        } 
        else {
          Serial.println("Access Denied");
          v_passcode = "";
          delay(1000);
        }
      }
    }
  }

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

1 Like

100 lines of a 500 line program is the problem part? Ignore the 100 Serial.print(), 50 "return" and 70 close braces makes 100 out of 250 lines the problem part...

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