Project tutorial
Password Based Door Lock

Password Based Door Lock © GPL3+

Type your set password using the keypad and open the door lock.

  • 15,263 views
  • 6 comments
  • 29 respects

Components and supplies

About this project

There are numerous websites that have posted this project & it is present on various youtube channels , and maybe even this website has a few of these. So, being honest, its nothing original. But I might be able to explain and display in a simpler and more informative manner.

The major component of this project is the matrix keypad. I have used a 4x4 membrane keypad which looks like this:

The keys on the keypad are basically push buttons. These button switches are 'closed' when pushed and once the force is released, they go back to their natural state i.e. 'open' .

This is how the keypad is connected internally as rows and columns. When, suppose, 1 is pressed, column 1 and row 1 are connected together. When 9 is pressed r3 and c3 are connected together.

Scanning is done with 4 keys configured as outputs and 4 keys as inputs. I made all the columns the inputs using input pullup resistors, and all the rows the outputs. Using programming, all the rows are made LOW one by one, multiple times in a second. So, when a key is pressed, the corresponding column becomes LOW. The state of the input pins to which all the columns are connected, is read, multiple times. Whenever a LOW state is read, it means that a key in that column is pressed. If a certain row is low and at the same time a certain column is low, then the pressed key is determined.

For e.g. if 1 is pressed, column 1 will be low. And since each row is made LOW so so fast, one by one, even if you press the key for a very short span, row 1 will be found LOW sometime and it will be determined that 1 is pressed. If row1==low && column1==low, it means that 1 is pressed.

This is shown in code 1. I wrote this code myself because I wanted to upload it to stm32 board and the KEYPAD library wasn't compatible. With this code, you'll understand what I explained above. Or you can simply use the keypad library and run the 'customkeypad' example. Both will serve the same purpose. But that code won't explain you the working.

Using serial monitor, each key that is pressed is displayed on the screen. This is shown in video 1.

After the key determination works fine, its time to work on the password. Its so simple. What I did was - made a string "1234". This is the password that I had set. Now, I made another array. Whatever the key value is, its stored in this array. When count reaches 4, both the strings are compared. If they match - the password is correct, else not. This is shown in code 2. I connected an LED to the pin 11. So, that when the password is correct, it glows. It is shown in video 2.

Now, the component that will be used as the lock: 12 V linear actuator. It looks like this.

This is operated using L293d IC which is otherwise commonly known as the 'motor driver' IC. This IC is conected to the 12v supply. It takes inputs from the Arduino i.e. 5v input, and outputs 12v to its output pins (to which the actuator is connected). So, when the password is correct, pin 11 is set high and pin 12 is set low. Pins 11 and 12 are connected to the inputs of the l293d. Hence, the actuator is pulled inside and the door opens. shown in video 3.

Code

code 1Arduino
Scanning
int rows=4;
int columns=4;
char readkey(void);
char nfunc(void);
#define c3 9
#define c2 8
#define c1 7
#define c0 6
#define r3 5
#define r2 4
#define r1 3
#define r0 2
void setup() {
  Serial.begin(9600);
 pinMode(c0,INPUT_PULLUP); 
 pinMode(c1,INPUT_PULLUP);
 pinMode(c2,INPUT_PULLUP);
 pinMode(c3,INPUT_PULLUP);
 pinMode(r0,OUTPUT);
 pinMode(r1,OUTPUT);
 pinMode(r2,OUTPUT);
 pinMode(r3,OUTPUT);
 pinMode(11,OUTPUT);
 pinMode(12,OUTPUT);

}
char readkey(void)
{digitalWrite(r0,LOW);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){delay(500);
return '1';}
else if(digitalRead(c1)==LOW){delay(500);
return '2';}
else if(digitalRead(c2)==LOW){delay(500);
return '3';}
else if(digitalRead(c3)==LOW){delay(500);
return 'A';}

digitalWrite(r0,HIGH);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){delay(500);
return '4';}
else if(digitalRead(c1)==LOW){delay(500);
return '5';}
else if(digitalRead(c2)==LOW){delay(500);
 return '6';}
else if(digitalRead(c3)==LOW){delay(500);
return 'B';}

digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){delay(500);
return '7';}
else if(digitalRead(c1)==LOW){delay(500);
return '8';}
else if (digitalRead(c2)==LOW){delay(500);
return '9';}
else if(digitalRead(c3)==LOW){delay(500);
return 'C';}

digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
if(digitalRead(c0)==LOW){delay(500);
return '*';}
else if(digitalRead(c1)==LOW){delay(500);
return '0';}
else if(digitalRead(c2)==LOW){delay(500);
return '#';}
else if(digitalRead(c3)==LOW){delay(500);
return 'D';}
return 'o';
}

char nfunc(void)
{
  char key='o';
  while(key=='o')
  key=readkey();
return key;
}

void loop()
{
char key1= nfunc();

if(key1){
  Serial.print(key1);

}

}
code 2Arduino
password
int rows=4;
int columns=4;
int count=0;
char readkey(void);
char nfunc(void);
#define c3 9
#define c2 8
#define c1 7
#define c0 6
#define r3 5
#define r2 4
#define r1 3
#define r0 2
char password[5]="1234";
char typed[5];

void setup() {
  Serial.begin(9600);
 pinMode(c0,INPUT_PULLUP); 
 pinMode(c1,INPUT_PULLUP);
 pinMode(c2,INPUT_PULLUP);
 pinMode(c3,INPUT_PULLUP);
 pinMode(r0,OUTPUT);
 pinMode(r1,OUTPUT);
 pinMode(r2,OUTPUT);
 pinMode(r3,OUTPUT);
 pinMode(11,OUTPUT);
 pinMode(12,OUTPUT);

}
char readkey(void)
{digitalWrite(r0,LOW);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){delay(500);
return '1';}
else if(digitalRead(c1)==LOW){delay(500);
return '2';}
else if(digitalRead(c2)==LOW){delay(500);
return '3';}
else if(digitalRead(c3)==LOW){delay(500);
return 'A';}

digitalWrite(r0,HIGH);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){delay(500);
return '4';}
else if(digitalRead(c1)==LOW){delay(500);
return '5';}
else if(digitalRead(c2)==LOW){delay(500);
 return '6';}
else if(digitalRead(c3)==LOW){delay(500);
return 'B';}

digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){delay(500);
return '7';}
else if(digitalRead(c1)==LOW){delay(500);
return '8';}
else if (digitalRead(c2)==LOW){delay(500);
return '9';}
else if(digitalRead(c3)==LOW){delay(500);
return 'C';}

digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
if(digitalRead(c0)==LOW){delay(500);
return '*';}
else if(digitalRead(c1)==LOW){delay(500);
return '0';}
else if(digitalRead(c2)==LOW){delay(500);
return '#';}
else if(digitalRead(c3)==LOW){delay(500);
return 'D';}
return 'o';
}

char nfunc(void)
{
  char key='o';
  while(key=='o')
  key=readkey();
return key;
}

void loop()
{
char key1= nfunc();

if(key1){
typed[count]=key1;
  count++;
  Serial.print(key1);

}
if(count==4){
if(strcmp(typed,password)==0)
{
  Serial.println(" correct");
  digitalWrite(11,HIGH);
  digitalWrite(12,LOW);
  delay(250);
  digitalWrite(11,LOW);
}
else{
  Serial.println(" intruder");
}
count=0;
}}

Schematics

keypad connection with arduino
Img 20160924 221103
l293d connection
Connect actuator where the motor is connected.
Connect pin 8 to 12v
L293d%20cirucit%20diagram
Video 1
pressed key displayed on the screen
VID_20160924_195032.mp4
Video 2
led glows when the password is correct
VID_20160924_200016.mp4
Video 3
The actuator is pulled outside in normal case (i.e. the door is locked).
When the password is correct , it is pulled inside and the door opens
VID_20160924_201528.mp4

Comments

Similar projects you might like

Arduino and Android Based Password Protected Door Lock

Project tutorial by Md. Khairul Alam

  • 11,083 views
  • 6 comments
  • 46 respects

Arduino and Android Based Bluetooth Password Lock

Project tutorial by Md. Khairul Alam

  • 16,764 views
  • 7 comments
  • 29 respects

How to make Arduino based Automatic Door Opening

Project tutorial by vijendra kumar

  • 19,831 views
  • 6 comments
  • 15 respects

Smart BT Door Lock (Simple Arduino)

Project showcase by Arun

  • 7,263 views
  • 1 comment
  • 19 respects

RFID Based Automatic Door System

Project showcase by Robodia Technology

  • 35,756 views
  • 20 comments
  • 97 respects
Add projectSign up / Login