Introduction: Arduino Door Lock With Password

In this project I mede an door lock (or box lock) that opens when you enter your password and press "#". The servo turns back to the position it was in after some seconds.

Step 1: PARTS & TOOLS

For this project I used:

* Arduino uno ( http://store.arduino.cc/index.php?main_page=produc... )

* 4x4 matrix keypad, can also use 3x4( http://www.ebay.com/itm/4-x-4-Matrix-Array-16-Key-... )

* Arduino PCB shield ( http://www.ebay.com/itm/Prototype-PCB-for-Arduino-... )

* 2x 1k OHM resistors ( http://www.ebay.com/itm/50-Pcs-Carbon-Film-Resisto... )

* 3mm green and red LEDs ( http://www.ebay.com/itm/LOT-OF-20-50-100-3mm-Red-G... )

* Male pin header ( http://www.ebay.com/itm/3pcs-40Pin-2-54mm-Male-Hea... )

* Female pin header ( http://www.ebay.com/itm/New-4PCS-40Pin-Straight-Fe... )

* Servo ( http://www.ebay.com/itm/SG90-Mini-Gear-Micro-9g-Se... )

* Wires ( http://www.ebay.com/itm/50pcs-1007-24-color-PCB-So... )

The tools you are going to need:

* Soldering iron

* Soldering paste

* Soldering tin

* Plier

Step 2: Schematic

Follow the schematic.

Step 3: Solder the Connectors

Solder he connections for the Arduino, kaypad and servo. When you are soldering the connection for the keypad and the servo try not to have it in a place where the programing port on the Arduino UNO touches your soldered places, I did that once and I almost ended up destroying my Arduino because the 5v and the GND got connected together when they touched the programing port.

Step 4: Soldering

Solder the LEDs, resistors and the wires for them, than solder the rest of the wires, try to cut your wires so that they fit nice and smooth on the PCB like shown in the photos.

Step 5: The Door Lock

I mounted my servo on an aluminum plate with an simple lock. unfortunately I did not take any photos when making this but hopefully you will understand how to make it by the photo, its really easy.

Step 6: CODE

Download the code and import libraries. You need to download the 3 Arduino libraries if you don't have them.

* password.h

* keypad.h

* servo.h

THANKS FOR VIEWING!

Ifyou like this project than go check out my channel for more cool projects :)

If you have any questions or tips than post them in the comments.

Comments

author
riched made it! (author)2017-07-25

I made this the first time round and had no problem, but i wanted to use a smaller uno bored but now every time i try to upload the code i get this "\Documents\Arduino\TEST1\TEST1.ino:7:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]" and because of this the code isnt working right on the bored, pls can anyone help as im confused to what the issue is. thanks

author
Moody2000 made it! (author)2017-06-12

C:\Users\Mahmoud\Documents\Arduino\sketch_jun13a\sketch_jun13a.ino:8:38: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Password password = Password( "0000" );

Please help , this error appeared.

author
ama3801 made it! (author)2017-05-06

This instructable is very nice and perfect .

I made it .but there
is a problem in the program .

When you enter password keys and * key
the pass is accepted , but after that whenever you press

Just only * key
and no any other key the servo acts ,unless you press another key or
rest # key .

I solved the problem by inserting this line password.reset();

by this when password is accepted the program automatically resets it .


Serial.println("Accepted");


Serial.write(254);delay(10);

//Add code to run
if it works


myservo.write(150); //deg


password.reset();


digitalWrite(11, HIGH);//turn on

delay(5000);
//wait 5 seconds

digitalWrite(11,
LOW);// turn off

author
ama3801 made it! (author)2017-05-04

VERY NICE AND PERFECT

author
achrefab095 made it! (author)2017-02-01

this is my project

IMG_20170131_181731.jpg
author
Sai CharanR made it! (author)Sai CharanR2017-04-09

i am a begginer will u help me to do this

author
TomG184 made it! (author)2017-03-09

how i connect the pins for 3x4 numpad ?

author
FlavioF4 made it! (author)2017-02-07

Hello everyone, i'm new in arduino and on programming, and when i try to compile he show me some errors like on the image, can you all please hellpe me?

Capturar.PNG
author
ShahrulM made it! (author)2017-02-03

is this the full programming ???
and how the programming if i add a lcd or cctv ?
can you help me to program it ?

author
achrefab095 made it! (author)2017-02-01

hello , i made the same project , but i want to add buzzer which do a sonor signal when we enter a false password 3 times
could someone how can i do it
(am asking about the code )

author
abhineshrocks made it! (author)2015-11-01

a little doubt here. if i press 123456789 instead of just 159 the opens. i mean the code is such that as if you press any no. having 1,5 & 9 in sequence the door opens

author
ibenkos made it! (author)ibenkos2015-11-01

I did not know that, do you have any suggestions to how I can make the code better?
Thanks

author
dinotom made it! (author)dinotom2016-07-31

just test for code entry size, if more than 3 digits, disallow

author
Bayslayerking made it! (author)Bayslayerking2016-11-28

how would i put that into the code here is the code i have i had tried to do //code entry size, if more than 3 digits, disallow... but it dint nothing and had the same problem

#include <Keypad.h>

#include <Servo.h>

Servo servo_Motor;

char* password = "123";

int position = 0;

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] = { 8, 7, 6, 9 };

byte colPins[COLS] = { 5, 4, 3, 2 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int redPin = 12;

int greenPin = 13;

void setup()

{

pinMode(redPin, OUTPUT);

pinMode(greenPin, OUTPUT);

servo_Motor.attach(11);

setLocked(true);

}

void loop()

{

char key = keypad.getKey();

if (key == '*' || key == '#')

{

position = 0;

setLocked(true);

}

if (key == password[position])

{

position ++;

}

if (position == 3)

{

setLocked(false);

}

delay(100);

}

void setLocked(int locked)

{

if (locked)

{

digitalWrite(redPin, HIGH);

digitalWrite(greenPin, LOW);

servo_Motor.write(11);

}

else

{

digitalWrite(redPin, LOW);

digitalWrite(greenPin, HIGH);

servo_Motor.write(90);

}

}

author
achrefab095 made it! (author)achrefab0952017-02-01

hello , i made the same project , but i want to add buzzer which do a sonor signal when we enter a false password 3 times
could someone how can i do it
(am asking about the code )

author
achrefab095 made it! (author)achrefab0952017-02-01

hello , i made the same project , but i want to add buzzer which do a sonor signal when we enter a false password 3 times
could someone how can i do it
(am asking about the code )
which and how can i do it please

author
inventorinlearning made it! (author)inventorinlearning2016-12-19

can you make the schematic with fritzing? thanks. by the way great project.

author
achrefab095 made it! (author)2017-02-01

hello , i made the same project , but i want to add buzzer which do a sonor signal when we enter a false password 3 times
could someone how can i do it
(am asking about the code )

author
aimimimie made it! (author)2017-01-18

why i have error?

Capture.PNG
author
MichaelB1068 made it! (author)MichaelB10682017-01-24

You need to install Password.h & Keypad.h from the link in the script. :)

author
JbW4 made it! (author)2017-01-04

Hello and thank you very much for this topic. I've just made it and it work fine.

Only one thing seems to be bad : my servo makes some noise and becomes hot during the loop (but not during the 5 sec after be opened). I watch in the code but nothing seems to be wrong.

Any idea ?

Thanks a lot

author
Gerhard AndreasL made it! (author)Gerhard AndreasL2017-01-13

@JbW4

My servo is doing the exact same thing, have you solved this yet?

It seems that ibenkos doesn't attend to this comments anymore?

author
aj_98 made it! (author)2016-11-14

THANK YOU SO MUCH!

I was struggling with my project and you just saved me!

author
Shayan Das made it! (author)2015-08-05

Your project is awesome but can u connect it with a 16 x 2 lcd module and supply another instructables? Then it would be preciously helpful. Thank You.

author
ibenkos made it! (author)ibenkos2015-08-06

Thank you, I dont have enough pins on my arduino uno for that. Maybe it will work with an arduino mega, but i dont have one

author
KamranF1 made it! (author)KamranF12016-11-07

IT ALSO WORKS ON UNO JUST CHANGE PINS

author
Sigmaz_1 made it! (author)Sigmaz_12016-10-07

I2C LCD only uses 2 pins

author
porpoisepower69 made it! (author)2016-10-30

Hey, How do you make it so I can add a pushbutton that whenever i press it the servo opens? For the other side of the door

author
MegaN6 made it! (author)2015-08-21

i need to change the lock code numbers within the keypad without connecting to the pc help me by sending the code

author
ibenkos made it! (author)ibenkos2015-08-22

That would have been an awesome uppgrade, but I dont know how to make that code :/

author
Sigmaz_1 made it! (author)Sigmaz_12016-10-07

you can store code changes in the EEPROM.

author
Shayan Das made it! (author)2015-09-01

Thanks for the code and the project. Can you help me with an issue from which i am suffering from your code :-
The code supplied by you stores the password after entering it that is, after entering the correct password and pressing * the lock open but the password gets stored in the system and if anybody will unknowingly press the * button instead of # button then the lock automatically opens.
Can you modify the code to auto refresh the password after opening the lock? It is because i have installed this lock at my house door and it will be a funny thing if after opening with the correct password the gate opens all the time by just a * button. I am very pleased with your project and i request the modified version of this code as i am unable to create arduino code because i am new to arduino.

Thanking you
Shayan Das
sanu.bullet@gmail.com

author
ibenkos made it! (author)ibenkos2015-09-01

Hello, I haven't noticed that there is a bug by pressing *. I will look into the code again and see what I can do :)

author
Sigmaz_1 made it! (author)Sigmaz_12016-10-07

maybe....

void checkPassword() {

if (password.evaluate()) { //if password is right open

Serial.println("Accepted");

Unlock();

} else {

Serial.println("Denied"); //if passwords wrong keep locked

LockIt();

}

LockIt()

{

Serial.write(254); delay(10);

//add code to run if it did not work

myservo.write(0);

digitalWrite(12, HIGH); //turn on

delay(500); //wait 5 seconds

digitalWrite(12, LOW);//turn off

}

Unlock()

{

Serial.println("Accepted");

Serial.write(254); delay(10);

//Add code to run if it works

myservo.write(150); //deg

digitalWrite(11, HIGH);//turn on

delay(5000); //wait 5 seconds

digitalWrite(11, LOW);// turn off

delay (15000); //wait 15 seconds for door to open and then close

password.reset();

LockIt();

}

author
Shayan Das made it! (author)Shayan Das2015-09-01

Its not a bug actually. After entering password we need to press the * button as it acts as the enter key.

author
RajatS12 made it! (author)RajatS122015-09-29

Hi, I have also noticed this problem, But you could simply fix this by pressing the # key on the keypad or the small red reset button on the Arduino, depending on which one suits you best. Both of these buttons clear the previously entered codes and the star key doesn't work on its own anymore.

author
ben.dobbs.3 made it! (author)2016-02-06

Once you enter the password, you need to reset it or else someone can just press the enter key to unlock.

author
Sigmaz_1 made it! (author)Sigmaz_12016-10-07

All he would need to do is password.reset() when the door relocks..

author
Bruno.Castro.Fmc made it! (author)2016-09-21

Im having that error : warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Password password = Password( "0000" ); //password to unlock, can be changed

How can i solve it ?

author
jgilbert9632 made it! (author)2016-09-09

I live in a dorm room and often forget my ID to open my door, is it possible to use this to pull down a door handle. How much weight can a servo pull? Does it rotate enough to turn a handle?

author
Spacewhistle2 made it! (author)2016-08-21

what parts of this code do I not use..what else do I have to write to get it to work with rotary phone. Have so many things to make need serious help with code!

author
Spacewhistle2 made it! (author)2016-08-21

I'm tring to use rotary phone as encoder would like to put a lock code in tring everything. Totally lost need some guidance please!

author
JacksonL13 made it! (author)2016-08-08

Hey I tried using the code and I got an error about the password event

author
ElectricNerd15 made it! (author)2016-07-29

The green light isn't lighting up. ;-;

author
adityaj11 made it! (author)2016-02-07

PROGRAM is wrong it shows an error

author
ibenkos made it! (author)ibenkos2016-02-07

The program works fine, what kind of error do you get?

author
adityaj11 made it! (author)adityaj112016-02-14

Compiling error

author
ElectricNerd15 made it! (author)ElectricNerd152016-07-28

Tell me the exact words that are printed out.

author
AdriaanDb04 made it! (author)2016-02-22

I've got a short question: is it possible to use 2 different codes for 2 different actions. Example with code '123' you turn on the green led. And with '456' you turn on a red led and rotate the servo.

author
ElectricNerd15 made it! (author)ElectricNerd152016-07-28

Yes, but you would have to reprogram it. I could try to make a program, if you'd like.

About This Instructable

125,772views

324favorites

License:

Bio: I am always making electronic stuff. I like to do Arduino projects best. more projects coming soon!
More by ibenkos:433MHz 4Ch Remote ControllerWireless Robotic Control Hack a servo
Add instructable to: