This tutorial covers on how to make a secured door lock until the right password is typed in via computer. suppose you are sitting in a room far away from doors I know sometimes you might get fed up responding all time people who are knocking at your doors. this project will only give you permission to allow the entry of person but not any other member at your room as the system is secure with predefined password.the same code given here works fine on both systems whether you want to run this project witlessly or by wired provided you just need to add wireless circuitry.To understand wireless circuitry click here
Proteus Design
Code
/*
* cmp_doorlock.c
*
* Created: 7/8/2014 9:57:52 PM
* Author: rohit
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#define lcdport PORTA
#define signal PORTB
#define en PB2
#define rw PB1
#define rs PB0
#define m1 PB5
#define m2 PB4
void lcdcmd(unsigned char cmd);
void lcdint();
void lcddata(unsigned char data);
void lcd_print(char * str);
void usart_init();
void usart_user();
void usart_pass();
void usart_send(unsigned char);
void entry();
unsigned char value;
unsigned char suser[15];
unsigned char spass[15];
unsigned char pass[]="1234";
unsigned char user[]="rohit";
void usart_init()
{
UCSRB=(1<<TXEN)|(1<<RXEN); // transmit enable
UCSRC=(1<<UMSEL)|(1<<UCSZ1)|(1<<UCSZ1); //synchronous mode,8-bit character size
UBRRL=0x33; //9600 baud rate
}
int main(void)
{
usart_init();
DDRA=0xff;//output port
DDRB=0xff;
lcdint();
while(1)
{
lcdcmd(0x01);
lcdcmd(0x02);
lcdcmd(0x80);
lcd_print("user id");
_delay_ms(200);
lcdcmd(0xc0);
usart_user();
entry();
}
}
void entry()
{
if ((strcmp(suser,user)==0))
{
lcdcmd(0x01);
lcdcmd(0x02);
lcd_print("id matched");
_delay_ms(2000);
lcdcmd(0x01);
lcdcmd(0x02);
lcd_print("password");
_delay_ms(200);
lcdcmd(0xc0);
usart_pass();
if((strcmp(spass,pass)==0))
{
lcdcmd(0x01);
lcdcmd(0x02);
lcd_print("id matched");
_delay_ms(2000);
lcdcmd(0x01);
lcd_print("opening door");
signal|=(1<<m1);
_delay_ms(10000);
signal&=~((1<<m1)|(1<<m2));
_delay_ms(5000);
lcdcmd(0x01);
lcd_print("closing door");
signal|=(1<<m2);
_delay_ms(10000);
signal&=~(1<<m2);
}
else
{
lcdcmd(0x01);
lcdcmd(0x02);
lcd_print("wrong entry");
lcdcmd(0xc0);
lcd_print("try again");
_delay_ms(5000);
}
}
else
{
lcdcmd(0x01);
lcdcmd(0x02);
lcd_print("invalid user");
lcdcmd(0xc0);
lcd_print("try again");
_delay_ms(5000);
}
}
void lcdint()
{
lcdcmd(0x38);
_delay_ms(1);
lcdcmd(0x01);
_delay_ms(1);
lcdcmd(0x0E);
_delay_ms(1);
}
void lcdcmd(unsigned char x)
{
lcdport=x;
signal|=(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
signal&=~((1<<rs)|(1<<rw)|(1<<en));
_delay_ms(50);
}
void lcddata(unsigned char data)
{
lcdport= data;
signal|=(1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
signal&=~((0<<rs)|(1<<rw)|(1<<en));
_delay_ms(50);
}
void lcd_print(char * str)
{
unsigned char i = 0;
while(str[i]!=0)
{
lcddata(str[i]);
i++;
}
}
void usart_user()
{
int k;
for(k=0;k<5;k++)
{
while(!(UCSRA & (1<<RXC)));
value=UDR;
suser[k]=value;
usart_send(value);
lcddata(value);
_delay_ms(500);
}
}
void usart_pass()
{
int r;
for(r=0;r<4;r++)
{
while(!(UCSRA & (1<<RXC)));
value=UDR;
spass[r]=value;
usart_send(value);
lcddata('*');
_delay_ms(500);
}
}
void usart_send(unsigned char ch)
{
while(!(UCSRA & (1<<UDRE))); //wait until UDR is empty
UDR=ch;
}
Video
Category: