Passcode using a keypad

What would I have to change in this program so that a passcode in the specific order such as 1234 will then display something in the serial monitor. Currently, I have it working so that one digit will display something on the serial monitor.
I am new to Arduino, so any help would be appreciated. :slight_smile:

4x4MatrixKeyboard.ino (917 Bytes)


Let me give you some hints. Please, follow them to bring necessary changes in your codes. Hope that you will get your expected result.

1. Digits (1 2 3 4) that you are entering (from the Keypad) are encoded into ASCII codes. For example: when 1 is pressed, the code 0x31 is prepared and similar codes are prepared when 2 3 4 are entered.

2. You need to save them in a character type array by the following declaration:

char myArray[5] = "";


3. Read the code of the Key and save into array and then show on the Serial Monitor and then increment the index pointer of the myArray. (The index pointer should have initial value of 0.)

myArray[i] = customKey;
Serial.print(customKey);     //not Serial.println(customKey);

4. If you have already entered 1 2 3 4, the value of i will be 4. Now, depending on the value of i make a decision if you will be receipting/saving any more digits or end here.

if(i == 4) //all 4-digits are received
   //make a comparison
   int x = strcmp(myArray, preSetString);   // declare in global area 'char preSetString[] = "1234";'
   if(x == 0x00)
       Serial.println("Hello");   //matched
       while(1);   //wait for ever
        i=0;        //start again from newline position