Problem with "while" statement

I just found another forum topic which had the same problem:


with a 200 ohm for R1
Using:

const int buttonPinOpen = A5;

void setup() {
  Serial.begin(9600);
  pinMode(5, INPUT_PULLUP);
}

void loop() {
  Serial.print("test Analog");
  Serial.println(digitalRead(buttonPinOpen));
  delay(333);
}

I do get "1" when the rocker is "on" (LED on) and "0" when "off", but it is "enough" to fit in the whole project.

Strangely, in the post, everyone told the guy that he had to use digital pins, but no one could figure out why it was only working with analog. https://forum.arduino.cc/t/rocket-switch-3-pin-with-led-not-working/615952/10

Hi Idahowalker,
now that the rocker is fixed, I was wondering if you know why, with your code, the last LED (6) is not lighting as the others, its intensity is much lower. It is not really a problem when it is turning rapidly, but still, I can't figure out why.
I have tried to light only this one, in case this would be hardware problem, but it does light normally, so it is linked to the code.
I have also tried to inverse the last 2 in the code (lighting 1,2,3,4,6,5) and without surprise, the 5 is now the one with lower intensity, so it is definitely from the code


int var1 = 0;
const unsigned long Count2K = 2000;
const unsigned long Count200 = 100;

unsigned long pastMotorTicks = millis();
unsigned long pastLEDTicks = millis();

//declare the two rockers
const int buttonPinOpen = A14;
const int buttonPinClose = A15;
//declare the motor states
int motorState = 0;
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;
//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3
//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//declare the LED
#define LED 41
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;
// Motor A connections
int enA = 12;
int in1 = 42;
int in2 = 43;
// Motor B connections
int enB = 13;
int in3 = 44;
int in4 = 45;
// Motor C connections
int enC = 10;
int in5 = 46;
int in6 = 47;
// Motor D connections
int enD = 11;
int in7 = 48;
int in8 = 49;
// Motor E connections
int enE = 1;
int in9 = 50;
int in10 = 51;
// Motor F connections
int enF = 2;
int in11 = 52;
int in12 = 53;

void setup() {
  Serial.begin(9600);
  input_password.reserve(32); // maximum input characters is 33, change if needed
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
    // Set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(enC, OUTPUT);
  pinMode(enD, OUTPUT);
  pinMode(enE, OUTPUT);
  pinMode(enF, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(in5, OUTPUT);
  pinMode(in6, OUTPUT);
  pinMode(in7, OUTPUT);
  pinMode(in8, OUTPUT);
  pinMode(in9, OUTPUT);
  pinMode(in10, OUTPUT);
  pinMode(in11, OUTPUT);
  pinMode(in12, OUTPUT);
  // Turn off motors - Initial motorState
  TurnOffMotors();
  MotorsToMaximumSpeed();

}

//Set Max speed Motors
void MotorsToMaximumSpeed()
{
  analogWrite(enA, 255);
  analogWrite(enB, 255);
  analogWrite(enC, 255);
  analogWrite(enD, 255);
  analogWrite(enE, 255);
  analogWrite(enF, 255);
}

//Turn off motors - Initial motorState
void TurnOffMotors()
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  digitalWrite(in5, LOW);
  digitalWrite(in6, LOW);
  digitalWrite(in7, LOW);
  digitalWrite(in8, LOW);
  digitalWrite(in9, LOW);
  digitalWrite(in10, LOW);
  digitalWrite(in11, LOW);
  digitalWrite(in12, LOW);
}


void loop()
{
  char key = keypad.getKey();
  // read the motorState of the pushbutton value:
  buttonmotorStateOpen = digitalRead(A14);
  buttonmotorStateClose = digitalRead(buttonPinClose);
  if (key)
  {
    if (digitalRead(A14) == LOW)
    {
      lcd.clear();
      lcd.print("Select button");
      delay(2000);
      lcd.clear();
      lcd.print("Welcome");
      lcd.setCursor(0, 1);
      lcd.print("Select button");
      lcd.setCursor(0, 0);
    }
  }

  if (digitalRead(A14) == HIGH) 
  {
    //lcd.clear();
    //lcd.print("Type code"); 
    if (key)
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          pinMode(LED_5, OUTPUT);
          digitalWrite(LED_5, LOW);
          pinMode(LED_4, OUTPUT);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          //while loop to have red lights
          while (var1 < 1) 
          {

            ledloop();
            ClosePiston();
          };
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }

}

// This function lets you control spinning direction of motors
void ClosePiston()
{

  switch ( motorState )
  {
    case 0 :
      // Turn on motor A
      lcd.clear();
      lcd.print("Lock A");
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      pastMotorTicks = millis();
      motorState = 1;
      break;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor B
        lcd.clear();
        lcd.print("Lock B");
        digitalWrite(in3, HIGH);
        digitalWrite(in4, LOW);
        pastMotorTicks = millis();
        motorState = 2;
      }
      break;
    case 2 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor C
        lcd.clear();
        lcd.print("Lock C");
        digitalWrite(in5, HIGH);
        digitalWrite(in6, LOW);
        pastMotorTicks = millis();
        motorState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor D
        lcd.clear();
        lcd.print("Lock D");
        digitalWrite(in7, HIGH);
        digitalWrite(in8, LOW);
        pastMotorTicks = millis();
        motorState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor E
        lcd.clear();
        lcd.print("Lock E");
        digitalWrite(in9, HIGH);
        digitalWrite(in10, LOW);
        //delay(2000);
        pastMotorTicks = millis();
        motorState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor F
        lcd.clear();
        lcd.print("Lock F");
        digitalWrite(in11, HIGH);
        digitalWrite(in12, LOW);
        pastMotorTicks = millis();
        motorState = 6;
      }
      break;
    case 6:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn off motors
        digitalWrite(in1, LOW);
        pastMotorTicks = millis();
        motorState = 7;
      }
      break;
    case 7:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in3, LOW);
        pastMotorTicks = millis();
        motorState = 8;
      }
      break;
    case 8:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in5, LOW);
        pastMotorTicks = millis();
        motorState = 9;
      }
      break;
    case 9:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in7, LOW);
        pastMotorTicks = millis();
        motorState = 10;
      }
      break;
    case 10:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in9, LOW);
        pastMotorTicks = millis();
        motorState = 11;
      }
      break;
    case 11:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in11, LOW);
        lcd.clear();
        lcd.print("All closed");
        lcd.setCursor(0, 1);
        lcd.print("stop button");
        lcd.setCursor(0, 0);
        var1++;
        motorState = 0;
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(10000);        
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, LOW);      
        lcd.clear();
        lcd.print("Welcome");
        lcd.setCursor(0, 1);
        lcd.print("Select button");
        lcd.setCursor(0, 0);
        pinMode(LED_5, OUTPUT);
        digitalWrite(LED_5, HIGH);  

      }
      break;
    default:
      TurnOffMotors();
      motorState = 0;
      break;
  }
}
void ledloop()
{
  switch ( ledState )
  {
    case 0:
      //turn on LED L1
      pinMode(LED_1, OUTPUT);     //row 1
      digitalWrite(LED_1, LOW);
      pinMode(LED_2, OUTPUT);     //row 2
      digitalWrite(LED_2, HIGH);
      pinMode(LED_3, INPUT);      //row 3
      digitalWrite(LED_3, LOW);
      pastLEDTicks = millis();
      ledState = 1;
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, INPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
  }
}

Another question. I understood that it is not perfect to have the rocker on the analog, but apparently, this is the only way to make it work. Still, when the rocker is on, the LCD seems to go down in contrast (not enough current). Is there anything that can be done? I guess that the button, when "on", is simply sucking the energy from the arduino, right?

Thanks for your precious help
Julien

I wouldn't think you would need anything as low as 200 ohm for R1, 10K would probably be fine, it should just be a pull-down for when the switch is OFF.

Can you post a link or model number of the exact switch you have?

No idea why a digital input could not be used, although in the post you linked the final working code was never posted.

@courju would begging help? I may not be the only person here with no clue as to what is going on inside the rocker switch.

TIA

a7

you mean that 10k would help to draw less power to the rest, and remove the effect on the LCD then? is it?

working on it ...

1 Like

That was my intent, to reduce the current draw. Might also be possible to reduce the LED current by placing a resistor in the ground connection for the LED.


So ... I can't really give more than that ...

As said above, the idea is that the potentio is used for the LCD contrast.
The blue light is on from the start
The LCD ask for a code, that can only be starting when the switch for opening is "on".
When the switch is "on", it is possible to make the password.
When the password is ok, the red light move, and the motor work. When done, the red LED go off, and the green are on.
Same must go to "close" the motors. (not yet in the code).

Current code is:


int var1 = 0;
const unsigned long Count2K = 2000;
const unsigned long Count200 = 100;

unsigned long pastMotorTicks = millis();
unsigned long pastLEDTicks = millis();

//declare the two rockers
const int buttonPinOpen = A14;
const int buttonPinClose = A15;
//declare the motor states
int motorState = 0;
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;
//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3
//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//declare the LED
#define LED 41
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;
// Motor A connections
int enA = 12;
int in1 = 42;
int in2 = 43;
// Motor B connections
int enB = 13;
int in3 = 44;
int in4 = 45;
// Motor C connections
int enC = 10;
int in5 = 46;
int in6 = 47;
// Motor D connections
int enD = 11;
int in7 = 48;
int in8 = 49;
// Motor E connections
int enE = 1;
int in9 = 50;
int in10 = 51;
// Motor F connections
int enF = 2;
int in11 = 52;
int in12 = 53;

void setup() {
  Serial.begin(9600);
  
  input_password.reserve(32); // maximum input characters is 33, change if needed
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
    // Set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(enC, OUTPUT);
  pinMode(enD, OUTPUT);
  pinMode(enE, OUTPUT);
  pinMode(enF, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(in5, OUTPUT);
  pinMode(in6, OUTPUT);
  pinMode(in7, OUTPUT);
  pinMode(in8, OUTPUT);
  pinMode(in9, OUTPUT);
  pinMode(in10, OUTPUT);
  pinMode(in11, OUTPUT);
  pinMode(in12, OUTPUT);
  // Turn off motors - Initial motorState
  TurnOffMotors();
  MotorsToMaximumSpeed();

}

//Set Max speed Motors
void MotorsToMaximumSpeed()
{
  analogWrite(enA, 255);
  analogWrite(enB, 255);
  analogWrite(enC, 255);
  analogWrite(enD, 255);
  analogWrite(enE, 255);
  analogWrite(enF, 255);
}

//Turn off motors - Initial motorState
void TurnOffMotors()
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  digitalWrite(in5, LOW);
  digitalWrite(in6, LOW);
  digitalWrite(in7, LOW);
  digitalWrite(in8, LOW);
  digitalWrite(in9, LOW);
  digitalWrite(in10, LOW);
  digitalWrite(in11, LOW);
  digitalWrite(in12, LOW);
}


void loop()
{
  char key = keypad.getKey();
  // read the motorState of the pushbutton value:
  buttonmotorStateOpen = digitalRead(A14);
  buttonmotorStateClose = digitalRead(buttonPinClose);
  if (key)
  {
    if (digitalRead(A14) == LOW)
    {
      lcd.clear();
      lcd.print("Select button");
      delay(2000);
      lcd.clear();
      lcd.print("Welcome");
      lcd.setCursor(0, 1);
      lcd.print("Select button");
      lcd.setCursor(0, 0);
    }
  }

  if (digitalRead(A14) == HIGH) 
  {
    //lcd.clear();
    //lcd.print("Type code"); 
    if (key)
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          pinMode(LED_5, OUTPUT);
          digitalWrite(LED_5, LOW);
          pinMode(LED_4, OUTPUT);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          //while loop to have red lights
          while (var1 < 1) 
          {

            ledloop();
            ClosePiston();
          };
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }

}

// This function lets you control spinning direction of motors
void ClosePiston()
{

  switch ( motorState )
  {
    case 0 :
      // Turn on motor A
      lcd.clear();
      lcd.print("Lock A");
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      pastMotorTicks = millis();
      motorState = 1;
      break;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor B
        lcd.clear();
        lcd.print("Lock B");
        digitalWrite(in3, HIGH);
        digitalWrite(in4, LOW);
        pastMotorTicks = millis();
        motorState = 2;
      }
      break;
    case 2 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor C
        lcd.clear();
        lcd.print("Lock C");
        digitalWrite(in5, HIGH);
        digitalWrite(in6, LOW);
        pastMotorTicks = millis();
        motorState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor D
        lcd.clear();
        lcd.print("Lock D");
        digitalWrite(in7, HIGH);
        digitalWrite(in8, LOW);
        pastMotorTicks = millis();
        motorState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor E
        lcd.clear();
        lcd.print("Lock E");
        digitalWrite(in9, HIGH);
        digitalWrite(in10, LOW);
        //delay(2000);
        pastMotorTicks = millis();
        motorState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn on motor F
        lcd.clear();
        lcd.print("Lock F");
        digitalWrite(in11, HIGH);
        digitalWrite(in12, LOW);
        pastMotorTicks = millis();
        motorState = 6;
      }
      break;
    case 6:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        // Turn off motors
        digitalWrite(in1, LOW);
        pastMotorTicks = millis();
        motorState = 7;
      }
      break;
    case 7:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in3, LOW);
        pastMotorTicks = millis();
        motorState = 8;
      }
      break;
    case 8:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in5, LOW);
        pastMotorTicks = millis();
        motorState = 9;
      }
      break;
    case 9:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in7, LOW);
        pastMotorTicks = millis();
        motorState = 10;
      }
      break;
    case 10:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in9, LOW);
        pastMotorTicks = millis();
        motorState = 11;
      }
      break;
    case 11:
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        digitalWrite(in11, LOW);
        lcd.clear();
        lcd.print("All closed");
        lcd.setCursor(0, 1);
        lcd.print("stop button");
        lcd.setCursor(0, 0);
        var1++;
        motorState = 0;
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(10000);        
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, LOW);      
        lcd.clear();
        lcd.print("Welcome");
        lcd.setCursor(0, 1);
        lcd.print("Select button");
        lcd.setCursor(0, 0);
        pinMode(LED_5, OUTPUT);
        digitalWrite(LED_5, HIGH);  

      }
      break;
    default:
      TurnOffMotors();
      motorState = 0;
      break;
  }
}
void ledloop()
{
  switch ( ledState )
  {
    case 0:
      //turn on LED L1
      pinMode(LED_1, OUTPUT);     //row 1
      digitalWrite(LED_1, LOW);
      pinMode(LED_2, OUTPUT);     //row 2
      digitalWrite(LED_2, HIGH);
      pinMode(LED_3, INPUT);      //row 3
      digitalWrite(LED_3, LOW);
      pastLEDTicks = millis();
      ledState = 1;
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, INPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
  }
}

Could you better figure it out?

@courju can you explain me why are you using pinMode "input" for leds ?

And also why insted of declaring pinMode in void setup for single time. You are using pinMode function multiple times

this did work well ! Thanks

So, the various problem of button have been solved.
Still the code is not fully working. It seems that it can't really get out of the LED loop.

Here a video of the system now, with the code below:
https://1drv.ms/v/s!AmQCAddskXi4hJ4AZvogie8FmPeOSQ?e=s5oD3e

int var1 = 0;
const unsigned long Count200 = 100;
//full time for the actuator
const unsigned long ActuatorTime = 10000;


unsigned long pastLEDTicks = millis();
//use the Long for checking current Millis
unsigned long currentMillis;

//declare the two rockers
const int buttonPinOpen = A14;
const int buttonPinClose = A15;
//declare the LED states
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
//declare the speaker output
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;
//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3
//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//declare the LED
#define LED 41
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;

// Declare constant for actuator A
const int ENA_PIN = 51; // the Arduino pin connected to the ENA pin L298N
const int IN1_PIN = 49; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 50; // the Arduino pin connected to the IN2 pin L298N
// Declare constant for actuator B
const int ENB_PIN = 53; // the Arduino pin connected to the ENB pin L298N
const int IN3_PIN = 52; // the Arduino pin connected to the IN3 pin L298N
const int IN4_PIN = 48; // the Arduino pin connected to the IN4 pin L298N

void setup() {
  Serial.begin(9600);
  //introduce code for speakers
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    while(true);
  }
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  myDFPlayer.volume(30);  //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

  input_password.reserve(32); // maximum input characters is 33, change if needed
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);  
  // Initialize motorA
  pinMode(ENA_PIN, OUTPUT);
  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);
  digitalWrite(ENA_PIN, HIGH);
    // Initialize motorB
  pinMode(ENB_PIN, OUTPUT);
  pinMode(IN3_PIN, OUTPUT);
  pinMode(IN4_PIN, OUTPUT);
  digitalWrite(ENB_PIN, HIGH);
  //Initiate programm
  StartStatus();
}

void loop()
{
  Serial.println(var1);
  char key = keypad.getKey();
  if (key)
  {
    //int var1 = 0;
    if (digitalRead(A14) == LOW && digitalRead(A15) == LOW)
    {
      lcd.clear();
      lcd.print("Select button");
      myDFPlayer.playMp3Folder(1);
      input_password = "";
      delay(2000);
      lcd.clear();
      lcd.print("Welcome");
      lcd.setCursor(0, 1);
      lcd.print("Select button");
      lcd.setCursor(0, 0);
    }
    else if (digitalRead(A14) == HIGH && digitalRead(A15) == HIGH)
    {
      lcd.clear();
      lcd.print("Too many button");
      input_password = "";
      delay(2000);
      lcd.clear();
      lcd.print("Welcome");
      lcd.setCursor(0, 1);
      lcd.print("Select button");
      lcd.setCursor(0, 0);
    }
    else if (digitalRead(A15) == HIGH && digitalRead(A14) == LOW) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          int var1 = 0;
          pinMode(LED_5, OUTPUT);
          digitalWrite(LED_5, LOW);
          pinMode(LED_4, OUTPUT);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          //while loop to have red lights
          while (var1 < 1) 
          {
            ClosePiston();
            //ledloop();
          }
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
    else if (digitalRead(A15) == LOW && digitalRead(A14) == HIGH) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          int var1 = 0;
          pinMode(LED_5, OUTPUT);
          digitalWrite(LED_5, LOW);
          pinMode(LED_4, OUTPUT);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          digitalWrite(LED_4, HIGH);
          delay(200);
          digitalWrite(LED_4, LOW);
          delay(200);
          //while loop to have red lights
          while (var1 < 1) 
          {
            //Print and say the message
            lcd.clear();
            lcd.print("Unlocking door");
            myDFPlayer.playMp3Folder(1);
            OpenPiston();
            //ledloop();
          };
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }
}

void StartStatus()//This should start the programm
{
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // Print a message to the LCD.
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  myDFPlayer.playMp3Folder(1); //Play sound
}

void ClosePiston()// This function closes the actuators
{
  //Print and say the message
  lcd.clear();
  lcd.print("Locking door");
  myDFPlayer.playMp3Folder(1);
  //leave the actuator to open for 10sec
  currentMillis = millis();
  while(millis()-currentMillis < ActuatorTime)
  {
    ledloop();
    digitalWrite(IN1_PIN, LOW);
    digitalWrite(IN2_PIN, HIGH);
    digitalWrite(IN3_PIN, LOW);
    digitalWrite(IN4_PIN, HIGH);
  }  
  //stop the motor
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  digitalWrite(IN3_PIN, LOW);
  digitalWrite(IN4_PIN, LOW);
  //change the LCD
  lcd.clear();
  lcd.print("All closed");
  lcd.setCursor(0, 1);
  lcd.print("stop button");
  lcd.setCursor(0, 0);
  //Update the LEDs
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, HIGH);
  //add some delay
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, LOW);      
  lcd.clear();
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);  
  var1++;
}
// This function opens the actuators
void OpenPiston()
{

  //leave the actuator to open for 10sec
  currentMillis = millis();
  while(millis()-currentMillis < ActuatorTime)
  {
    ledloop();
    digitalWrite(IN1_PIN, HIGH);
    digitalWrite(IN2_PIN, LOW);
    digitalWrite(IN3_PIN, HIGH);
    digitalWrite(IN4_PIN, LOW);
  } 
  //stop the motor
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  digitalWrite(IN3_PIN, LOW);
  digitalWrite(IN4_PIN, LOW);
  //change the LCD
  lcd.clear();
  lcd.print("All open");
  lcd.setCursor(0, 1);
  lcd.print("stop button");
  lcd.setCursor(0, 0);
  //Update the LEDs
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, HIGH);
  //add some delay
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, LOW);      
  lcd.clear();
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);  
  var1++;
}
void ledloop()
{
  switch ( ledState )
  {
    case 0:
      if ( (millis() - pastLEDTicks) >= Count200 ) {
        //turn on LED L1
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, INPUT);     //row 2
        digitalWrite(LED_3, LOW);
        pinMode(LED_2, OUTPUT);      //row 3
        digitalWrite(LED_2, HIGH);
        pastLEDTicks = millis();
        ledState = 1;
      }
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        pinMode(LED_2, INPUT);    //row 1
        digitalWrite(LED_2, LOW);
        pinMode(LED_1, OUTPUT);     //row 2
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
    
  }
}

Again, a summary of the goal:
the general idea: I have:

-the LCD
-the speakers (so far I only created 0001, but depending on the action I would do other mp3 corresponding to the message to be said)
-the red LEDs in charlieplexing
-the blue LEDs
-the green LEDs
-the actuator A&B (that we run at the same time and have automated start stop)
-the keypad
-the button Open and Close

A1: When powering, LCD must show "welcome", and maybe speakers say 0001. LED blue is on.
A2: When touching keypad, LCD ask to set a button, and red LED blink 2x (using fast switch of 2ms for the whole code you made, this works), speakers tells to select a button (0002). Then after 5sec, it turns back to A1 again
A3: Button OPen and BUtton Close are now switched on, touching keypad triggers a LCD text that you have 2 buttons open, red LED blink 2x, speakers tells to close one button (0003), After 5 sec, it turns back to A1 again
A4: Button Open is on but Close is off, touching keypad triggers speaker to say "enter your code", and while you type, you see your code on the LCD. When you press "#", it checks if the code is right.
A4a: the code is wrong, the red LED blink 2x, the LCD says "incorrect", the speaker says "incorrect" (0004), it waits 2 sec and the LCD write "enter code again"
A4b: the code is right, the red lights starts turning around, while the Speaker says "opening the lock" (0005), and Motor A&B are opening. After 15sec, the LED green light on, the LCD says "door opened", the speaker "the door can be opened" (0005). It waits 5sec, LCD write "close button", speaker says "please close button", and it goes to A1 again.

And of course, A5 A5a and A5b would be same, with the close action.

From the hardware perspective, everything is working now. but not from the software then.

Any help ...

there are too many error first is this one

you have already called the ledloop function and that will do its work

the second mistake

this will always return true (means it will always execute the code which is in while function) also it is a endless loop
and many more

I took back some of the code on the top, and corrected some mistakes:

int var1 = 0;
const unsigned long Count2K = 1000;
const unsigned long Count200 = 50;
unsigned long pastMotorTicks = millis();
unsigned long pastLEDTicks = millis();
int motorState = 0;
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
//declare the speaker output
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;

//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3

//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define LED 41

// PushbuttonOpen
const int buttonPinOpen = 14;
// PushbuttonClose
const int buttonPinClose = 15;
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;

// Declare constant for actuator A
const int ENA_PIN = 51; // the Arduino pin connected to the ENA pin L298N
const int IN1_PIN = 49; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 50; // the Arduino pin connected to the IN2 pin L298N
// Declare constant for actuator B
const int ENB_PIN = 53; // the Arduino pin connected to the ENB pin L298N
const int IN3_PIN = 52; // the Arduino pin connected to the IN3 pin L298N
const int IN4_PIN = 48; // the Arduino pin connected to the IN4 pin L298N

void setup() {
  Serial.begin(9600);
    //introduce code for speakers
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    while(true);
  }
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  myDFPlayer.volume(10);  //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  //password
  input_password.reserve(32); // maximum input characters is 33, change if needed
  //Set the pin for the button
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Welcome");
  // Initialize motorA
  pinMode(ENA_PIN, OUTPUT);
  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);
  digitalWrite(ENA_PIN, HIGH);
  // Initialize motorB
  pinMode(ENB_PIN, OUTPUT);
  pinMode(IN3_PIN, OUTPUT);
  pinMode(IN4_PIN, OUTPUT);
  digitalWrite(ENB_PIN, HIGH);
  //Initiate programm
  StartStatus();
}

void loop()
{
  Serial.println(var1);
  char key = keypad.getKey();
  if (key)
  {
    if (digitalRead(A14) == LOW && digitalRead(A15) == LOW)
    {
      Erreur();
      lcd.clear();
      lcd.print("Select button");
      myDFPlayer.playMp3Folder(1); //play that a button must be selected
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A14) == HIGH && digitalRead(A15) == HIGH)
    {
      Erreur();
      lcd.clear();
      lcd.print("Too many button");
      myDFPlayer.playMp3Folder(1); //play that too many button are pushed
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A15) == HIGH && digitalRead(A14) == LOW) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          int var1 = 0;
          Correct();    
          while (var1 < 1) //while loop to have red lights
          {
            lcd.clear();
            lcd.print("Locking door");
            myDFPlayer.playMp3Folder(1); //Play that the door is locking
            ClosePiston();
            ledloop();
          }
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
    else if (digitalRead(A15) == LOW && digitalRead(A14) == HIGH) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          int var1 = 0;
          Correct();
          //while loop to have red lights
          while (var1 < 1) 
          {
            //Print and say the message
            lcd.clear();
            lcd.print("Unlocking door");
            myDFPlayer.playMp3Folder(1); //Play that the door is unlocking
            OpenPiston();
            ledloop();
          };
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }
}

void ClosePiston()  // Closing the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, LOW);
      digitalWrite(IN2_PIN, HIGH);
      digitalWrite(IN3_PIN, LOW);
      digitalWrite(IN4_PIN, HIGH);
      pastMotorTicks = millis();
      motorState = 1;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All closed");
        var1++;
        //pinMode(LED_4, OUTPUT);
        //digitalWrite(LED_4, HIGH);
        //delay(1000);
        //StartStatus();
        motorState = 0;
      }
  }
}

void OpenPiston()  // Opening the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, HIGH);
      digitalWrite(IN2_PIN, LOW);
      digitalWrite(IN3_PIN, HIGH);
      digitalWrite(IN4_PIN, LOW);
      pastMotorTicks = millis();
      motorState = 1;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All opened");
        var1++;
        //pinMode(LED_4, OUTPUT);
        //digitalWrite(LED_4, HIGH);
        //delay(1000);
        //StartStatus();
        motorState = 0;
      }
  }
}

void ledloop()   //Turning red lights
{
  switch ( ledState )
  {
    case 0:
      if ( (millis() - pastLEDTicks) >= Count200 ) {
        //turn on LED L1
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, INPUT);     //row 2
        digitalWrite(LED_3, LOW);
        pinMode(LED_2, OUTPUT);      //row 3
        digitalWrite(LED_2, HIGH);
        pastLEDTicks = millis();
        ledState = 1;
      }
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        pinMode(LED_2, INPUT);    //row 1
        digitalWrite(LED_2, LOW);
        pinMode(LED_1, OUTPUT);     //row 2
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
    
  }
}

void StartStatus()  //This should start the programm
{
  //Turn off the motor PIN
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  digitalWrite(IN3_PIN, LOW);
  digitalWrite(IN4_PIN, LOW);
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the green
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, LOW);
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // Print a message to the LCD.
  lcd.clear();
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  myDFPlayer.playMp3Folder(1); //Play sound
}

void Erreur()  //in case of error
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //double light on the blue
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
}

void Correct()  //in case of correct code
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, LOW);
  //double light on the green
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
}

Now, working better, but the red light is not stopping

It gets stuck on "Locking door" for example (closing the actuator and with red lights turning, fine), like if it could not get out of to the "case 1" ... i don't get it

With the following, I end the red, but they start again after .. I don't get where it gets again the code

int var1 = 0;
const unsigned long Count2K = 8000;
const unsigned long Count200 = 50;
unsigned long pastMotorTicks = millis();
unsigned long pastLEDTicks = millis();
int motorState = 0;
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
//declare the speaker output
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;

//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3

//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define LED 41

// PushbuttonOpen
const int buttonPinOpen = 14;
// PushbuttonClose
const int buttonPinClose = 15;
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;

// Declare constant for actuator A
const int ENA_PIN = 51; // the Arduino pin connected to the ENA pin L298N
const int IN1_PIN = 49; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 50; // the Arduino pin connected to the IN2 pin L298N
// Declare constant for actuator B
const int ENB_PIN = 53; // the Arduino pin connected to the ENB pin L298N
const int IN3_PIN = 52; // the Arduino pin connected to the IN3 pin L298N
const int IN4_PIN = 48; // the Arduino pin connected to the IN4 pin L298N

void setup() {
  Serial.begin(9600);
    //introduce code for speakers
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    while(true);
  }
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  myDFPlayer.volume(10);  //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  //password
  input_password.reserve(32); // maximum input characters is 33, change if needed
  //Set the pin for the button
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Welcome");
  // Initialize motorA
  pinMode(ENA_PIN, OUTPUT);
  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);
  digitalWrite(ENA_PIN, HIGH);
  // Initialize motorB
  pinMode(ENB_PIN, OUTPUT);
  pinMode(IN3_PIN, OUTPUT);
  pinMode(IN4_PIN, OUTPUT);
  digitalWrite(ENB_PIN, HIGH);
  //Initiate programm
  StartStatus();
}

void loop()
{
  Serial.println(var1);
  char key = keypad.getKey();
  if (key)
  {
    if (digitalRead(A14) == LOW && digitalRead(A15) == LOW)
    {
      Erreur();
      lcd.clear();
      lcd.print("Select button");
      myDFPlayer.playMp3Folder(1); //play that a button must be selected
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A14) == HIGH && digitalRead(A15) == HIGH)
    {
      Erreur();
      lcd.clear();
      lcd.print("Too many button");
      myDFPlayer.playMp3Folder(1); //play that too many button are pushed
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A15) == HIGH && digitalRead(A14) == LOW) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          int var1 = 0;
          Correct();
          lcd.clear();
          lcd.print("Locking door");
          myDFPlayer.playMp3Folder(1); //Play that the door is locking    
          while (var1 < 1) //while loop to have red lights
          {
            ClosePiston();
            ledloop();
          }
          StartStatus();
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
    else if (digitalRead(A15) == LOW && digitalRead(A14) == HIGH) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          int var1 = 0;
          Correct();
          //Print and say the message
          lcd.clear();
          lcd.print("Unlocking door");
          myDFPlayer.playMp3Folder(1); //Play that the door is unlocking
          while (var1 < 1) //while loop to have red lights
          {
            OpenPiston();
            ledloop();
          };
          StartStatus();
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }
}

void ClosePiston()  // Closing the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, LOW);
      digitalWrite(IN2_PIN, HIGH);
      digitalWrite(IN3_PIN, LOW);
      digitalWrite(IN4_PIN, HIGH);
      pastMotorTicks = millis();
      motorState = 1;
      break;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All closed");
        var1++;
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(1000);
        StartStatus();
        motorState = 0;
        break;
      }
  }
}

void OpenPiston()  // Opening the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, HIGH);
      digitalWrite(IN2_PIN, LOW);
      digitalWrite(IN3_PIN, HIGH);
      digitalWrite(IN4_PIN, LOW);
      pastMotorTicks = millis();
      motorState = 1;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All opened");
        var1++;
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(1000);
        StartStatus();
        motorState = 0;
      }
  }
}

void ledloop()   //Turning red lights
{
  switch ( ledState )
  {
    case 0:
      if ( (millis() - pastLEDTicks) >= Count200 ) {
        //turn on LED L1
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, INPUT);     //row 2
        digitalWrite(LED_3, LOW);
        pinMode(LED_2, OUTPUT);      //row 3
        digitalWrite(LED_2, HIGH);
        pastLEDTicks = millis();
        ledState = 1;
      }
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        pinMode(LED_2, INPUT);    //row 1
        digitalWrite(LED_2, LOW);
        pinMode(LED_1, OUTPUT);     //row 2
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
  }
}

void StartStatus()  //This should start the programm
{
  //Turn off the motor PIN
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  digitalWrite(IN3_PIN, LOW);
  digitalWrite(IN4_PIN, LOW);
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the green
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, LOW);
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // Print a message to the LCD.
  lcd.clear();
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  myDFPlayer.playMp3Folder(1); //Play sound
}

void Erreur()  //in case of error
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //double light on the blue
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
}

void Correct()  //in case of correct code
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, LOW);
  //double light on the green
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
}

https://1drv.ms/v/s!AmQCAddskXi4hJ4FCkcpYDPludYHHw?e=hUPVI7
Here, the video showing that it is not working properly. After starting fine, and completing, it starts again the red loop

nailed part of the bug with the code: (was the var1 that was declared in the wrong place)

int var1 = 0;
const unsigned long Count2K = 8000;
const unsigned long Count200 = 50;
unsigned long pastMotorTicks = millis();
unsigned long pastLEDTicks = millis();
int motorState = 0;
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
//declare the speaker output
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;

//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3

//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define LED 41

// PushbuttonOpen
const int buttonPinOpen = 14;
// PushbuttonClose
const int buttonPinClose = 15;
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;

// Declare constant for actuator A
const int ENA_PIN = 51; // the Arduino pin connected to the ENA pin L298N
const int IN1_PIN = 49; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 50; // the Arduino pin connected to the IN2 pin L298N
// Declare constant for actuator B
const int ENB_PIN = 53; // the Arduino pin connected to the ENB pin L298N
const int IN3_PIN = 52; // the Arduino pin connected to the IN3 pin L298N
const int IN4_PIN = 48; // the Arduino pin connected to the IN4 pin L298N

void setup() {
  Serial.begin(9600);
    //introduce code for speakers
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    while(true);
  }
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  myDFPlayer.volume(10);  //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  //password
  input_password.reserve(32); // maximum input characters is 33, change if needed
  //Set the pin for the button
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Welcome");
  // Initialize motorA
  pinMode(ENA_PIN, OUTPUT);
  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);
  digitalWrite(ENA_PIN, HIGH);
  // Initialize motorB
  pinMode(ENB_PIN, OUTPUT);
  pinMode(IN3_PIN, OUTPUT);
  pinMode(IN4_PIN, OUTPUT);
  digitalWrite(ENB_PIN, HIGH);
  //Initiate programm
  StartStatus();
}

void loop()
{
  //int var1 = 0;
  char key = keypad.getKey();
  if (key)
  {
    if (digitalRead(A14) == LOW && digitalRead(A15) == LOW)
    {
      Erreur();
      lcd.clear();
      lcd.print("Select button");
      myDFPlayer.playMp3Folder(1); //play that a button must be selected
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A14) == HIGH && digitalRead(A15) == HIGH)
    {
      Erreur();
      lcd.clear();
      lcd.print("Too many button");
      myDFPlayer.playMp3Folder(1); //play that too many button are pushed
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A15) == HIGH && digitalRead(A14) == LOW) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          Correct();
          lcd.clear();
          lcd.print("Locking door");
          myDFPlayer.playMp3Folder(1); //Play that the door is locking    
          while (var1 < 1) //while loop to have red lights
          {
            ClosePiston();
            ledloop();
          }
          input_password = "";
          StartStatus();
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
    else if (digitalRead(A15) == LOW && digitalRead(A14) == HIGH) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          Correct();
          //Print and say the message
          lcd.clear();
          lcd.print("Unlocking door");
          myDFPlayer.playMp3Folder(1); //Play that the door is unlocking
          while (var1 < 1) //while loop to have red lights
          {
            OpenPiston();
            ledloop();
          }
          input_password = "";
          StartStatus();
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }
}

void ClosePiston()  // Closing the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, LOW);
      digitalWrite(IN2_PIN, HIGH);
      digitalWrite(IN3_PIN, LOW);
      digitalWrite(IN4_PIN, HIGH);
      pastMotorTicks = millis();
      motorState = 1;
      break;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All closed");
        var1++;
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(1000);
        motorState = 0;
        break;
      }
  }
}

void OpenPiston()  // Opening the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, HIGH);
      digitalWrite(IN2_PIN, LOW);
      digitalWrite(IN3_PIN, HIGH);
      digitalWrite(IN4_PIN, LOW);
      pastMotorTicks = millis();
      motorState = 1;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All opened");
        var1++;
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(1000);
        motorState = 0;
        break;
      }
  }
}

void ledloop()   //Turning red lights
{
  switch ( ledState )
  {
    case 0:
      if ( (millis() - pastLEDTicks) >= Count200 ) {
        //turn on LED L1
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, INPUT);     //row 2
        digitalWrite(LED_3, LOW);
        pinMode(LED_2, OUTPUT);      //row 3
        digitalWrite(LED_2, HIGH);
        pastLEDTicks = millis();
        ledState = 1;
      }
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        pinMode(LED_2, INPUT);    //row 1
        digitalWrite(LED_2, LOW);
        pinMode(LED_1, OUTPUT);     //row 2
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
  }
}

void StartStatus()  //This should start the programm
{
  //Turn off the motor PIN
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  digitalWrite(IN3_PIN, LOW);
  digitalWrite(IN4_PIN, LOW);
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the green
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, LOW);
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // Print a message to the LCD.
  lcd.clear();
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  myDFPlayer.playMp3Folder(1); //Play sound
}

void Erreur()  //in case of error
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //double light on the blue
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
}

void Correct()  //in case of correct code
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, LOW);
  //double light on the green
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
}

It is now stopping correctly, as wished.
THe next (and last?) problem, is that now, after opening, or closing, I can't do the inverse action. There again, it seems that the problem is the var1 that is not anymore at 0, and if I do put it somewhere in the code, it loops again the red ...

FINAL working solution:

int var1 = 0;
const unsigned long Count2K = 8000;
const unsigned long Count200 = 50;
unsigned long pastMotorTicks = millis();
unsigned long pastLEDTicks = millis();
int motorState = 0;
int ledState = 0;
// include the library keypad & LiquidCrystal:
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
//declare the speaker output
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//Define constantn for the keypad
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
//Matrix for the Keypad
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
//DEFINE pins for the keypad
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
//DEFINE code for the keypad
const String password = "1234"; // password
String input_password;

//Define matrix for colors
const int LED_1 = 21;     //LED row 1
const int LED_2 = 20;     //LED row 2
const int LED_3 = 19;     //LED row 3

//Declare PIN for the green LEDS
const int LED_4 = 40;
//Declare PIN for the blue LEDS
const int LED_5 = 41;
// Declare pins for the LCD
const int rs = 30, en = 31, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define LED 41

// PushbuttonOpen
const int buttonPinOpen = 14;
// PushbuttonClose
const int buttonPinClose = 15;
// variables will change:
int buttonmotorStateOpen = 0;
int buttonmotorStateClose = 0;

// Declare constant for actuator A
const int ENA_PIN = 51; // the Arduino pin connected to the ENA pin L298N
const int IN1_PIN = 49; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 50; // the Arduino pin connected to the IN2 pin L298N
// Declare constant for actuator B
const int ENB_PIN = 53; // the Arduino pin connected to the ENB pin L298N
const int IN3_PIN = 52; // the Arduino pin connected to the IN3 pin L298N
const int IN4_PIN = 48; // the Arduino pin connected to the IN4 pin L298N

void setup() {
  Serial.begin(9600);
    //introduce code for speakers
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    while(true);
  }
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  myDFPlayer.volume(10);  //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  //password
  input_password.reserve(32); // maximum input characters is 33, change if needed
  //Set the pin for the button
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Welcome");
  // Initialize motorA
  pinMode(ENA_PIN, OUTPUT);
  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);
  digitalWrite(ENA_PIN, HIGH);
  // Initialize motorB
  pinMode(ENB_PIN, OUTPUT);
  pinMode(IN3_PIN, OUTPUT);
  pinMode(IN4_PIN, OUTPUT);
  digitalWrite(ENB_PIN, HIGH);
  //Initiate programm
  StartStatus();
}

void loop()
{
  //int var1 = 0;
  char key = keypad.getKey();
  if (key)
  {
    if (digitalRead(A14) == LOW && digitalRead(A15) == LOW)
    {
      Erreur();
      lcd.clear();
      lcd.print("Select button");
      myDFPlayer.playMp3Folder(1); //play that a button must be selected
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A14) == HIGH && digitalRead(A15) == HIGH)
    {
      Erreur();
      lcd.clear();
      lcd.print("Too many button");
      myDFPlayer.playMp3Folder(1); //play that too many button are pushed
      input_password = "";
      delay(2000);
      StartStatus();
    }
    else if (digitalRead(A15) == HIGH && digitalRead(A14) == LOW) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          Correct();
          lcd.clear();
          lcd.print("Locking door");
          myDFPlayer.playMp3Folder(1); //Play that the door is locking    
          while (var1 < 1) //while loop to have red lights
          {
            ClosePiston();
            ledloop();
          }
          var1--;
          input_password = "";
          StartStatus();
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
    else if (digitalRead(A15) == LOW && digitalRead(A14) == HIGH) 
    {
      if(key == '*') 
      {
        input_password = ""; // clear input password
      } 
      else if (key == '#')
      {
        if (password == input_password)
        {
          lcd.clear();
          lcd.print("CORRECT");
          Correct();
          //Print and say the message
          lcd.clear();
          lcd.print("Unlocking door");
          myDFPlayer.playMp3Folder(1); //Play that the door is unlocking
          while (var1 < 1) //while loop to have red lights
          {
            OpenPiston();
            ledloop();
          }
          var1--;
          input_password = "";
          StartStatus();
        }
        else
        {
          lcd.clear();
          lcd.print("INCORRECT");
        }
        input_password = ""; // clear input password
      }
      else
      {
        input_password += key; // append new character to input password string
        lcd.clear();
        lcd.print(input_password);
      }
    }
  }
}

void ClosePiston()  // Closing the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, LOW);
      digitalWrite(IN2_PIN, HIGH);
      digitalWrite(IN3_PIN, LOW);
      digitalWrite(IN4_PIN, HIGH);
      pastMotorTicks = millis();
      motorState = 1;
      break;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All closed");
        var1++;
        //light off the red
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);      //row 3
        digitalWrite(LED_3, LOW);
        //light on the green
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(1000);
        motorState = 0;
        break;
      }
  }
}

void OpenPiston()  // Opening the piston
{
  switch ( motorState )
  {
    case 0 :
      // Turn on actuator A and B
      digitalWrite(IN1_PIN, HIGH);
      digitalWrite(IN2_PIN, LOW);
      digitalWrite(IN3_PIN, HIGH);
      digitalWrite(IN4_PIN, LOW);
      pastMotorTicks = millis();
      motorState = 1;
    case 1 :
      if ( (millis() - pastMotorTicks ) >= Count2K )
      {
        lcd.clear();
        lcd.print("All opened");
        var1++;
        //light off the red
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);      //row 3
        digitalWrite(LED_3, LOW);
        //light on the green
        pinMode(LED_4, OUTPUT);
        digitalWrite(LED_4, HIGH);
        delay(1000);
        motorState = 0;
        break;
      }
  }
}

void ledloop()   //Turning red lights
{
  switch ( ledState )
  {
    case 0:
      if ( (millis() - pastLEDTicks) >= Count200 ) {
        //turn on LED L1
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, INPUT);     //row 2
        digitalWrite(LED_3, LOW);
        pinMode(LED_2, OUTPUT);      //row 3
        digitalWrite(LED_2, HIGH);
        pastLEDTicks = millis();
        ledState = 1;
      }
      break;
    case 1:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L2
        pinMode(LED_1, OUTPUT);     //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, INPUT);      //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 2;
      }
      break;
    case 2:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L3
        pinMode(LED_1, INPUT);      //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);     //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);     //row 3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 3;
      }
      break;
    case 3:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L4
        pinMode(LED_1, INPUT);     //row 1
        digitalWrite(LED_1, LOW);
        pinMode(LED_2, OUTPUT);    //row 2
        digitalWrite(LED_2, HIGH);
        pinMode(LED_3, OUTPUT);    //row 3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 4;
      }
      break;
    case 4:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L5
        pinMode(LED_2, INPUT);    //row 1
        digitalWrite(LED_2, LOW);
        pinMode(LED_1, OUTPUT);     //row 2
        digitalWrite(LED_1, LOW);
        pinMode(LED_3, OUTPUT);    //row3
        digitalWrite(LED_3, HIGH);
        pastLEDTicks = millis();
        ledState = 5;
      }
      break;
    case 5:
      if ( (millis() - pastLEDTicks) >= Count200 )
      {
        //turn on LED L6
        pinMode(LED_1, OUTPUT);    //row 1
        digitalWrite(LED_1, HIGH);
        pinMode(LED_2, INPUT);    //row 2
        digitalWrite(LED_2, LOW);
        pinMode(LED_3, OUTPUT);   //row3
        digitalWrite(LED_3, LOW);
        pastLEDTicks = millis();
        ledState = 0;
      }
      break;
    default:
      ledState = 0;
      break;
  }
}

void StartStatus()  //This should start the programm
{
  //Turn off the motor PIN
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  digitalWrite(IN3_PIN, LOW);
  digitalWrite(IN4_PIN, LOW);
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, INPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the green
  pinMode(LED_4, OUTPUT);
  digitalWrite(LED_4, LOW);
  //light on the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, HIGH);
  // Print a message to the LCD.
  lcd.clear();
  lcd.print("Welcome");
  lcd.setCursor(0, 1);
  lcd.print("Select button");
  lcd.setCursor(0, 0);
  myDFPlayer.playMp3Folder(1); //Play sound
}

void Erreur()  //in case of error
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, OUTPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //double light on the blue
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
  digitalWrite(LED_5, HIGH);
  delay(200);
  digitalWrite(LED_5, LOW);
  delay(200);
}

void Correct()  //in case of correct code
{
  //light off the red
  pinMode(LED_1, OUTPUT);     //row 1
  digitalWrite(LED_1, LOW);
  pinMode(LED_2, OUTPUT);     //row 2
  digitalWrite(LED_2, LOW);
  pinMode(LED_3, OUTPUT);      //row 3
  digitalWrite(LED_3, LOW);
  //light off the blue
  pinMode(LED_5, OUTPUT);
  digitalWrite(LED_5, LOW);
  //double light on the green
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
  digitalWrite(LED_4, HIGH);
  delay(200);
  digitalWrite(LED_4, LOW);
  delay(200);
}