An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a keypad, LCD and the controller AT89C51 which belongs to the 8051 series of microcontrollers. This article describes the making of an electronic code lock using the 8051 microcontroller.
A 4×3 matrix keypad and a 16×2 LCD have been used here. Keypad and LCD are very commonly used input & output devices, respectively. A four digit predefined password needs to be specified the user. This password is stored in the system.
While unlocking, if the entered password from keypad matches with the stored password, then the lock opens and a message is displayed on LCD. Also an output pin is made high to be used for further purpose.
Project Source Code
###
//Program to make a code lock with user defined password #include<reg51.h> #define port P1 #define dataport P2 #define key P0 #define sec 100 sbit rs = port^0; sbit rw = port^1; sbit en = port^2; sbit col1=key^4; sbit col2=key^5; sbit col3=key^6; sbit row1=key^0; sbit row2=key^1; sbit row3=key^2; sbit row4=key^3; sbit lock_output=P0^7; int check=0; int digit[4]={0,0,0,0}; int dig_input[4]={0,0,0,0}; int dig_input_recheck[4]={0,0,0,0}; int i,k; void delay(unsigned int msec) // Time delay function { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); } void lcd_cmd(unsigned char item) // Function to send command to LCD { dataport = item; rs= 0; rw=0; en=1; delay(1); en=0; return; } void lcd_data(unsigned char item) // Function to send data to LCD { dataport = item; rs= 1; rw=0; en=1; delay(1); en=0; return; } void lcd_data_string(unsigned char *str) // Function to send data to string { int i=0; while(str[i]!='