Entering password problem

Hello all, i am making a security system for a school project. When/while my alarm is activated with the PIR sensor, it does not allow me to enter the password. I tried using the while statement but having no luck.

Any ideas?

Thank You

You may have a software problem.

.

im not sure I i think its my code

void loop(){
  keypad.getKey();
  
   if(activated){
    
    activateMotion = true;
  }

if(activateMotion == true){
  
  lcd.setCursor(0,0);
  lcd.print("  MOTION ALARM");
  lcd.setCursor(0,1);
  lcd.print("ACTIVATING IN");
    
    int countdown = 9; // 9 second count down before activating the alarm
    while(countdown != 0){
    lcd.setCursor(14,1);
    lcd.print(countdown);
    countdown--;
    tone(Buzz,700,100);
    delay(1000);
  }
  
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  MOTION ALARM");
  lcd.setCursor(0,1);
  lcd.print("   ACTIVATED");
  tone(Buzz,1110,700);
  delay(2500);
  activateMotion = false;
  MalarmActivated = true;
  activated=false;
  lcd.clear();
  
  }

if(MalarmActivated == true){
    
  
  Pval = digitalRead(PIR);  // read input value
  
  if (Pval == HIGH) {            // check if the input is HIGH
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" *** ALARM *** ");
    
    
    digitalWrite(relay, HIGH);
    digitalWrite(RED, HIGH);  // turn LED ON
    
    delay(1000);
    lcd.clear();
    playTone(300, 160);
    delay(100);
    lcd.clear();
    checkPassword();
    keypad.getKey();
    
 
}
}

}
void checkPassword(){

  while(MalarmActivated){
    keypad.getKey();
  }
   
  if (password.evaluate()){
    password.reset();
    activated = true; 
  }

else if(password2.evaluate()){
  
  password2.reset();
  activated = false;
  MalarmActivated = false; 
  digitalWrite(relay, LOW);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN,HIGH); //RED Light will turn on
   
    tone(Buzz,1000,1000);
    delay(100);
    tone(Buzz,500,100);
    lcd.setCursor(0,0);
    lcd.print("  MOTION ALARM");
    lcd.setCursor(0,1);
    lcd.print("  DEACTIVATED");
    delay(1000);
    lcd.clear();
    digitalWrite(GREEN,LOW); //RED light will turn off
  
}

else{  //if password is wrong 
  password.reset();
  password2.reset();
  tone(Buzz,1600,1500);
  lcd.setCursor(0,0);
  lcd.print("INVALID PASSWORD");
  password.reset(); //resets password after incorrect entry
  digitalWrite(RED,HIGH); //RED Light will turn on
  delay(4000); // wait 5 seconds
  digitalWrite(RED,LOW); //RED light will turn off
  lcd.clear();
}

}

Using delay() freezes code execution for that amount of time, during which nothing can happen.

.

My PIR sensor is blocking my keypad when it is activated. How can i code it to fix this problem?

Don't write the PIR code to block.

.

i don't understand how I'am blocking it. How am i suppose to code it?
is there another way other than using the while statement?

You can test a condition with an 'if' statement, then operate on code when the conditions are met.

Using an 'if' you avoid blocking.

.

how is this blocking me from pressing numbers on the keypad? it doesn't make sense to me. Sorry for asking too many questions, but just can seem to figure it out.

if(MalarmActivated == true){

   if(digitalRead(PIR)== HIGH){
    MotionAlarmTriggered();
    
    
    
    }
    }
    } //void loop ends

void MotionAlarmTriggered(){
    
    lcd.setCursor(0,0);
    lcd.print(" *** ALARM *** ");
    digitalWrite(relay, HIGH);
    digitalWrite(RED, HIGH); 
    delay(1000);
    
    playTone(300, 160);
    deactivate();
     
}

void deactivate(){
  
  
  password2.evaluate(); // password to turn off alarm but when pir is high it blocks me from pressing keypad 
  keypad.getKey();
  
  }

You are only showing snippets from your sketch.

Using delay() freezes your sketch for that amount of time.

.

Thank you for your help sir, The problem was my void playTone().

Good for you for finding the problem.

.