pic16f877 password locker

Hits: 188

Security is a serious issue that needs to be addressed in our society today. This project tends to bring solution to does security challenges we face in our everyday life. This is an electronic password lock security system that allows you to keep your home and other things safe and protected using your own personal password. This electronics device can be installed in doors of your home, rooms, offices or workplace, garages or even safe boxes. It allows the user to enter their password to lock and unlock. The desired password can be changed to what your want in the MicroC code. It have a buzzer that sounds whenever an intruder tries to guess your password and also comes with an LCD display that shows you the current security state of your place.

You can easily build this project on your own at home for your own use. This project is built using a PIC micro-controller and the MicroC code is simple and easy to understand and use. I also explained how you can make you own with the circuit diagram and the code given. The materials for the project is cheap and can be easily find in any electronics store around the world and even in online stores.

Circuit Diagram

pic16f877 password locker circuit

Materials required:

  1. Pic16f877 micro-controller.
  2. LCD 20 x 4.
  3. Keypad 4 x 3.
  4. 12 volts DC motor.
  5. 2n2369 transistor.
  6. 1k resistor.
  7. A breadboard.
  8. 5 and 12 volts power supply.
  9. connecting wires.
  10. A buzzer.

Explanation of the Circuit Diagram

You can build this project on your own by assembling and connecting the the circuit diagram of this project correctly using a breadboard plug in your pic16f877 micro controller in and connect the LCD to it. Make sure you connect the D4, D5, D6 and D7 to the pin RBO, RB1, RB2 and RB3 as shown in the circuit diagram. Then connect RS and E of the LCD to the RB4 and RB5 of the micro controller respectively and also the VSS pin to ground GND and VDD to +5 volts power supply. Connect the pin A, B, C, D and pin 1, 2, 3 of the keypad to the RD0, RD1, RD2 and also RD4, RD5, RD6, RD7 as shown in the circuit diagram respectively. The reset pin is connected to pin 1 of the micro controller which is the MCLR of the PIC micro controller to the power supply using a 1k resistor. After you program the pic16f877 with the HEX file produced after compiling the program using microC for PIC IDE.

MicroC code here

Author: Okolo Anthony
Date: 11/11/2018
Project: Password Protected Door lock

unsigned short kp;
char actual_password[] = "12345678";
char given_password[] = "00000000";
int count;
// LCD module connections
// LCD pins declaration
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit buzzerpin at RB6_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit buuzerpin at TRISB6_bit;
// End LCD module connections

// Keypad module connections
char keypadPort at PORTD;
// End Keypad module connections

void showPassword(){
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1, 1, "Motor is Off");
Lcd_Out(2,1,"and Locked");

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1, 1, "Enter your Password:");

Lcd_Cmd(_LCD_BLINK_CURSOR_ON); // Cursor off

int PasswordChecker(){

if(!memcmp(actual_password, given_password, 6)){
Lcd_Out(1, 1, "Password Matched");
Lcd_Out(2,1,"Motor is on");

return 1;
Lcd_Out(1, 1, "Incorrect Password");
Lcd_Out(2, 1, "Try Again!");

return 0;

void Init(){
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Welcome to");
Lcd_Out(2, 1, "Password Lock");
Lcd_Out(3, 2, "Security system");
Lcd_Out(4, 1,"www.hertzelectroz.com");


Keypad_Init(); // Initialize Keypad

void buzzer()

int i;
void main() {
do {
kp = 0; // Reset key code variable
PORTB.B7= PasswordChecker(); //0/1 according to password check and drives the motor
Lcd_Out(1,1,"Press * to Off");
Lcd_Out(2,1,"and Lock again");
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

kp = Keypad_Key_Click(); // Store key code in kp variable
while (kp!=13);

// Wait for key to be pressed and released

kp = Keypad_Key_Click(); // Store key code in kp variable
while (!kp);
switch (kp) {
case 1: kp = 49;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 1 
case 2: kp = 50;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 2
case 3: kp = 51;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 3
case 4: kp = 65;Lcd_Chr_Cp(kp); break; // A
case 5: kp = 52;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 4
case 6: kp = 53;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 5
case 7: kp = 54;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 6
case 8: kp = 66;Lcd_Chr_Cp(kp); break; // B
case 9: kp = 55;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 7
case 10: kp = 56;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 8
case 11: kp = 57;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 9
case 12: kp = 67;Lcd_Chr_Cp(kp); break; // C
case 13: kp = 42;Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);count--; break; // *
case 14: kp = 48;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 0
case 15: kp = 35;Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);count++; break; // #
case 16: kp = 68;Lcd_Chr_Cp(kp); break; // D

} while (1);



Leave a Reply