#include <Keypad.h>

#define PASSWORD "123456789"
#define GREEN_LED 12
#define RED_LED 11

const uint8_t ROWS = 3;
const uint8_t COLS = 3;

// digits
char keys[ROWS][COLS] = {
  { '1', '2', '3'},
  { '4', '5', '6'},
  { '7', '8', '9'}
};

// change the following pins
uint8_t colPins[COLS] = { 5, 4, 3}; // Pins connected to C1, C2, C3
uint8_t rowPins[ROWS] = { 8, 7, 6}; // Pins connected to R1, R2, R3

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String entered_number = "";
bool password_status;

void setup() {
  Serial.begin(9600);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);

  digitalWrite(RED_LED, HIGH);
}

void loop() {
  if (password_status == 0) {
    char key = keypad.getKey();
    if (key != NO_KEY) {
      entered_number += key;
    }
    if (entered_number.length() == 9) {
      if (entered_number == PASSWORD) {
        Serial.println("Password matched!");
        password_status = 1;
      }
      else {
        Serial.println("Password Mismatched! Try again...");
        for (int i = 0; i < 3; i++) {
          digitalWrite(RED_LED, LOW);
          delay(500);
          digitalWrite(RED_LED, HIGH);
          delay(500);
        }
        entered_number = "";
      }
    }
  } else {
    digitalWrite(RED_LED, LOW);
    digitalWrite(GREEN_LED, HIGH);
  }
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
1
2
3
4
5
6
7
8
9
led1:A
led1:C
led2:A
led2:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
btn4:1.l
btn4:2.l
btn4:1.r
btn4:2.r
btn5:1.l
btn5:2.l
btn5:1.r
btn5:2.r
btn6:1.l
btn6:2.l
btn6:1.r
btn6:2.r
btn7:1.l
btn7:2.l
btn7:1.r
btn7:2.r
btn8:1.l
btn8:2.l
btn8:1.r
btn8:2.r
btn9:1.l
btn9:2.l
btn9:1.r
btn9:2.r