Introduction: Arduino Door Lock With Password

Picture of 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.


Picture of PARTS & TOOLS

For this project I used:

* Arduino uno ( )

* 4x4 matrix keypad, can also use 3x4( )

* Arduino PCB shield ( )

* 2x 1k OHM resistors ( )

* 3mm green and red LEDs ( )

* Male pin header ( )

* Female pin header ( )

* Servo ( )

* Wires ( )

The tools you are going to need:

* Soldering iron

* Soldering paste

* Soldering tin

* Plier

Step 2: Schematic

Picture of Schematic

Follow the schematic.

Step 3: Solder the Connectors

Picture of 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

Picture of 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

Picture of 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


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.


achrefab095 (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 )

JohnM703 (author)achrefab0952017-09-17

dude ask once, not like 30 times

riched (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

Moody2000 (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.

ama3801 (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 .



//Add code to run
if it works

myservo.write(150); //deg


digitalWrite(11, HIGH);//turn on

//wait 5 seconds

LOW);// turn off

ama3801 (author)2017-05-04


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

this is my project

Sai CharanR (author)achrefab0952017-04-09

i am a begginer will u help me to do this

TomG184 (author)2017-03-09

how i connect the pins for 3x4 numpad ?

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?

ShahrulM (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 ?

achrefab095 (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 )

abhineshrocks (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

ibenkos (author)abhineshrocks2015-11-01

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

dinotom (author)ibenkos2016-07-31

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

Bayslayerking (author)dinotom2016-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);




void loop()


char key = keypad.getKey();

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


position = 0;



if (key == password[position])


position ++;


if (position == 3)






void setLocked(int locked)


if (locked)


digitalWrite(redPin, HIGH);

digitalWrite(greenPin, LOW);





digitalWrite(redPin, LOW);

digitalWrite(greenPin, HIGH);




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 )

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

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

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

why i have error?

MichaelB1068 (author)aimimimie2017-01-24

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

JbW4 (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

Gerhard AndreasL (author)JbW42017-01-13


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

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

aj_98 (author)2016-11-14


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

Shayan Das (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.

ibenkos (author)Shayan Das2015-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

KamranF1 (author)ibenkos2016-11-07


Sigmaz_1 (author)Shayan Das2016-10-07

I2C LCD only uses 2 pins

porpoisepower69 (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

MegaN6 (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

ibenkos (author)MegaN62015-08-22

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

Sigmaz_1 (author)ibenkos2016-10-07

you can store code changes in the EEPROM.

Shayan Das (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

ibenkos (author)Shayan Das2015-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 :)

Sigmaz_1 (author)ibenkos2016-10-07


void checkPassword() {

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



} else {

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





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

//add code to run if it did not work


digitalWrite(12, HIGH); //turn on

delay(500); //wait 5 seconds

digitalWrite(12, LOW);//turn off





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




Shayan Das (author)ibenkos2015-09-01

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

RajatS12 (author)Shayan Das2015-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.

ben.dobbs.3 (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.

Sigmaz_1 (author)ben.dobbs.32016-10-07

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

Bruno.Castro.Fmc (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 ?

jgilbert9632 (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?

Spacewhistle2 (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!

Spacewhistle2 (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!

JacksonL13 (author)2016-08-08

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

ElectricNerd15 (author)2016-07-29

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

adityaj11 (author)2016-02-07

PROGRAM is wrong it shows an error

ibenkos (author)adityaj112016-02-07

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

adityaj11 (author)ibenkos2016-02-14

Compiling error

ElectricNerd15 (author)adityaj112016-07-28

Tell me the exact words that are printed out.

AdriaanDb04 (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.

About This Instructable




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: