//2020 Ali_Kilicoglu
#include <Servo.h>
Servo servoNesnesi;
#include <Keypad.h>
String pasword1="Your password";
String pasword2="";
int p=0;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
#define BUZZERPIN 11
servoNesnesi.attach(10);
pinMode(BUZZERPIN,OUTPUT);
servoNesnesi.write(100);//first lock drawer
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();// Read the key
// Print if key pressed
if (key){
Serial.print("Key print : ");
Serial.println(key);
digitalWrite(BUZZERPIN,HIGH);
delay(100);
digitalWrite(BUZZERPIN,LOW);
p = pasword2.length();
pasword2+= key;
Serial.println(pasword2);
}
if(pasword2 == pasword1){//if your pasword equal keypad pasword
servoNesnesi.write(20);//open the drawer
pasword2="";
}
else if(pasword2 !=pasword1 and p>= 6){
digitalWrite(BUZZERPIN,HIGH);
pasword2="";
}
if(key == '#'){//for lock the drawer
servoNesnesi.write(100);
pasword2="";
}
}
Comments