Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Keypad Locking System with User Defined Password

By Gurmeet Singh January 20, 2021

In this keypad lock project I have used the AT89S52 microcontroller, one of the series of 8051 microcontroller by ATMEL corp. Here I’m using 4X4 keypad to take input from the user (to enter password) and display the corresponding results on a 16X2 LCD.
Since AT89S52 doesn’t have its own internal oscillator, thus we need to provide an external crystal of 11.0592 Mhz to make it function able. I am using a 7805 voltage regulator IC to convert 9V to desired 5V output.
In this project, I have used a normal 9V DC battery but we can also connect an AC-DC adapter for longer demonstrations. (For adapter  configuration, look for the datasheet of IC 7805 voltage regulator)
Prototype of 8051 Microcontroller based Keypad Locking System
Fig. 1: Prototype of 8051 Microcontroller based Keypad Locking System
2 LEDs(green, red) also help us to know about status of the lock.Green led lights up when the lock is open and Red led lights up when the lock is closed.I have also indicated the status of lock on the LCD itself, on its bottom right corner.Using a preset(potentiometer), can help us to adjust the contrast of the text on LCD. I have used a preset of 50K.
The default password set is “000”, but user can change this password.To change the password, press “*” on the keypad followed by pressing “#”. It will ask user for the current password, then for the new password followed by its confirmation.On confirming the password, “CHANGE SUCCESSFUL” statement will be shown else “CHANGE UNSECCESSFUL” will appear for which current password will remain authenticated. Password related things are hidden, rather they are shown by “*”. This is done to make password more protected/hidden (only known to user) in real world.
I have used three user defined header file:
< lcd.h>, < delay.h> and <keypad.h>
lcd.h handles with all user defined functions which are needed to operate a 16X2_8 bit   LCD.
delay.h includes  function like delay_msec(), which provides delay in milliseconds according to the TIMERS present in AT89S52.
keypad.h deals with the functions which is responsible for inputting values from 4X4 keypad.
·                     LCD data ports are connected to PORT 3 of AT89S52.
·                     RS, R/W and ES pins of the LCD are connected to P2^0, P2^1, P2^2 respectively.
·                     VEE pin of LCD is connected to a preset to adjust the contrast.
·                     Pins 15 & 16 of LCD are connected to VCC & GND respectively.
·                     The 8 pins of the Keypad are connected to PORT 1 of AT89S52.
·                     The GREEN LED is connected to P2^4 and RED LED to P2^3.
Peripherals that can be attached:
·                     We can use a linear actuator system to provide a mechanical locking system
·                     We can also use a magnetic system for doing the same.
·                     Using a stepper motor/servo motor controlled system in also a good idea.

 Utilities and Drawbacks of This Lock

UTILITIES OF THIS LOCK:
This keypad based system can be used for security purposes like electronic safe, keypad door lock and many more.
This can also be clubbed with some major projects to make them password operated.
DRAWBACKS:
Due to volatile (data vanishes as soon as the supply goes off) nature of the memory of AT89S52, the user defined password will remain retained until reset button is not pressed or supply to the microcontroller is given.
Once reset button is pressed or supply to the microcontroller is cut-off, default password (000) will get activated automatically and hence the user defined password will not exist anymore.
To avoid this we can use EEPROM (Electronically Erasable Programmable Read Only Memory). This will help us to store the user defined password even if the supply goes off or reset button is pressed.
EEPROM is a non volatile memory which means that it will store data in itself even if it is not provided with any supply/voltage.

 

Project Source Code

###

#include
#include
#include
#include

sbit LEDg=P2^4;
sbit LEDr=P2^3;

//// FUNCTIONS FOR LOCK image on LCD////
void lock()
{
Lcd8_Cmd(72);
Lcd8_Write_Char(0);
Lcd8_Write_Char(14);
Lcd8_Write_Char(10);
Lcd8_Write_Char(10);
Lcd8_Write_Char(31);
Lcd8_Write_Char(27);
Lcd8_Write_Char(31);
Lcd8_Cmd(0xcf);
Lcd8_Write_Char(1);

}
void open()
{
Lcd8_Cmd(72);
Lcd8_Write_Char(14);
Lcd8_Write_Char(10);
Lcd8_Write_Char(2);
Lcd8_Write_Char(2);
Lcd8_Write_Char(31);
Lcd8_Write_Char(27);
Lcd8_Write_Char(31);
Lcd8_Cmd(0xcf);
Lcd8_Write_Char(1);
}

//// FUNCTION INPUTTING VALES FROM USERS AND STORING THEM TO AN ARRAY////
void input(char arr[])
{ unsigned char i=0,k=0,N[16];
Lcd8_Cmd(0xc0);
while(k!='#')
{
k=Read_Keypad();
if(k && k!='#')
{
N[i++]=k;
Lcd8_Write_Char('*');
}
}
strcpy(arr,N);
arr[i]='';
}

void main()
{
unsigned char P[16]={"000"}; ///default password

while(1)
{ unsigned char p[16],s[16],j;

LEDg=0;LEDr=1;
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("ENTER PASSWORD");
input(p);

if(strcmp(p,P)==0)
{
Lcd8_Init();
open();
Lcd8_Cmd(0x80);
Lcd8_Write_String("ACCESS GRANTED");
LEDr=0;LEDg=1;
while(Read_Keypad()!='#')
{}
}
else if(strcmp(p,"*")==0)
{
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("CURRENT PASSWORD");
input(p);

if(strcmp(p,P)==0)
{
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("NEW PASSWORD");
input(s);

Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("CONFIRM PASSWORD");
input(p);

if(strcmp(p,s)==0)
{ j=strlen(s);
strcpy(P,s);
P[++j]='';
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("CHANGE");
Lcd8_Cmd(0xc0);
Lcd8_Write_String("SUCCESSFULL");
while(Read_Keypad()!='#')
{}
}
else
{
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("CHANGE");
Lcd8_Cmd(0xc0);
Lcd8_Write_String("UNSUCCESSFULL");
while(Read_Keypad()!='#')
{}
}
}
else
{
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("WRONG PASSWORD");
delay_msec(2000);
}
}
else
{
Lcd8_Init();
lock();
Lcd8_Cmd(0x80);
Lcd8_Write_String("ACCESS DENIED");
LEDr=0;delay_msec(250); LEDr=1;delay_msec(250);
LEDr=0;delay_msec(250);
LEDr=1;delay_msec(250);
LEDr=0;delay_msec(250);
LEDr=1;delay_msec(250);
}
}
}

 

----------------------------------------------------------------------------------

CODE (delay.h)

----------------------------------------------------------------------------------
void delay_msec(int time)
{int i=0;
while(i{TMOD=0x10;
TH1=0xfc;
TL1=0x65;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
i++;
}
}

 
--------------------------------------------------------------------------------------
CODE (lcd.h)
--------------------------------------------------------------------------------------
#include
//LCD Module Connections
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
//End LCD Module Connections

char *string;
//LCD 8 Bit Interfacing Functions

void Lcd8_Cmd(unsigned char value)
{
P3=value;
RS=0;
RW=0;
E=1;
delay_msec(1);
E=0;
}


void Lcd8_Init()
{
Lcd8_Cmd(0x38); //function set
Lcd8_Cmd(0x0C); //display on,cursor off,blink off
Lcd8_Cmd(0x01); //clear display
Lcd8_Cmd(0x06); //entry mode, set increment
}

void Lcd8_Write_Char(unsigned char value)
{

P3=value;
RS=1;
RW=0;
E=1;
delay_msec(1);
E=0;
}

void Lcd8_Write_String(char *a)
{
int i;
string=a;
for(i=0;a[i]!='';i++)
Lcd8_Write_Char(a[i]);
}

void Lcd8_Shift_Right()
{ int j;
for(j=0;j{Lcd8_Cmd(0x1C);delay_msec(100);}
}

void Lcd8_Shift_Left()
{ int k;
for(k=0;k{Lcd8_Cmd(0x18);delay_msec(100);}
}

 


------------------------------------------------------------------------------
CODE (keypad.h)

------------------------------------------------------------------------------
sbit R1 = P1^0;
sbit R2 = P1^1;
sbit R3 = P1^2;
sbit R4 = P1^3;

sbit C1 = P1^4;
sbit C2 = P1^5;
sbit C3 = P1^6;
sbit C4 = P1^7;

//End Keypad Connections

char Read_Keypad()
{
C1=C2=C3=C4=1;

R1=0;
R2=1;
R3=1;
R4=1;
if(C1==0){while(C1==0);return '1';}
if(C2==0){while(C2==0);return '2';}
if(C3==0){while(C3==0);return '3';}
if(C4==0){while(C4==0);return 'A';}
R1=1;
R2=0;
R3=1;
R4=1;
if(C1==0){while(C1==0);return '4';}
if(C2==0){while(C2==0);return '5';}
if(C3==0){while(C3==0);return '6';}
if(C4==0){while(C4==0);return 'B';}
R1=1;
R2=1;
R3=0;
R4=1;
if(C1==0){while(C1==0);return '7';}
if(C2==0){while(C2==0);return '8';}
if(C3==0){while(C3==0);return '9';}
if(C4==0){while(C4==0);return 'C';}
R1=1;
R2=1;
R3=1;
R4=0;
if(C1==0){while(C1==0);return '*';}
if(C2==0){while(C2==0);return '0';}
if(C3==0){while(C3==0);return '#';}
if(C4==0){while(C4==0);return 'D';}
return 0;
}
 

###

 


Circuit Diagrams

Circuit-Diagram-8051-Microcontroller-Based-Keypad-Locking-System

Project Video


Filed Under: Circuit Design
Tagged With: at89s52, keypad lock
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Multiple DC/DC converters and a single input source
  • Xiaomi Mijia 1C Robot problem of going backwards while working
  • Will this TL084C based current clamp circuit work?
  • ADS optimization cockpit window does not open
  • Voltage mode pushpull is a nonsense SMPS?

RSS Electro-Tech-Online.com Discussions

  • Parts required for a personal project
  • Curved lines in PCB design
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz
  • using a RTC in SF basic
  • PIC KIT 3 not able to program dsPIC

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection
  • Convection-cooled power controller integrates EtherCat connectivity

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe