creating a check password

hei guys im trying to create a check with a password and everytime at the end of the project it repeats the serial print () thats the coding plz check if there are some problems on it and thank u for ur help…
#include <Keypad.h>
int count =0;
char a[5]={‘1’,‘2’,‘3’,‘4’,‘B’};
char b[5];

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘c’},
{’*’,‘0’,’#’,‘D’}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A5,A4, A3, A2}; //connect to the column pinouts of the keypad

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

void setup(){
Serial.begin(9600);

Serial.println("plz enter the password and press B: ");

}

void loop(){

char c =keypad.getKey();
if (c !=0){
Serial.println(c);
b[count]={c} ;
count++;
}

if (count ==6){

for (int j=0;j<6;j++){
if (b[j]==a[j] && b[4]==‘B’){
Serial.println("welcome Home ");

}
else {
Serial.println(“wrong Pass”);

}
}

}
}

Maybe revise the checks a bit (not tested):

void loop()
{ 
    bool
        bPass;
        
    char c = keypad.getKey();
    if( c != 0 )
    {
        Serial.println(c);
        b[count] = c ;
        count++;
        
    }//if

    if( count == 5 )    //6 or 5?
    {
        bPass = false;
        if( b[4] == 'B' )
        {
            bPass = true;
            for( int j=0; j<5; j++ )   //6 or 5?
                if ( b[j] != a[j] )
                    bPass = false;
                    
        }//if

        if( bPass )
            Serial.println("welcome Home ");
        else 
            Serial.println("wrong Pass");
   
    }//if
    
}//loop

36mehdi:
hei guys im trying to create a check with a password and everytime at the end of the project it repeats the serial print () thats the coding plz check if there are some problems on it and thank u for ur help..

1. Let us correct/adjust your above quote first to extract some meaning out-of-it and then ask you questions.

Hey guys! I am trying to create a check with a password. The password is this: 1234 which I will enter from a Keypad. The password will be accepted only when B is entered from the Keypad and the message "Welcome Home" will appear on the Serial Monitor. But, the program is not working in my UNO setup. I have given below my codes without code tags (</>); please, help me. Thanks...!

2. What are your inputs from the Keypad/Serial Monitor to the program; what output do you expect to see on the Serial Monitor?

The answers are there in Step-1.

3. If you would use code tags (</>) with literate formatting (opening ({) and closing brace (}) should be aligned vertically), your codes would appear as shown below which is good to read and easier to debug (find software faults).

#include <Keypad.h>
int count = 0;
char a[5] = {'1', '2', '3', '4', 'B'};
char b[5];

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'c'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A5, A4, A3, A2}; //connect to the column pinouts of the keypad

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

void setup()
{
  Serial.begin(9600);
  Serial.println("plz enter   the password  and press B: ");
}

void loop()
{
  char c = keypad.getKey();
  if (c != 0)
  {
    Serial.println(c);
    b[count] = {c} ;
    count++;
  }
  if (count == 6)
  {
    for (int j = 0; j < 6; j++)
    {
      if (b[j] == a[j] && b[4] == 'B')
      {
        Serial.println("welcome Home ");
      }
      else
      {
        Serial.println("wrong Pass");
      }
    }
  }
}

4. Please, go through the slight changes I have done in your program; upload the program and check that the program outputs the expected result.

#include <Keypad.h>
int count = 0;
char a[5] = {'1', '2', '3', '4', 'B'};
char b[5] = "";
bool flag1 = true;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'c'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //R1R2R3R4connect to the row pinouts of the keypad
byte colPins[COLS] = {A5, A4, A3, A2}; //C1C2C3C4connect to the column pinouts of the keypad

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

void setup()
{
  Serial.begin(9600);
  Serial.println("plz enter   the password  and press B: ");
}

void loop()
{
  char c = mykeypad.getKey();
  if (c != 0)
  {
    Serial.println(c);
    b[count] = c;//{c} ;
    count++;
    // }
    if (count == 5)
    {
      // Serial.println(b);
      // Serial.println(a);
      for (int i = 0; i < 5; i++)
      {
        if (a[i] == b[i])
        {
          ;
        }
        else
        {
          flag1 = false;
        }
      }
      //---------------------------
      if (flag1 == true)
      {
        Serial.println("welcome Home ");
        count = 0;
      }
      else
      {
        Serial.println("wrong Pass");
        count = 0;
      }
      //---------------------------
    }
  }
}

sm57.png

sm57.png