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
#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-
[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
0 Comments