keypad password

Hi,

I got a keypad to switch relays when they use the correct code.
when the playeris entering the good code, it switch the relays.
When the player is entering the wrong code, he must try again.

but when I enter a wrong code, the correct code will not work anymore. It appears that he no longer recognized the correct code.

can anyone help me with?

#include <Keypad.h>
#include <Password.h>

Password password = Password( "4317" ); //password to unlock box, can be changed


const byte ROWS = 4; //4 rijen
const byte COLS = 3; //3 kolommen
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'},

};
byte rowPins[ROWS] = {10 ,9, 8, 7}; //connect to 4567
byte colPins[COLS] = {6, 5, 4}; //connect to 8910
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



void setup(){
  Serial.begin(9600);
  Serial.write(254);
  Serial.write(0x01);
  delay(200); 
  pinMode(A0, OUTPUT);  //buzzer1
  pinMode(13, OUTPUT);  //relay1
   pinMode(11, OUTPUT);  //relay2
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  
 }

void loop() {

 keypad.getKey();
  }
  void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
  
  Serial.print("Enter: ");
  Serial.println(eKey);
  digitalWrite(A0, HIGH); //buzzer on
  delay(10);
  digitalWrite(A0, LOW); //buzzer off
  
  
  Serial.write(254);
  
  switch (eKey){
    case '#': checkPassword(); delay(1); break;
    
  case '*': password.reset(); delay(1); break;
    
     default: password.append(eKey); delay(1);
}
}
}
void checkPassword(){
  
if (password.evaluate()){  //if password is right open box
    
    Serial.println("Accepted");
    Serial.write(254);delay(10);
       digitalWrite(A0, HIGH);//turn BUZZER on
         digitalWrite(13, HIGH);//turn RELAY on
           digitalWrite(11, HIGH);//turn RELAY on
            delay(2000); //wait 2 seconds
          digitalWrite(A0, LOW);// turn BUZZER off
    delay(3000); //wait 5 seconds
    digitalWrite(13, LOW);//turn relay off
      delay(3600000); //wait 60 minutes
    
}else{
    Serial.println("Denied"); //if passwords wrong keep box locked
    Serial.write(254);delay(10);
    digitalWrite(A0, HIGH); //turn on
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, LOW);//turn off
   delay(300); //wait 0,3 seconds
       digitalWrite(A0, HIGH); //turn on
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, LOW);//turn off
   delay(300); //wait 0,3 seconds
       digitalWrite(A0, HIGH); //turn on
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, LOW);//turn off
   delay(300); //wait 0,3 seconds
}}

(deleted)

i didn't clear..
but now i try to use flush but it will not clear.

Lots of functions appear to be missing from the posted code (such as password.evaluate()). Also your layout is a mess - do a CTRL-T in the ARduino IDE to clean it up, and then please post complete code.

solved.
just added password.reset() .
see code.

#include <Keypad.h>
#include <Password.h>

Password password = Password( "4317" ); //password to unlock box, can be changed


const byte ROWS = 4; //4 rijen
const byte COLS = 3; //3 kolommen
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'},

};
byte rowPins[ROWS] = {10 , 9, 8, 7}; //connect to 4567
byte colPins[COLS] = {6, 5, 4}; //connect to 8910
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



void setup() {
  Serial.begin(9600);
  Serial.write(254);
  Serial.write(0x01);
  delay(200);
  pinMode(A0, OUTPUT);  //buzzer1
  pinMode(13, OUTPUT);  //relay1(lade open)
  pinMode(11, OUTPUT);  //relay2 (volgende puzzel aan)
  pinMode(12, OUTPUT);   //relay 3 (morse ledjes)
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad

}

void loop() {

  keypad.getKey();
}
void keypadEvent(KeypadEvent eKey) {
  switch (keypad.getState()) {
    case PRESSED:

      Serial.print("Enter: ");
      Serial.println(eKey);
      digitalWrite(A0, HIGH); //buzzer on
      delay(10);
      digitalWrite(A0, LOW); //buzzer off


      Serial.write(254);

      switch (eKey) {
        case '#': checkPassword(); delay(1); break;

        case '*': password.reset(); delay(1); break;

        default: password.append(eKey); delay(1);
      }
  }
}
void checkPassword() {

  if (password.evaluate()) { //if password is right open box

    Serial.println("Accepted");
    Serial.write(254); delay(10);
    digitalWrite(A0, HIGH);//turn BUZZER on
    digitalWrite(13, HIGH);//turn RELAY on
    digitalWrite(11, HIGH);//turn RELAY on
    digitalWrite(12, HIGH); //morse ledjes uit
    delay(2000); //wait 2 seconds
    digitalWrite(A0, LOW);// turn BUZZER off
    delay(3600000); //wait 5 seconds



  } else {
    Serial.println("Denied"); //if passwords wrong keep box locked
    Serial.write(254); delay(10);
    digitalWrite(A0, HIGH); //turn on
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, LOW);//turn off
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, HIGH); //turn on
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, LOW);//turn off
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, HIGH); //turn on
    delay(300); //wait 0,3 seconds
    digitalWrite(A0, LOW);//turn off
    delay(300); //wait 0,3 seconds
password.reset(); 


  }
}

where i can get password.h library from????????????

RefAatNa:
where i can get password.h library from????????????

You already posted this question in a new thread. Why revive an old one?

Google search for: password library arduino

https://playground.arduino.cc/Code/Password/

How can the password be changed later when occupying the library?
I currently have that problem

Gunfred:
How can the password be changed later when occupying the library?
I currently have that problem

Post your code.

in case you haven't done so yet, please read How to use this forum - please read - Website and Forum - Arduino Forum. For posting code, pay specific attention to point #7.