Password based door locksystem
-
Upload
uvsofts-technologies -
Category
Engineering
-
view
907 -
download
0
Transcript of Password based door locksystem
PASSWORD BASED DOOR LOCK SYSTEM
The aim of this project is to create a security system which asks for a
password before opening the door and opens the door only if the password
matches the programmed key. The door is opened by motors which in turn are
controlled by this security system.
Project overview:
Password Based Door Lock System
Hardware components required
1. ATMega 16 microcontroller
2. Basic calculator keypad
3. 2x16 LCD
Keypad and LCD are connected with microcontroller to make an easy man-
machine interface to make the system capable of performing the desired
function.
ATMega16 microcontroller: This is the brain of system which is
programmed to take input from user through keypad, perform the
desired operation and the display the appropriate message on the
provided 2x16 LCD.
Basi keypad: This is a 4x4 (having 4 rows and 4 columns) keypad which
is interfaced with microcontroller with its each key assigned a specific
no. or symbol defined in the program.
2x16 LCD: this is the liquid crystal display module capable of
displaying 32 characters in two rows (16 in each row). Microcontroller
displays characters on it while taking inputs from user and to display the
appropriate message to user.
Interfacing keypad with microcontroller
Keyboard Connections to PORTS
With matrix keypads 16 keys can function with 8 pins (4 rows and 4 columns)
of microcontroller’s either same or different ports as convenient.
Scanning and identifying the key pressed
Function to identify a key pressed
//connect colum with lower nibble and rows with upper nibble
#define key_port PORTA
#define key_ddr DDRA
#define key_pin PINA
unsigned char keypad[4][4]={'7','8','9','/',
'4','5','6','*',
'1','2','3','-',
'c','0','=','+'};
char takekey()
{
unsigned char row,colum;
char key;
key_ddr=0xf0;
key_port=0xff;
do
{
key_port&=0x0f;
colum=(key_pin&0x0f);
}while(colum!=0x0f);
do
{
do
{
_delay_ms(1);
key_port&=0x0f;
colum=(key_pin&0x0f);
}while(colum==0x0f);
_delay_ms(1);
key_port&=0x0f;
colum=(key_pin&0x0f);
}while(colum==0x0f);
while(1)
{
key_port=0xef;
colum=(key_pin&0x0f);
if(colum!=0x0f)
{
row=0;
break;
}
key_port=0xdf;
colum=(key_pin&0x0f);
if(colum!=0x0f)
{
row=1;
break;
}
key_port=0xbf;
colum=(key_pin&0x0f);
if(colum!=0x0f)
{
row=2;
break;
}
key_port=0x7f;
colum=(key_pin&0x0f);
row=3;
break;
}
if(colum==0x0e)
key=keypad[row][0];
else if(colum==0x0d)
key=keypad[row][1];
else if(colum==0x0b)
key=keypad[row][2];
else
key=keypad[row][3];
return(key);
}
Interfacing 2x16 LCD with microcontroller (in 4 bit mode)
LCD interfacing with atmega 16
LCD functions in accordance with above figure:
#define en PA2 // enable signal
#define rw PA1 // read/write signal
#define rs PA0 // register select signal
void lcd_cmd(unsigned char cmd)
{
DDRA=0xff;
PORTA=0;
PORTA=cmd&0xf0;
lcd &=~(1<<rs);
lcd &=~(1<<rw);
lcd |= (1<<en);
_delay_ms(1);
lcd &=~(1<<en);
_delay_ms(1);
PORTA=((cmd<<4)&0xf0);
lcd &=~(1<<rs);
lcd &=~(1<<rw);
lcd |= (1<<en);
_delay_ms(1);
lcd &=~(1<<en);
_delay_ms(1);
return;
}
void lcd_data(unsigned char data)
{
PORTA=(data&0xf0);
lcd |=(1<<rs);
lcd &=~(1<<rw);
lcd |= (1<<en);
_delay_ms(1);
lcd &=~(1<<en);
_delay_ms(1); // delay to get things executed
PORTA= ((data<<4)&0xf0);
lcd |=(1<<rs);
lcd &=~(1<<rw);
lcd |= (1<<en);
_delay_ms(1);
lcd &=~(1<<en);
return ;
}
void ini_lcd(void)
{
_delay_ms(5);
lcd_cmd(0x02);
_delay_ms(1);
lcd_cmd(0x28);
_delay_ms(1);
lcd_cmd(0x01); // clear LCD
_delay_ms(1);
lcd_cmd(0x0E); // cursor ON
_delay_ms(1);
lcd_cmd(0x84);
_delay_ms(1);
return;
}
Description:
This system works as follows to open the door:-
i. Asks for the visitor to enter the Password.
ii. If entered password matches the programmed one then it glows the
indicator and run the motors to open the door otherwise takes the
programmed action.
Main Program:
#include<avr/io.h>
#include<util/delay.h>
#include"keypad.h"
#include"4bitlcd.h"
void main()
{
unsigned int pass=5555,key,key1,ch1;
unsigned char ch=0,i,w[]="wrong password",E[]="ENTER PASSWORD";
DDRD=0XFF;
DDRB=0XFF;
_delay_ms(500);
ini_lcd();
while (1)
{
key=0;
ch=0;
lcd_cmd(0X80);
for(i=0;i<15; i++)
lcd_data(E[i]);
lcd_cmd(0xC0);
while(ch!='=') //get password from visitor
{
ch=takekey();
ch1=ch;
if(ch!='=')
{
lcd_data(ch);
key=((key*10)+(ch1-0x30));
}
else
break;
}
lcd_cmd(0x01);
lcd_cmd(0xce);
key1=key;
while(key)
{
lcd_data((key%10)+0x30);
lcd_cmd(0x10);
lcd_cmd(0x10);
key=key/10;
}
ch=takekey();
if(key1!=5555) //compare the entered password
{
lcd_cmd(0x01);
lcd_cmd(0xc1);
for(i=0;i<15; i++)
lcd_data(w[i]);
PORTD=0X0f;
ch=takekey();
}
else
{
PORTD=0XF0;
ch=takekey();
PORTD=0;
}
lcd_cmd(0x01);
}
}