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, bio-matrix systems etc. Even now, there are Digital locks which can be operated using our smart phones, means no more need to keep different keys, just one smart phone can operate all the locks, this concept is based on Internet of Things.

In this project, we have explained a simple Electronic code lock using 8051 Microcontorller, which can only be unlocked by a predefined code, if we enter the wrong code, the system alerts by siren the buzzer. We have already created a Digital lock using Arduino.

Working Explanation:

This system mainly contains AT89S52 microcontroller, keypad module, buzzer and LCD. At89s52 microcontroller controls the complete processes like taking password form keypad module, comparing passwords predefined password, driving buzzer and send status to LCD display. Keypad is used for inserting password into the microcontroller. Buzzer is used for indication of wrong password and LCD is used for displaying status or messages on it. Buzzer has inbuilt driver by using a NPN transistor.

In this circuit we have used multiplexing technique to interface keypad to the 8051 microcontroller, for entering the password in the system. Here we are using a 4x4 keypad which has 16 keys. If we want to use 16 keys then we need 16 pin for connection to 89s52, but in multiplexing technique we need to use only 8 pins for interfacing 16 keys. So that it is a smart way to interface the keypad module.

Multiplexing technique is a very efficient way to reduce number of pins used with the microcontroller for providing the input or password. Basically this technique is used in two ways - one is row scanning and other one is column scanning.

Here we are going to explain row scanning:

First we have to define 8 pin for keypad module. In which first 4 pins are column and last 4 pins are rows.

For row scanning we need to give data or signal to column pins and read that data or signal from row pin. Now suppose we give below data to column pins:

C1=0;
C2=1;
C3=1;
C4=1;

And we read this data at row pins (by default row pins are HIGH due to pull-up resistor).

If user presses key number ‘1’ then R1 changes HIGH to LOW means R1=0; and controller understands that user has pressed key ‘1’. And it will print ‘1’ on the LCD and store ‘1’ in array. So this HIGH to LOW change at R1, is the main thing by which controller understands that some key, corresponding to Column 1, has been pressed.

Now if user presses key number ‘2’ then R1 remains at HIGH as C1 and R1 both are already at HIGH. Hence there will be no change, it means microcontroller understands that nothing has been pressed in column one. And likewise this principal goes for all another pins. So in this step controller only waits for keys in column one: ‘1’, ‘4’, ‘7’ and ‘*’.

Now if we want to track the keys in other columns (like in col 2), then we need to change the data at columns pins:

C1=1;
C2=0;
C3=1;
C4=1;

This time controller only waits for keys in column two: ‘2’, ’5’, ’8’and ‘0’, because change (HIGH to LOW) only occurs when column two keys will be pressed. If we press any key in col 1, 3 or 4 then no change will occur, because these columns are at HIGH, and Rows are already at HIGH.

So likewise keys in column C3 and C4 can also be tracked by making them 0, at a time. Check here the detailed explanation: Keypad Interfacing with 8051. Also go through the Code section below for properly understand the logic.

Circuit Explanation:

Circuit diagram for this Digital lock using 8051 has been shown below and can easily be understood. Keypad module’s Column pins are directly connected to pin P0.0, P0.1, P0.2, P0.3 and Row pins are connected to P0.4, P0.5, P0.6, P0.7 of 89s52 microcontroller’s port 0. A 16x2 LCD is connected with 89s52 microcontroller in 4-bit mode. Control pin RS, RW and En are directly connected to pin P1.0, GND and P1.2. And data pin D4-D7 is connected to pins P1.4, P1.5, P1.6 and P1.7 of 89s52. And one buzzer is connected at pin P2.6 through a resistor.

Program Explanation:

We have used a predefined password in the program, this password can be defined by the user in the code below. When user enters a password to the system, then system compares the user entered password with stored or predefined password in Code of Program. If a match occurs then LCD will show “Access Grated” and if the password doesn’t match then LCD will show “Access Denied” and buzzer will continuously beep for some time. Here we have used string.h library. By using this library we can compare or match two strings, by using “strncmp” function.

In the program, first of all we include header file and defines variable and input & output pins for keypad and LCD.

Function for creating the delay of 1 second has been created, along with some LCD functions like for LCD initialization, printing the string, for commands etc. You can easily find them in Code. Check this article for LCD interfacing with 8051 and its functions.

After this, in main program we have initialize LCD and then we read the input from Keypad using the keypad() function and stores input keys into an array and then compare it from predefined array data using strncmp.

Comments

Hi guys im currently doing a project on a security system using the microntroller 8051 , and wanted to try the code to demo . But when i run my code on Silicon IDE , the code is able to be build and download into the microntroller . But the LCD doesnt seem to light up with the Enter The Password for me to type input the password . Can you guys help me out .