In this project I will show you how I build a electronic door lock. The project will use a solenoid that will be activated when an correct pin code is entered. All you need to do is connect all the parts together like shown in the schematic. After I drew the schematic I realised that it is missing a button to allow you to leave the room so connect the button to pin 9.
Once your parts are all connected to together you will need to upload the code. to do this just plug in the Arduino into a pc and upload the code that I have provided.
After your code is uploaded make sure every thing is working then you are ready to install it. Mount the solenoid to the edge of the door with some wood screws and I hot glued the wire for it to the back of the door to the hinge. Then I drilled a hole though the wall from the inside out and feed the wires for the keypad and the LCD though it them mount in a small enclosure and screw to the wall. Also place your button in a suitable place inside of the room so it is easy to get out.
#include <Keypad.h>
#include <LiquidCrystal.h>
#define Button 9
#define GreenLED 11
#define RedLED 12
#define Lock 13
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // set the pins for the LCD
char* password ="8569"; //Set your password
int pin = 0;
byte rowPins [rows] = {2, 3, 4, 5}; //Set the keypad pins
byte colPins [cols] = {6, 7, 8,}; //Set the keypad pins
byte rows = 4; //number of rows in the keypad
byte cols = 3; //number of columbs in the keypad
char keyMap [rows] [cols] = { //Maps the keypad
{'1', '2', '3',}, //sets the button positions on the keypad
{'4', '5', '6',}, //sets the buttons positions on the keypad
{'7', '8', '9',}, //sets the buttons positions on the keypad
{'*', '0', '#',} //sets the buttons positions on the keypad
};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
void setup(){
lcd.begin(16, 2);
pinMode(Button, INPUT); //set the pin as an input
pinMode(greenLED, OUTPUT); //set the pin as an output
pinMode(redLED, OUTPUT); //set the pin as an output
pinMode(Lock, OUTPUT); //set the pin as an output
setLocked (true); //state of the password
}
void loop(){
char whichKey = myKeypad.getKey();
lcd.setCursor(0, 0);
lcd.print(" Enter Pin");
if(whichKey == password [pin]){
pin ++;
}
if(pin == 4){
setLocked (false);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pincode correct");
delay(5000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked){
if(locked){
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, HIGH);
digitalWrite(Lock, LOW);
}
else{
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
digitalWrite(Lock, HIGH);
}
else{
if (digitalRead(Button) == HIGH){
digitalWrite(Lock, HIGH):
delay(5000);
}
}
}
Please be aware that the solenoid I used is normally locked meaning that when power is lost the door will be locked. I realised this the hard way when I shut the door while the unit wasn't powered and I was locked out of my room so I had to climb though the window to open the door again. So make sure that there is some kind of fail safe so that when power is lost the door will be able to be unlocked
AcknowledgementI thank PCBWay & LCSC Electronics for the partnership.
PCBWay Is a cheap reliable service where you can get your PCBs manufactured. All the PCBs are high quality and the engineers are very helpful and will resolve any problems you may have quickly. Sign up today and get a $5 welcome bonus. Check Out PCBWay Hackster page.
LCSC Electronics Is China's leading Electronic Components Distributor. LCSC sells a wide variety of high quality electronic components at low prices. With over 150, 000 parts in stock they should have the components you need for your next project. Sign up today and get $8 off on your first order.
WebsiteCheck out more of my other projects on my website.
Support meIf you like my projects and would like to support me so I continue making projects and sharing them with the community visit my Patreon
Comments
Please log in or sign up to comment.