CODE LOCK USING RASPBERRY PI

 CODE LOCK USING RASPBERRY PI

INDEX

 1. INTRODUCTION 
 2. PROBLEM DEFINITION
 3. LITERATURE REVIEW
 4. BLOCK DIAGRAM 
 5. IMPORTANT MODULES USED OF RASPBERRY PI BOARD
 6. COMPONENTS
 7. CIRCUIT DIAGRAM
 8. PROGRAMMING CODE
 9. SOFTWARE USED
10.HARDWARE RESULTS SNAPSHOTS
11.COMMENTS ON THE RESULTS
12.SUMMARY 
13.CONCLUSION
14.REFERENCES
 



1. INTRODUCTION 

Security is a major concern in our day-to-day life, and digital locks have become an important part of these security systems. There are many types technologies available to secure our place, like PIR Based security systems, RFID based Security system, Laser security alarms, biomatrix systems etc. 
So, we are going to build a Digital Lock using Raspberry Pi with User Defined Password. Once the password is set, user can only access the door with correct password.

 2. PROBLEM DEFINITION

To build a Digital Lock with user defined password for security purpose.

  3. LITERATURE REVIEW
The advanced digital technology has changed the role and manufacture of locking mechanism and keys to the point that, small plastic pieces, digital numbers and codes, within the computer chip inside "acts more effectively than a lock made from a hunk of metal with a key to open it. Several remote systems have been proposed whether for the academic or business domain. Such systems were intended to provide a remote control and monitoring tasks. For instance, a system was proposed by [3] which is based on Zigbee technology. This system is composed of multiple modules such as the human detection module (HDM) which aims to detect the user at the door which can be performed using the camera module in which the images or the video stream is being processed. Another system proposed by [4] is based on the RFID technology which provides a touch LCD monitor. In addition, a system submitted by [5] is based on design of GSM digital door lock system using PIC platform. 5-digit password is used to lock/unlock the door. If the user submits an incorrect password the system notifies the owner. This served to be the source of idea for our project. However, instead of using GSM, we tried to remove the complexity by using a keypad module for taking input, lcd for displaying welcome, input and error messages, and motor to indicate locking/unlocking of the door by assembling them all together as a single module with the help of raspberry pi. We have used Raspberry Pi 4B here instead of Raspberry Pi 3 due to reverse compatibility. It gives better CPU i.e., better processing and performance speeds, can support 2 to 4K monitors, supports USB 3.0 and USB type C power supply, has more ports and provides more memory for projects. Hence, it was the ideal board for this mini project and served the purpose by making the project more efficient and reliable. 


 4. BLOCK DIAGRAM 






 5. IMPORTANT MODULES USED OF RASPBERRY PI BOARD

In this project, we have made use of 18 GPIO pins out of the 26 available on the board for input or output based on the requirement by using pinMode(), digitalWrite(), digitalRead(), keypad(), buzzer(), lcdcmd(), enter(), gateopen(), gateclose(), gatestop(), and choice() functions in the code. They are GPIO 2, 5, 6, 7, 8, 9, 10, 11, 13, 16, 18, 19, 20, 21 23, 24, 25, 26. 3 Ground pins and a 5V power pin also have been used. GPIO means General Purpose Input/Output. Basically, that’s a pin one can use to write data to external components (output), or read data from external components (input). GPIOs will allow you to read some basic sensors (ex: infrared), control some actuators (those which are working with a ON/OFF mode), and communicate with other hardware boards, such as Raspberry Pi, Arduino, Beaglebone, Jetson Nano, etc. GPIOs are digital pins. The Raspberry Pi 4 GPIOs are quite similar to what we call “digital pins” on an Arduino board. We have used GPIOs 2, 7, 8, 16, 18, 20, 21, 23, 24, 25 for providing output on the LCD and to turn on/off the motor. Pins used for output indicate that we can read a value to it either HIGH or LOW (1 or 0) and GPIOs 5, 6, 9, 10, 11, 13, 19, 26 for taking input from the keypad module. Pins used for input indicate that we can read a value from it either HIGH or LOW (1 or 0). A digital pin has only two states. LOW usually means 0V, and HIGH means 3.3V (with some tolerances). To configure these for input and output via code, we made use of an important library named WiringPi. GND pins are all shorted together and the 5V pin is used to direct power to LCD, motor driver and the bussed resistor which holds together the connections of the keypad module.

  6. COMPONENTS

▪ Raspberry Pi (with booted SD card) - x 1 
▪ Keypad Module - x 1 
▪ Buzzer - x 1 
▪ LCD (16 x 2) - x 1 
▪ 10 kΩ Potentiometer - x 1 
▪ 10 kΩ Resistor pack (Pull-up) - x 1 
▪ LED - x 1 
▪ 1 kΩ Resistor - x 1 
▪ Bread board - x 1 
▪ Power (5 volt) - x 1 
▪ Motor driver L293D - x 1 
▪ Battery (12 Volt) - x 1 / Battery (9 Volt) – x 2 

7. CIRCUIT DIAGRAM



 8. PROGRAMMING CODE

#include<wiringPi.h>
#include<string.h>
#include<stdio.h>
#define buzz 8
#define m1 29
#define m2 28
#define led 27
#define RS 11
#define EN 10
#define D4 6
#define D5 5
#define D6 4
#define D7 1
char pass[4];
char pass1[]={'1','2','3','4'};
int n=0;
char row[4]={21, 14, 13, 12};
char col[4]={22, 23, 24, 25};
char num[4][4]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
void keypad();
void buzzer();
void lcdcmd(unsigned int ch)
33

{
int temp=0x80;
digitalWrite(D4, temp & ch<<3);
digitalWrite(D5, temp & ch<<2);
digitalWrite(D6, temp & ch<<1);
digitalWrite(D7, temp & ch);
digitalWrite(RS, LOW);
digitalWrite(EN, HIGH);
delay(10);
digitalWrite(EN, LOW);
digitalWrite(D4, temp & ch<<7);
digitalWrite(D5, temp & ch<<6);
digitalWrite(D6, temp & ch<<5);
digitalWrite(D7, temp & ch<<4);
digitalWrite(RS, LOW);
digitalWrite(EN, HIGH);
delay(10);
digitalWrite(EN, LOW);

}
void write(unsigned int ch)

{
int temp=0x80;
digitalWrite(D4, temp & ch<<3);
digitalWrite(D5, temp & ch<<2);
digitalWrite(D6, temp & ch<<1);
digitalWrite(D7, temp & ch);
digitalWrite(RS, HIGH);
digitalWrite(EN, HIGH);
delay(10);
digitalWrite(EN, LOW);
digitalWrite(D4, temp & ch<<7);
digitalWrite(D5, temp & ch<<6);
digitalWrite(D6, temp & ch<<5);
34
digitalWrite(D7, temp & ch<<4);
digitalWrite(RS, HIGH);
digitalWrite(EN, HIGH);
delay(10);
digitalWrite(EN, LOW);

}

void clear()

{
lcdcmd(0x01);

}
void setCursor(int x, int y)

{
int set=0;
if(y==0)
set=128+x;
if(y==1)
set=192+x;
lcdcmd(set);

}
void print(char *str)

{
while(*str)

{
write(*str);
str++;

}

}
void begin(int x, int y)

{
lcdcmd(0x02);
35
lcdcmd(0x28);
lcdcmd(0x06);
lcdcmd(0x0e);
lcdcmd(0x01);

}
void enter()

{
clear();
print("Current Passkey:");
setCursor(0,1);
keypad();
if(strncmp(pass,pass1,4)==0)

{
clear();
print("Enter New Passkey");
setCursor(0,1);
keypad();
for(n=0;n<4;n++)
pass1[n]=pass[n];
clear();
print("Passkey Changed.");
delay(3000);
return;

}
else

{
clear();
print("Wrong Passkey");
setCursor(0,1);
print("Try again later");
digitalWrite(led, HIGH);
buzzer();
36
buzzer();
buzzer();
buzzer();
delay(2000);
digitalWrite(led, LOW);
return;

}

}
void gate_open()

{
digitalWrite(m1, LOW);
digitalWrite(m2, HIGH);
delay(2000);

}
void gate_stop()

{
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
delay(2000);

}
void gate_close()

{
digitalWrite(m1, HIGH);
digitalWrite(m2, LOW);
delay(2000);

}
void choice()

{
digitalWrite(col[0], LOW);
digitalWrite(col[1],HIGH);
37
if(digitalRead(row[3])==0)

{
buzzer();
clear();
print("Enter Passkey:");
setCursor(0,1);
keypad();

if(strncmp(pass,pass1,4)==0)

{
clear();
print(" Welcome");
setCursor(0,1);
print("Access Granted");
gate_open();
gate_stop();
gate_close();
gate_stop();
return;

}
else

{
clear();
print("Access Denied");
setCursor(0,1);
print("Try again later");
digitalWrite(led, HIGH);
digitalWrite(buzz, HIGH);
delay(3000);
digitalWrite(led, LOW);
digitalWrite(buzz, LOW);
return;

}

}
38
digitalWrite(col[0], HIGH);
digitalWrite(col[1], LOW);
if(digitalRead(row[3])==0)

{
buzzer();
enter();

}

}
void setup()

{
if(wiringPiSetup()==
-1)
printf("Error");
pinMode(RS, OUTPUT);
pinMode(EN, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
pinMode(led, OUTPUT);
pinMode(buzz, OUTPUT);
for(n=0;n<4;n++)
pinMode(row[n], INPUT);
for(n=0;n<4;n++)
pinMode(col[n], OUTPUT);
for(n=0;n<4;n++)
digitalWrite(col[n], HIGH);

}

void main(void) {
setup();
39
begin(16,2);
print("Electronic Door");
setCursor(0,1);
print("Lock Using RPI ");
delay(2000);
clear();
print("Circuit Digest");
setCursor(0,1);
print("Raspberry Pi");
delay(2000);
clear();
while (1)

{
setCursor(0,0);
//keypad();
print("A
-Input Password");
setCursor(0,1);
print("B
-Change Passkey");
choice();

}
}
void buzzer() {
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW); }
void keypad() {
int i,j;
int x=0,k=0;
delay(2000);
while(k<4)
40
{
for(i=0;i<4;i++)

{
digitalWrite(col[i], LOW);
for(j=0;j<4;j++)

{
if(digitalRead(row[j])==0)

{
setCursor(x,1);
write(num[i][j]);
buzzer();
setCursor(x,1);
write('*');
x++;
pass[k++]=num[i][j];
while(digitalRead(row[j])==0);
}

}
digitalWrite(col[i], HIGH);

}
}
}

 9. SOFTWARE USED
Software used to load and run the code in Raspberry pi: Geany IDE

(Note – We directly implemented the project via Hardware and hence didn’t make use of any
simulation tool or software other than the one used to load and run the program code i.e.,
 Geany IDE whose snapshot is attached above)

10.HARDWARE RESULTS SNAPSHOTS



On running the code, this is the welcome message displayed on the LCD



On clicking A on the keypad, the LCD asks to enter the passkey



If the passkey entered is correct, this message is displayed on the LCD and the motor
 turns on indicating the door is unlocked.



Initial Welcome screen




On clicking B on the keypad, the LCD asks to enter the current passkey to authenticate the
change of password




If the correct passkey is entered, the board gives authentication to change the passkey and
displays the message asking the user to enter a new passkey




Once the new passkey is entered, the passkey is changed and stored.
If the door is tried to unlock again, the same initial procedure should be followed but
 the now the passkey will the new one which is stored.

11.COMMENTS ON THE RESULTS

1.      The system works as desired.

2.      On turning on the raspberry pi, the lcd interfaced with it displays the welcome message. It asks user to choose between entering the password for unlocking the door (turning on the motor) & changing the pin.

3.      If user opts for the first option, it asks to enter the password. If the entered password is correct, the motor turns on and runs for four seconds indicating unlocking of the door.

4.      If the entered password is wrong, the motor doesn’t turn on and an error message is displayed on the LCD.

5.      If user opts for second option, it prompts to enter the current password. If the current entered password is correct, it allows user to change the password but if the current entered password is incorrect, it doesn’t allow user to go ahead and change the password.

6.      This helps maintain security which is the main purpose of this project.


12.SUMMARY 

Safety is the most crucial concern for everyone. Various types of locks, safes, etc. are hence used to preserve and ensafe all of one’s precious items and belongings. One of these methods is to use a password-based lock system, a system where only the one with the correct password can unlock the door, safe, etc. This mini project targets safety and security while being reliable. RASPBERRY PI 4B board is used to control this project by handling all the external components connected to it and processing the code it is run with for the same. The LCD interfaced with it displays all the welcome, input, output and error messages. The user enters the message when prompted to, if it is correct, the board sends message to the motor driver which turns on the motor else error message is displayed. It also provides the user an option for changing the password given that user enter the current password correctly. This is the basic mechanism for the lock system. It proves to be useful, reliable and provides the required security by keeping one’s precious belongings safe, prevent robberies and hence, deliver the essential safety. 



13.CONCLUSION

This mini project helped us to understand how to use a RASPBERRY PI, it’s GPIO pins/ ports and RASPBERRY PI OS, etc.  in unison to

interface external components such as LCD, motor driver, keypad modules etc. with it. Initially we understood the installation process of the RASPBERRY PI OS, its setup and remote connection with board, etc. Next, we learnt and installed various packages needed to compile and run a code written for RASPBERRY PI 4B. Once the code was successfully compiled and installed, the components were finally interfaced with the RASPBERRY PI board as per the circuit diagram. This project took a lot of troubleshooting in every way, a significant amount of time for researching and then debugging the code till its successful compilation. It worked perfectly fine and as desired. Thus, it proved to be useful in understanding the software as well as hardware aspects of RASPBERRY PI by putting it all in order as a mini project. 

14.REFERENCES 

[1]    https://circuitdigest.com/microcontroller-projects/raspberry-pi-digital-lock

[2]    https://www.instructables.com/Password-Based-Door-Lock-System-Using-Raspberry-

Pi/

[3]    I.-K. Hwang and J.-W. Baek, "Wireless access monitoring and control system based on digital door lock," IEEE Transactions on Consumer Electronics, vol. 53, 2007

[4]    Y. T. Park, P. Sthapit, and J.-Y. Pyun, "Smart digital door lock for the home automation," in TENCON 2009-2009 IEEE Region 10 Conference, 2009, pp. 1-6 [5] A. Ibrahim, A. Paravath, P. Aswin, S. M. Iqbal, and S. U. Abdulla, "GSM based digital door lock security system," in Power, Instrumentation, Control and Computing (PICC), International Conference, 2015, pp. 1-6 


keep visiting us again and again & don't forget to leave a comment and your suggestions for the Upcoming Topics.

You may also like : 

Basic Introduction to the Layout & Working of Stock Market in SEVEN POINTS

Seven Reasons Why Everyone Should Play Chess

Post a Comment

0 Comments