#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //three columns
String password = "1234";
String inputPass;
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_column[COLUMN_NUM] = {22,24, 26, 28}; //connect to the row pinouts of the keypad
byte pin_rows[ROW_NUM] = {30, 32,34,36}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
void setup(){
Serial.begin(9600);
pinMode(25, OUTPUT);
digitalWrite(25, HIGH);
}
void loop(){
char key = keypad.getKey();
if (key){
inputPass = inputPass + key;
if(inputPass.length()==4){
if(inputPass == password){
Serial.println("Welcome!");
digitalWrite(25, LOW);
delay(3000);
digitalWrite(25,HIGH);
}
else{
Serial.println("Incorrect!");
delay(3000);
}
inputPass = "";
}
Serial.println(inputPass);
}
}