Jugaadu's father is going on a Business trip. He is carrying some important and confidential documents with him. He wants to keep these documents safe. But his luggage doesn't have a smart locking system. He wants Jugaadu to make a smart locking box that can help him in keeping his documents safe?
include
#include
Servo myservo;
String password="1306";
String tempPassword="";
const byte ROWS = 4;
const byte COLS = 4;
char keyPressed;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9,8,7,6};
byte colPins[COLS] = {5,4,3,2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
myservo.attach(10);
}
void loop(){
keyPressed = keypad.getKey();
if(keyPressed != NO_KEY){
if(keyPressed =='#')
{
tempPassword="";
myservo.write(0);
}
else if(keyPressed=='*' )
{
if(tempPassword==password && tempPassword != ""){
myservo.write(180);
}else{
myservo.write(0);
}
}
else if(keyPressed =='0' || keyPressed=='1' || keyPressed=='2'||
keyPressed=='3'|| keyPressed=='4'|| keyPressed=='5'||
keyPressed=='6'|| keyPressed=='7'|| keyPressed=='8'|| keyPressed=='9')
{
tempPassword +=keyPressed;
}
Serial.println(keyPressed);
}
}