A Password Lock Using Keypad and Servo Which Opens the Lock When the Correct Password Is Entered and Beeps the Buzzer When Wrong Password Is Entered.
by ganesh_20203 in Circuits > Arduino
909 Views, 0 Favorites, 0 Comments
A Password Lock Using Keypad and Servo Which Opens the Lock When the Correct Password Is Entered and Beeps the Buzzer When Wrong Password Is Entered.
Assume that the lock is a servo motor . The servo motor shaft rotates 40 degrees if the entered password is accurate . IF incorrect password is entered the servo will rotate 180 degrees and the buzzer will tone up.
Supplies
arduino uno board -1
piezo buzzer -1
servo motor -1
keypad (4x4) -1
jumper wires
Circuit Diagram Using TinkerCAD
I have attached above a picture of the complete circuit which i designed using TinkerCAD. The image is self- explanatory.
Below Is the Code for This Project
#include <Servo.h>
#include <Keypad.h>
Servo servo;
const byte ROWS = 4;
const byte COLS = 4;
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);
String password = "";
bool isLocked = true;
String unlock = "1234";
void setup()
{
pinMode(11,OUTPUT);
servo.write(0);
servo.attach(10);
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if(key != '*' && key != NO_KEY){
password += key;
Serial.println(password);
} else if(key == '*' && password.length() == 4){
checkPassword();
password = "";
} else if(key == '*' && password.length() < 4){
password = "";
} else if(key == '*' && password.length() > 4){
password = "";
}
}
void checkPassword(){
if(unlock == password){
isLocked = false;
servo.write(40);
delay(15);
}
else{
isLocked=true;
servo.write(180);
delay(15);
tone(11,200);
delay(2000);
noTone(11);
delay(2000);
}
}