0% found this document useful (0 votes)
48 views

Code With Keypad Working

RFID CODE WITH KEYPAD

Uploaded by

abhaystp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Code With Keypad Working

RFID CODE WITH KEYPAD

Uploaded by

abhaystp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

#include <Keypad.

h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char attempt[6]={'0','0','0','0','0','0'}; // used for comparison


char tagA[] ="FF000B5B16B9";

// declaration of Tag ID

char tagB[]="FF000B6AF16F";

// declaration of Tag ID

char tagC[]="13004A1B8AC8";

// declaration of Tag ID

char tagD[]="FF000C0BD62E";

// declaration of Tag ID

char tagE[]="13004A889445";
int o=1;
int n=0; //for Tag A to check the correct password
int m=0;
int v=0; //for Tag B to check the correct password
int x=0; //for Tag C to check the correct password

char input[12];

// A variable to store the Tag ID being presented

int count = 0;
input[] character array
boolean flag = 0;

// A counter variable to navigate through the


// A variable to store the Tag match status

boolean flagB=0;
boolean flagC=0;

// A variable to store the Tag match status


// A variable to store the Tag match status

// initialize the library with the numbers of the interface pins

const byte ROWS = 4; //four rows


const byte COLS = 3; //three columns
char keys[ROWS][COLS] =
{
{
'1','2','3' }
,

{
'4','5','6' }
,
{
'7','8','9' }
,
{
'*','0','#' }
};
byte rowPins[ROWS] = {17, 16, 15, 14}; //connect to the row pinouts of the kp
byte colPins[COLS] = {10, 9, 8}; //connect to the column pinouts of the kp

Keypad kp = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char PA[6]={ '1','2','3','4','5','6'}; // our secret (!) number


char PB[6]={'9','8','7','6','5','4'};
char PC[6]={'1','2','3','7','8','9'};
int z=0;

void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(13,OUTPUT);
pinMode(7,OUTPUT);
Serial.begin(9600);
Monitor

// Initialise Serial Communication with the Serial

// set up the LCD's number of columns and rows:


lcd.begin(16, 2);

//screenwidth=16

// Print a message to the LCD.


lcd.setCursor(0,0);
lcd.print(" Good Afternoon");

screenheight=2

delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Employee");
lcd.setCursor(0,1);
lcd.print("ManagementSystem");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Please move");
lcd.setCursor(0,1);
lcd.print(" your tag below");
delay(1000);
}
void loop()
{
if(Serial.available())// Check if there is incoming data in the RFID Reader Serial
Buffer.
{
count = 0; // Reset the counter to zero
/* Keep reading Byte by Byte from the Buffer till the RFID Reader
Buffer is empty
or till 12 Bytes (the ID size of our Tag) is read */
while(Serial.available() && count < 12)
{
input[count] = Serial.read(); // Read 1 Byte of data and store
it in the input[] variable
count++; // increment counter
delay(10);

}
/* When the counter reaches 12 (the size of the ID) we stop and
compare each value

of the input[] to the corresponding stored value */


if(count == 12) //
{
count =0; // reset counter varibale to 0
flag = 1;
flagB=1;
flagC=1;
/* Iterate through each value and compare till either the 12
values are
all matching or till the first mistmatch occurs */
while(count<12 && flag !=0)
{
if(input[count]==tagA[count])
{
Serial.println("if condition");
flag = 1; // everytime the values match, we set the flag
variable to 1

}
else
{ Serial.println("else");
flag= 0;
}
/* if the ID values don't match, set flag variable to 0 and
stop comparing by exiting the while loop */

if(input[count]==tagB[count])
{
flagB = 1; // everytime the values match, we set the flag
variable to 2
}
else

{
flagB= 0;
}
/* if the ID values don't match, set flag variable to 0 and
stop comparing by exiting the while loop */

if(input[count]==tagC[count])
{
flagC = 1; // everytime the values match, we set the flag
variable to 2
}
else
{
flagC= 0;
}
/* if the ID values don't match, set flag variable to 0 and
stop comparing by exiting the while loop */
count++; // increment count
}//while
}
if(flag == 1) // If flag variable is 1, then it means the tags match
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Enter PIN:");
lcd.setCursor(0,1);
n=readKeypad(PA);
if(n==1)
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Welcome Ankit");

delay (1000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(3000);
digitalWrite(13, LOW); // turn the LED off (LOW is the voltage
level)
delay(3000);
goto abhay;
}
else
{
lcd.clear();
lcd.print("Entry denied");
}
}

else
{
if(flagB ==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Enter PIN:");
lcd.setCursor(0,1);
v=readKeypad(PB);
if(v==1)
{
lcd.print("Access Allowed");
lcd.setCursor(0,1);
lcd.print("Welcome Parth Tyagi ");
delay (2000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage
level)

delay(3000);
digitalWrite(13, LOW); // turn the LED off (LOW is the voltage
level)
delay(3000);
goto abhay;
}
}
else
{
if(flagC==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Enter PIN:");
lcd.setCursor(0,1);
x=readKeypad(PC);
if(x==1)
{
lcd.print("Access Allowed");
lcd.setCursor(0,1);
lcd.print("Welcome Abhay");
delay(1000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(3000);
digitalWrite(13, LOW); // turn the LED off (LOW is the voltage
level)
delay(3000);
goto abhay;
}
}
else
{

lcd.clear();
lcd.print("Access Denied");// Incorrect Tag Message
lcd.setCursor(0,1);
lcd.print("Tag is invalid");
delay(1000);
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(4000);
digitalWrite(7, LOW); // turn the LED on (HIGH is the voltage
level)
}
}
/* Fill the input variable array with a fixed value 'L' to overwrite
all values getting it empty for the next read cycle */
for(count=0; count<12; count++)
{
input[count]= 'L';
}
count = 0; // Reset counter variable
}
}
abhay:
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Please move");
lcd.setCursor(0,1);
lcd.print(" your tag below");
delay(1000);
}
int checkPIN(char at[])
{
int correct=0;
int i;

for ( i = 0; i < 6 ; i++ )


{

if (attempt[i]==at[i])
{
correct++;
}
}
int p=0;
if (correct==6)
{
p=1;
lcd.print("* Correct PIN *");
delay(1000);
lcd.clear();

}
else
{
lcd.print(" * Try again *");
delay(1000);
lcd.clear();
lcd.print(" Enter PIN...");
}

for (int zz=0; zz<6; zz++)


{
attempt[zz]='0';
}
return(p);
}

int readKeypad(char ar[])


{
int n;
int p=0;
while(p<=6){
Serial.println("Enter key");
char key='a';
while(1){
key = kp.getKey();
if(key){
Serial.println(key);
break;
}
}

if (key)
{
lcd.print("#");
delay(200);
attempt[z]=key;
z++;
switch(key)
{
case '*':
z=0;
allclear();
break;
case '#':
z=0;
delay(200); // for extra debounce
lcd.clear();
n=checkPIN(ar);

Serial.println("n is");
Serial.println(n);
break;
}
}
p++;
}//outermost while
return (n);
}
void allclear()
{
for(int q=0;q<6;q++)
{
attempt[q]='0';
}
}

You might also like