Password Based Door Open System Using LPC2148

In this tutorial, we are going to see Password Based Door Open System Using LPC2148 Project.

Prerequisites

Before we will start I would suggest you to read these topics. Then only you can understand this strongly. If you already know, please go ahead.

Password Based Door Open System Using LPC2148

Introduction

In the present scenario of the world, security is a major concern for all, and the security problem is being faced by every person. The usual means of securing anything is through mechanical locks, which operate with a specific key or a few keys; but, for locking a large area many locks are necessary. However, conventional locks are heavy and do not offer the desired protection as they can be easily broken down by using some tools. Therefore, security breaching problems are associated with mechanical locks. However to decide the electronic-based locking system problems that are associated with the mechanical locks.

Nowadays, many devices’ operations are based on digital technology. For example, a token-based digital identity device. Here we will see  Password Based Door Open System Using LPC2148.

Application and Advantage

  • Can be used in various rooms like seminar hall, conference room, and study rooms in college.
  • The project (password detector) can be used to automate the door locking process, so the user need not to carry the door lock keys along with them, they need to just remember the password and use it later to open the door.
  • It will add good security.

Components Required

  • LPC2148 Development board
  • LCD Module
  • 4*3 Keypad
  • DC Motor
  • L293D (Motor Driver)

Software Required

  • Keil IDE

Block Diagram

This project consists of blocks as a microcontroller, a keypad, an LCD, a DC motor, and a motor driver.

  • The keypad is an input device which helps to enter a password to open the door.
  • Then, it gives the entered code signals to the microcontroller.
  • The LCD is used to indicating devices for displaying the information.
  • The DC motor moves the door to open and close and the motor driver drives the motor after receiving the code signals from the microcontroller.

Circuit Diagram

LCD:

  • RS – P0.2
  • RW – GND
  • EN – P0.3
  • Data lines – P0.4 to P0.7 (4 Bit Mode)

DC Motor (Motor Driver):

  • Input 1 – Port 0.16
  • Input 2 – Port 0.17
  • Enable 1 – P0.18

Keypad:

  • R1 – P1.16
  • R2 – P1.17
  • R3 – P1.18
  • R4 – P1.19
  • C1 – P1.20
  • C2 – P1.21
  • C3 – P1.22

Password Based Door Open System Using LPC2148

Code

It will ask for the Password. By default password is “5555”. It will open the door and again will close if we enter the correct password. Otherwise, it won’t open the door at all.

[Download the Source code from GitHub]

#include<lpc214x.h>

#define bit(x) (1<<x)

unsigned char pass[4] = "5555";   //Set your Password

void delay ()
{
    unsigned int temp, ct;
    for(ct=0; ct<30; ct++) {
        for(temp=0; temp < 65000; temp++);
    }
}
unsigned int range=0,i;

/* --------- DC Motor ----- */
void forward(void);
void reverse(void);
void stop(void);
/* --------- LCD ---------*/
 
void lcd_init(void);
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void lcd_delay(void);

/* ---------- Keypad ------*/
#define c1 (IOPIN1&1<<20)
#define c2 (IOPIN1&1<<21)
#define c3 (IOPIN1&1<<22)

unsigned char r_loc,c_loc;
unsigned char key[4][3]={"123","456","789","*0#"};
unsigned char keypad(void);

/* ------- Main -------*/
int main()
{
    
    unsigned char rx_arr[4];
    int count;
    
    VPBDIV=0x01;                 // PCLK = 60MHz
    IO1DIR |= 0x0f<<16;
    IO0DIR |= 0xf00fc;
    
    lcd_init();

    while(1) {
        cmd(0x80);
        show("#Enter Password#");
        
        cmd(0xc5);
        for(count=0; count <4; count++) {
            rx_arr[count] = keypad();
            dat('*');
        }
        
        if ( (pass[0] == rx_arr[0]) && 
                (pass[1] == rx_arr[1]) && 
                (pass[2] == rx_arr[2]) && 
                (pass[3] == rx_arr[3]) ) {
            cmd(0xc0);
            show("   Thank You!   ");
            forward();
            delay();
            stop();
            cmd(0xc0);
            show("  Come Again!!  ");
            delay();
            reverse();
            delay();
            stop();
        } else {
            cmd(0xc0);
            show("~Wrong Password~");
            delay();
        }
        cmd(0x01);
        
    }
}

/* ----- Keypad Function ----*/
unsigned char keypad()
{
    IO1PIN &= ~(0xff<<16);
    IO1PIN |= 0xf0<<16;

    while(c1 && c2 && c3);
    while(!c1 || !c2 || !c3) {
        if(!c1 && c2 && c3)     c_loc=0;
        else if(c1 && !c2 && c3)    c_loc=1;
        else if(c1 && c2 && !c3)    c_loc=2;

        IO1CLR = 1<<16;
        IO1SET = 0x0e<<16;
        if(!c1 || !c2 || !c3) {
            r_loc=0;
            break;
        }

        IO1CLR = 1<<17;
        IO1SET = 0x0d<<16;
        if(!c1 || !c2 || !c3) {
            r_loc=1;
            break;
        }
        
        IO1CLR = 1<<18;
        IO1SET = 0x0b<<16;
        if(!c1 || !c2 || !c3) {
            r_loc=2;
            break;
        }

        IO1CLR = 1<<19;
        IO1SET = 0x07<<16;
        if(!c1 || !c2 || !c3) {
            r_loc=3;
            break;
        }
    }
    while(!c1 || !c2 || !c3);
    return (key[r_loc][c_loc]);
}


/* ----- LCD Functions -------*/

void lcd_init()
{
    cmd(0x02);
    cmd(0x28);
    cmd(0x0c);
    cmd(0x06);
    cmd(0x80);
}
 
void cmd(unsigned char a)
{
    IO0PIN &= 0xffffff03;
    IO0PIN |= (a & 0xf0) << 0;
    IO0CLR |= bit(2);                //rs=0
    IO0CLR |= bit(1);                //rw=0
    IO0SET |= bit(3);                 //en=1
    lcd_delay();
    IO0CLR |= bit(3);                 //en=0
    
    IO0PIN &= 0xffffff03;
    IO0PIN |= ((a << 4)  & 0xf0) << 0;
    IO0CLR |= bit(2);                //rs=0
    IO0CLR |= bit(1);                //rw=0
    IO0SET |= bit(3);                 //en=1
    lcd_delay();
    IO0CLR |= bit(3);                 //en=0
}
 
void dat(unsigned char b)
{
    IO0PIN &= 0xffffff03;
    IO0PIN |= (b & 0xf0) << 0;
    IO0SET |= bit(2);                //rs=1
    IO0CLR |= bit(1);                //rw=0
    IO0SET |= bit(3);            //en=1
    lcd_delay();
    IO0CLR |= bit(3);            //en=0
    
    IO0PIN &= 0xffffff03;
    IO0PIN |= ((b << 4)  & 0xf0) << 0;
    IO0SET |= bit(2);                //rs=1
    IO0CLR |= bit(1);                //rw=0
    IO0SET |= bit(3);            //en=1
    lcd_delay();
    IO0CLR |= bit(3);            //en=0
}
 
void show(unsigned char *s)
{
    while(*s) {
        dat(*s++);
    }
}
 
void lcd_delay()
    {
    unsigned int i;
    for(i=0;i<=1000;i++);
}

/* ---------- DC Motor ---------*/
void forward()
{
    
    IO0SET = bit(16) | bit(18);
    IO0CLR = bit(17);   
}

void reverse()
{
    
    IO0SET = bit(17) | bit(18);
    IO0CLR = bit(16);   
}

void stop()
{
    IO0CLR = bit(18);   
}


 

Output

You can also add many features in this project like you can send messages to the owner if multiple wrong attempts, you can add a buzzer.

 

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader TutorialsRaspberry PI Pico Tutorials

 

5 3 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

23 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
23
0
Would love your thoughts, please comment.x