Keypad Input and Access Control for Locks with LCD using CloudX M633 CloudX

  • img
Project Details

Keypad access control is an easy means to restrict access to unwanted visitors and has the advantage of not requiring a physical key. Just don’t forget the pin code.

Today we will build a keypad access control with an LCD feedback. We will briefly look at the types of keypads available, then we’ll build a keypad access system using an CloudX M633 board and a few extra components. 

 

What is Keypad Access Control ?
 

Keypad access control is commonly found to control electric door locks, safe doors, electric gates, alarm system panels and anywhere where keyless entry is required.

Generally a 4 digital code is required but for further security you can have a larger pin code with 6 or however many digits you can remember! The more pins number you use, the more secure. But in this tutorial i use 4 digital Code.

Keypads generally come in two flavors , a series of direct switches or a switch matrix. They both have their pros and cons which we will go through now.

 

Types of Keypad – Switches Vs Scan Matrix Keypads ?
 

A keypad is just a series of switches, however, the simplest form has one wire per switch. So a 4×4 keypad,  that is 4 columns by 4 rows will use 17 wires including the earth wire.A 3×4 keypad will use 13 wires including the earth wire.

Image result for keypad 4x4

 

The other type of keypad is the scan matrix, which is also a series of switches but requires extra code to scan the rows and columns. This has the advantage of using less wires, so a 4×4 key pad will only require 8 wires (3×4 keypad will require 7 wires), but require more code for the scanning algorithm.

Image result for keypad 4x4

 

Build a Keypad Access Control with LCD using Arduino Board
 

So now that you have a better idea of the keypad types and requirements, we will build a keypad access system that uses a simple direct switch keypad to input a 4 digit pin. We also make the code robust so that if the wrong pin is entered, it will tell you and some features.

 

Components Required to build a Keypad Access Control with LCD

  • CloudX M633
  • SoftCard
  • LCD 16x2 display
  • 4×4 keypad
  • Bread board
  • 4x 10k ohm resistor
  • 1k resistor
  • hookup wire.
  • Red Led
  • Green Led

 

 

 

Building the circuit

 

We wire up the circuit as per the schematic diagram below.

Programming the Keypad Control using an CloudX M633 Board 

#include <CloudX\Keypad.h>
#include <CloudX\LCD.h>

#define NumberOfRows  4            // set display to four rows
#define NumberOfColumns  4            // set display to three columns
#define redLed  15
#define greenLed 16


char  KeypadCharacters[NumberOfRows][NumberOfColumns] = {
        '1','2','3','A',
        '4','5','6','B',
        '7','8','9','C',
        '*','0','#','D'
    };

char RowPins[NumberOfRows] = {7, 8, 9, 10};
char ColumnsPins[NumberOfColumns] = {11, 12, 13, 14};
signed char times=0;
char Keys , mask , i;
char Code[4] = {0,0,0,0};
char Attempt[4] = {0,0,0,0} ;


greenPrompt(){
        digitalWrite(redLed , LOW);
        digitalWrite(greenLed , HIGH);
}
redPrompt(){
        digitalWrite(redLed , HIGH);
        digitalWrite(greenLed , LOW);
}
optionPrompt(){
        LCD_cmd(clear);
        LCD_writeText(1,1,"A TO CHANGE PIN");
        LCD_writeText(2,1,"B TO ENTER PIN");
}
earlyCheckPrompt(){
        LCD_cmd(clear);
        LCD_writeText(1,1, "PIN NOT COMPLETE");
        LCD_writeText(2,1, "   TRY AGAIN    ");
}

checkPassword(){
char Check=0;

    for (i = 0; i < 4 ; i++ )
     if (Attempt[i]==Code[i]) Check++ ;

     if (Check == 4) {
        LCD_cmd(clear);
        LCD_writeText(1,1, " ACCESS GRANTED ");
        digitalWrite(redLed , LOW);
        digitalWrite(greenLed , HIGH);
        delayMs(3000);
        LCD_cmd(clear);
        LCD_writeText(1,1,"A TO CHANGE PIN");
        LCD_writeText(2,1,"B TO ENTER PIN");
        digitalWrite(redLed , HIGH);
        digitalWrite(greenLed , LOW);
     }

     else {
        LCD_cmd(clear);
        LCD_writeText(1,1, "  ACCESS DENIED ");
        digitalWrite(redLed , HIGH);
        digitalWrite(greenLed , LOW);
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, "    ENTER PIN   ");
        times=0;
     }

    for (i=0; i<4; i++) Attempt[i]=0;
        Keys=0;
}


checkOldPassword(){
 char Check=0;

 for (i = 0; i < 4 ; i++ ) {
 if (Attempt[i]==Code[i]) Check++ ;
 }

 if (Check == 4) {
     Keys=0;
     times=0;
     for (i=0; i<4; i++) Attempt[i] = Code[i] = 0;
     digitalWrite(redLed , LOW);
     digitalWrite(greenLed , HIGH);
     LCD_cmd(clear);
     LCD_writeText(1,1, "  ENTER NEW PIN ");


 while(times<4) {
     while(Keys==0)Keys= Keypad_getKey();
     if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        if(times<0)times=0;
     }

     else if(Keys=='#' && times != 4 ){
        Keys=0;
        times=0;
        LCD_cmd(clear);
        LCD_writeText(1,1, "PIN NOT COMPLETE");
        LCD_writeText(2,1, "   TRY AGAIN    ");
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, "  ENTER NEW PIN ");
     }

     else{
        mask = Keys - (Keys-42);
        LCD_write(2,times+1, mask );
        Code[times] = Keys;
        Keys=0;
        times++;

     if(times==4){
         LCD_writeText(1,1, "     PRESS #    ");
    while(Keys!='#'&& Keys!='*') Keys=getKey();
     if(Keys=='#'){
         LCD_cmd(clear);
         LCD_writeText(1,1, "  PIN CHANGED   ");
         LCD_writeText(2,1, "  SUCCESSFULLY  ");
         digitalWrite(redLed , LOW);
         digitalWrite(greenLed , HIGH);
         delayMs(2000);
         LCD_cmd(clear);
         LCD_writeText(1,1,"A TO CHANGE PIN");
         LCD_writeText(2,1,"B TO ENTER PIN");
         digitalWrite(redLed , HIGH);
         digitalWrite(greenLed , LOW);
     }

     if(Keys=='*'){
         Keys = 0;
         LCD_write(2,times,' ');
         times--;
         LCD_writeText(1,1, "  ENTER NEW PIN ");
     }
     }
     }
    }




 }


 else {
        LCD_cmd(clear);
        LCD_writeText(1,1, "   WRONG INPUT  ");
        LCD_writeText(2,1, "    TRY AGAIN   ");
        digitalWrite(redLed , HIGH);
        digitalWrite(greenLed , LOW);
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, "  ENTER OLD PIN ");
        times=0;
 }
for (i=0; i<4; i++) Attempt[i]=0;
        Keys=0;
}

setup(){
        Keypad_setting(PULLDOWNCOL, RowPins, ColumnsPins, NumberOfRows, NumberOfColumns, KeypadCharacters, 0);
        LCD_setting(1,2,3,4,5,6);
        pinMode(redLed , OUTPUT);
        pinMode(greenLed , OUTPUT);
        digitalWrite(redLed , HIGH);
        digitalWrite(greenLed , LOW);


        LCD_writeText(1,1, "     WELCOME    ");
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, "SECURITY  ACCESS");
        LCD_writeText(2,0, "     CONTROL    ");
        delayMs(1500);
        LCD_cmd(clear);


        LCD_writeText(1,1, " INPUT NEW PIN  ");

    while(times<4) {
        while(Keys==0)Keys= Keypad_getKey();
     if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        if(times<0) times=0;
     }

     else if(Keys=='#' && times != 4 ){
        Keys=0;
        times=0;
        LCD_cmd(clear);
        LCD_writeText(1,1, "PIN NOT COMPLETE");
        LCD_writeText(2,1, "   TRY AGAIN    ");
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, " INPUT NEW PIN ");
     }

     else{
        mask = Keys - (Keys-42);
        LCD_write(2,times+1, mask );
        Code[times] = Keys;
        Keys=0;
        times++;

     if(times==4){
         LCD_writeText(1,1, "     PRESS #    ");
         while(Keys!='#' &&  Keys!='*') Keys= Keypad_getKey();

        if(Keys=='#'){
        LCD_cmd(clear);
        LCD_writeText(1,1, " NEW PIN STORED ");
        LCD_writeText(2,1, "  SUCCESSFULLY  ");
        digitalWrite(redLed , LOW);
        digitalWrite(greenLed , HIGH);
        delayMs(2000);
        LCD_cmd(clear);
        LCD_writeText(1,1,"A TO CHANGE PIN");
        LCD_writeText(2,1,"B TO ENTER PIN");
        digitalWrite(redLed , HIGH);
        digitalWrite(greenLed , LOW);
     }
    if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        LCD_writeText(1,1, "  INPUT NEW PIN ");
     }

     }

     }

    }
        times=0;
        Keys=0;

loop(){

     while(Keys!='A' &&  Keys!='B') Keys= Keypad_getKey();

       if(Keys == 'A' ){
        Keys=0;
        LCD_cmd(clear);
        LCD_writeText(1,1, "  ENTER OLD PIN ");

     while(times<4) {
     while(Keys==0)Keys = Keypad_getKey();
     if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        if(times<0)times=0;
     }

     else if(Keys=='#' && times != 4 ){
        Keys=0;
        times=0;
        LCD_cmd(clear);
        LCD_writeText(1,1, "PIN NOT COMPLETE");
        LCD_writeText(2,1, "   TRY AGAIN    ");
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, "  ENTER OLD PIN ");
     }

     else{
        mask = Keys - (Keys-42);
        LCD_write(2,times+1, mask );
        Attempt[times] = Keys;
        Keys=0;
        times++;

     if(times==4){
         LCD_writeText(1,1, "     PRESS #    ");
     while(Keys!='#'&& Keys!='*') Keys= Keypad_getKey();
     if(Keys=='#'){
        checkOldPassword();
     }
     if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        LCD_writeText(1,1, "  ENTER OLD PIN ");
     }
     }
     }
    }
    }


    if(Keys == 'B' ){
    Keys=0;
    LCD_cmd(clear);
    LCD_writeText(1,1, "    ENTER PIN   ");

    while(times<4) {
        while(Keys==0)Keys= Keypad_getKey();
     if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        if(times<0)times=0;
     }

     else if(Keys=='#' && times != 4 ){
        Keys=0;
        times=0;
        LCD_cmd(clear);
        LCD_writeText(1,1, "PIN NOT COMPLETE");
        LCD_writeText(2,1, "   TRY AGAIN    ");
        delayMs(1500);
        LCD_cmd(clear);
        LCD_writeText(1,1, "    ENTER PIN   ");
     }

     else{
        mask = Keys - (Keys-42);
        LCD_write(2,times+1, mask );
        Attempt[times] = Keys;
        Keys=0;
        times++;

     if(times==4){
         LCD_writeText(1,1, "     PRESS #    ");
         while(Keys!='#'&& Keys!='*') Keys= Keypad_getKey();
     if(Keys=='#'){
        checkPassword();
     }
     if(Keys=='*'){
        Keys=0;
        LCD_write(2,times,' ');
        times--;
        LCD_writeText(1,1, "    ENTER PIN   ");
     }
     }
     }
    }
    }
    times=0;
    Keys=0;
}
}

 

Keypad Input and Access Control for Locks with LCD| Summary

So, there you go, we’ve built a keypad access control system. If you wanted to, you could further develop it to switch a relay from a pin output that would unlock an electric door lock when the correct code is entered.

I hope this tutorial was useful to you.

 

 

 

Share this with friends