Вы находитесь на странице: 1из 16

#include <Keypad.

h>
#include <LiquidCrystal.h>
#include <Time.h>
#include<DateTime.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //RX ,TX
LiquidCrystal lcd(12, 11, 5, 4, A4, A5);
char attempt[6]={
'0','0','0','0','0','0'};
// used for comparison
char qwerty[2]={
'0','0'};
//used for comparison
char salaryall[1]={
'1'};
//salary authorised array
char tagA[] ="FF000B5B16B9";
// declaration of Tag ID for
char tagB[]="FF000B6AF16F";
// declaration of Tag ID for
char tagC[]="13004A1B8AC8";
// declaration of Tag ID for
char tagD[]="FF000C0BD62E";
// declaration of Tag ID for
char tagE[]="13004A889445";
// declaration of Tag ID for

A
B
C
D
E

int matlabData=0;
//hours,minutes,seconds and milli-seconds declaration
float hA=0.0,maA=0.0,sA=0.0, msA=0.0;
float hB=0.0,maB=0.0,sB=0.0,msB=0.0;
float hC=0.0,maC=0.0,sC=0.0,msC=0.0;
//working dasys
float daysA=0,daysB=0,daysC=0;
//salary declaration for A,B and C
float salA=0;
float salarA=0;
float salaryA=0;
float salB=0;
float salarB=0;
float salaryB=0;
float salC=0;
float salarC=0;
float salaryC=0;
//Unsigned long range from 0 to 4,294,967,295 (2^32 - 1).
unsigned long overA, overC, overB;
unsigned long startA;
// declaration of start time for A
unsigned long finishedA;
// declaration of end time for A
unsigned long startB;
// declaration for start time for B
unsigned long finishedB;
// declaration of end time for B
unsigned long startC;
// declaration of start time for C
unsigned long finishedC;
// declaration of end time for C
unsigned long elapsedA;
// declaration of time difference for A
unsigned long elapsedB;
// declaration of time difference for B
unsigned long elapsedC;
// declaration of time difference for C
//exit flag declaration
boolean exA=0;
boolean exB=0;
boolean exC=0;

boolean flagA1=0;
boolean flagB1=0;
boolean flagC1=0;

//exit declaration for A


//exit declaration for B
//exit declaration for C

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
int l=0; // to read keypad for A
int j=0;
char input[12];
// A variable to store the Tag ID being presen
ted
int count = 0;
// A counter variable to navigate through the
input[] character array
boolean flag = 0;
// A variable to store the Tag match status
boolean flagB=0;
// A variable to store the Tag match status
boolean flagC=0;
// 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]={
'4','5','6','7','8','9'}; // 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()
{
mySerial.begin(9600);
Serial.begin(9600);// Initialise Serial Communication with the Serial Monitor
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//screenwidth=16
screenheight=2
//Setting Date and Time
DateTime.sync(DateTime.makeTime(30,50,13,28,2,2015));

//January is treated

as month 0
//For LED blink
pinMode(13,OUTPUT);
pinMode(7,OUTPUT);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print(" Good Evening");
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(2000);
}
void loop()
{
if(Serial.available()>0)
// Check if there is incoming data in the RFID Re
ader Serial Buffer.
{
Serial.println("");
lcd.clear();
// lcd.print("ABHAY KAPOOR");
matlabData=Serial.read();
lcd.setCursor(0,1);
lcd.print(matlabData);
delay(1000);
/* 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 */
}
if(mySerial.available())
if(matlabData==1)
{
while(mySerial.available() && count < 12)
{
input[count] = mySerial.read();// Read 1 Byte of data and store it in th
e input[] variable
count++; // increment counter
delay(11);
}//while ends
/* When the counter reaches 12 (the size of the ID) we stop and compare ea
ch 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 occu
rs */
while(count<12 )
{
if(input[count]==tagA[count] && exA==1)
flagA1 = 1; // everytime the values match, we set the flag variable
to 2
else
flagA1= 0;
if(input[count]==tagB[count] && exB==1)
flagB1 = 1; // everytime the values match, we set the flag variable
to 2
else
flagB1= 0;
if(input[count]==tagC[count] && exC==1)
flagC1 = 1; // everytime the values match, we set the flag variable
to 2
else
flagC1= 0;
if(input[count]==tagA[count] && exA==0)
flag = 1; // everytime the values match, we set the flag variable t
o 1
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] && exB==0)
flagB = 1; // everytime the values match, we set the flag variable t
o 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] && exC==0)
flagC = 1; // everytime the values match, we set the flag variable t
o 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);
int ak=0;
abhayA:
lcd.print(" Enter PIN:");
lcd.setCursor(0,1);
l=readKeypad(PA);
ak++;
if(l==1)
{
exA=1;
startA=millis();
delay(200);
lcd.print("Access Allowed");

lcd.setCursor(0,1);
lcd.print("Welcome Ankit");
delay (1000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage leve
l)
delay(1000);
digitalWrite(13,LOW);
goto abhay;
}
else
{
if(ak<2)
{
lcd.clear();
goto abhayA;
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Come Again ");
}
}
}
else
{
if(flagB ==1)
{
lcd.clear();
lcd.setCursor(0,0);
int ak=0;
abhayB:
lcd.print(" Enter PIN:");
lcd.setCursor(0,1);
v=readKeypad(PB);
ak++;
if(v==1)
{
exB=1;
startB=millis();
delay(200);
Serial.print("ENTRY PARTH TYAGI");
lcd.print("Access Allowed");
lcd.setCursor(0,1);
lcd.print("Welcome Parth Tyagi ");
delay (1000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage le
vel)
delay(1000);
digitalWrite(13,LOW);
goto abhay;
}
else
{
if(ak<2)
{
lcd.clear();
goto abhayB;

}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Come Again ");
}
}
}
else
{
if(flagC==1)
{
lcd.clear();
lcd.setCursor(0,0);
int ak=0;
abhayC:
lcd.print(" Enter PIN:");
lcd.setCursor(0,1);
x=readKeypad(PC);
ak++;
if(x==1)
{
exC=1;
startC=millis();
Serial.print("ENTRY ABHAY KAPOOR");
lcd.print("Access Allowed");
lcd.setCursor(0,1);
lcd.print("Welcome Abhay kapoor ");
delay (1000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(1000);
digitalWrite(13,LOW);
goto abhay;
}
else
{
if(ak<2)
{
lcd.clear();
goto abhayC;
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Come Again ");
}
}
}
else
if(flagA1==1)
{
finishedA=millis();
delay(10);
lcd.clear();
lcd.setCursor(0,0);
elapsedA=finishedA - startA;

delay(10);
//Serial.print(elapsedA);
salA=elapsedA;
salarA=salarA + salA;
salaryA=salarA*0.0001;
hA = int(elapsedA/ 3600000);
overA = elapsedA % 3600000;
maA = int(overA / 60000);
overA = overA % 60000;
sA = int(overA/ 1000);
msA = overA % 1000;
daysA=hA/24;
if(daysA>0)
{
lcd.print(daysA,0);
lcd.print("D ");
}
lcd.print(hA, 0);
lcd.print("h ");
lcd.print(maA, 0);
lcd.print("m ");
lcd.print(sA, 0);
lcd.print("s ");
lcd.print(msA, 0);
lcd.print("ms");
Serial.print(" , ");
Serial.print(hA, 0);
Serial.print("h ");
Serial.print(maA, 0);
Serial.print("m ");
Serial.print(sA, 0);
Serial.print("s ");
Serial.print(msA, 0);
Serial.print("ms");
delay(3000);
lcd.setCursor(0,0);
lcd.print(" Want to see your");
lcd.setCursor(0,1);
lcd.print(" salary ?");
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("1 (yes) 0 (No)");
int uy=0;
lcd.setCursor(0,1);
int mn=salaryKeypad(salaryall);
delay(20);
parthA:
if(mn==1)
{
delay(20);
lcd.print(" Enter Password :");
lcd.setCursor(0,1);
int op=readKeypad(PA);
uy++;
if(op==1)
{
lcd.clear();

lcd.setCursor(0,0);
lcd.print("Your Salary is");
lcd.setCursor(0,1);
lcd.print("Rs. ");
lcd.print(salaryA);
delay(1000);
}
else
{
if(uy<2)
{
lcd.clear();
goto parthA;
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Suceeded your");
lcd.setCursor(0,1);
lcd.print(" attempts !");
}
}
}
else
{
lcd.clear();
lcd.print(" Thank You");
lcd.setCursor(0,1);
lcd.print(" Exit");
delay(2000);
}
exA=0;
startA=0;
finishedA=0;
overA=0;
maA=0;
elapsedA=0;
sA=0;
msA=0;
hA=0;
delay(1000);
}
else
if(flagB1==1)
{
lcd.clear();
finishedB=millis();
lcd.clear();
lcd.setCursor(0,0);
elapsedB=finishedB-startB;
salB=elapsedB;
salarB=salarB + salB;
salaryB=salarB*0.0001;
hB = int(elapsedB/ 3600000);
overB = elapsedB % 3600000;

maB = int(overB / 60000);


overB = overB % 60000;
sB = int(overB / 1000);
msB = overB % 1000;
daysB=hB/24;
Serial.print("Exit Parth Tyagi");
if(daysB>0)
{
lcd.print(daysB,0);
lcd.print("D ");
}
lcd.print(hB, 0);
lcd.print("h ");
lcd.print(maB, 0);
lcd.print("m ");
lcd.print(sB, 0);
lcd.print("s ");
lcd.print(msB, 0);
lcd.print("ms");
delay(3000);
lcd.setCursor(0,0);
lcd.print(" Want to see your");
lcd.setCursor(0,1);
lcd.print(" salary ?");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("1 (yes) 0 (No)");
int uy=0;
lcd.setCursor(0,1);
int mn=salaryKeypad(salaryall);
delay(20);
parthB:
if(mn==1)
{
delay(20);
lcd.print(" Enter Password :");
lcd.setCursor(0,1);
int op=readKeypad(PB);
uy++;
if(op==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your Salary is");
lcd.setCursor(0,1);
lcd.print(salaryB);
delay(1000);
}
else
{
if(uy<3)
{
lcd.clear();
goto parthB;
}
else

{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Attempts Over");
lcd.setCursor(0,1);
lcd.print(" Thank You");
}
}
}
else
{
lcd.clear();
lcd.print(" Thank You");
lcd.setCursor(0,1);
lcd.print(" Exit");
delay(1000);
}
exB=0;
startB=0;
finishedB=0;
overB=0;
maB=0;
elapsedB=0;
sB=0;
msB=0;
hB=0;
}
else
if(flagC1==1)
{
finishedC=millis();
lcd.clear();
lcd.setCursor(0,0);
elapsedC=finishedC-startC;
salC=elapsedC;
salarC=salarC + salC;
salaryC=salarC*0.0001;
hC = int(elapsedC/ 3600000);
overC = elapsedC % 3600000;
maC = int(overC / 60000);
overC = overC % 60000;
sC = int(overC / 1000);
msC = overC % 1000;
daysC=hC/24;
if(daysC>0)
{
lcd.print(daysC,0);
lcd.print("D ");
}
lcd.print(hC, 0);
lcd.print("h ");
lcd.print(maC, 0);
lcd.print("m ");
lcd.print(sC, 0);
lcd.print("s ");
lcd.print(msC, 0);
lcd.print("ms");
delay(3000);

lcd.setCursor(0,0);
lcd.print(" Want to see your");
lcd.setCursor(0,1);
lcd.print(" salary ?");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("1 (yes) 0 (No)");
if(delay)
{
int uy=0;
lcd.setCursor(0,1);
int mn=salaryKeypad(salaryall);
delay(20);
parthC:
if(mn==1)
{
delay(20);
lcd.print(" Enter Password :");
lcd.setCursor(0,1);
int op=readKeypad(PC);
uy++;
if(op==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your Salary is");
lcd.setCursor(0,1);
lcd.print(salaryC);
delay(1000);
}
else
{
if(uy<3)
{
lcd.clear();
goto parthC;
}
else
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Attempts Over.");
lcd.setCursor(0,1);
lcd.print(" Thank You");
}
}
}
else
{
lcd.clear();
lcd.print(" Thank You");
lcd.setCursor(0,1);
lcd.print(" Exit");
delay(1000);
}
}

startC=0;
finishedC=0;
overC=0;
maC=0;
elapsedC=0;
sC=0;
msC=0;
hC=0;
exC=0;
delay(1000);
}
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 volta
ge level)
delay(2000);
digitalWrite(7, LOW);

// turn the LED on (HIGH is the voltag

e 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:
if(DateTime.available())
{
unsigned long prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
DateTime.available(); //refresh the Date and time properties
lcd.clear();
lcd.setCursor(0,0);
digitalClockDisplay( ); // update digital clock
digitaldateDisplay();
}
}
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
{
p=0;
lcd.setCursor(0,0);
lcd.print(" Thank You");
lcd.setCursor(0,1);
lcd.print(" Try again ");
delay(1000);
}
for (int zz=0; zz<6; zz++)
{
attempt[zz]='0';
}
return(p);
}
int readKeypad(char ar[])
{
int n=0;
int p=0;
while(p<=6)
{
//if(p==0)
//Serial.print("Enter key:");
char key='a';
while(1)
{
key = kp.getKey();
if(key)
{
//Serial.print("*");
break;
}
}
if (key)
{
lcd.print("*");
delay(300);
attempt[z]=key;
z++;
switch(key)
{
case '*':
z=0;
allclear();
p=6;
break;
case '#':
z=0;
delay(200); // for extra debounce

lcd.clear();
n=checkPIN(ar);
p=6;
break;
}
}
p++;
}//outermost while
return (n);
}
void allclear()
{
for(int q=0;q<6;q++)
{
attempt[q]='0';
}
}
void digitalClockDisplay()
{
lcd.home();
// display time on line 0
//print time:
lcd.print("Time ");
//print hour
lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}
void digitaldateDisplay()
{
lcd.home();
lcd.setCursor(0, 1);
int dayofweek=0,day=0;
day=(DateTime.DayofWeek);
dayofweek=day;
switch(dayofweek){
case 1:
lcd.print("Mon ");
break;
case 2:
lcd.print("Tues ");
break;
case 3:
lcd.print("Wed ");
break;
case 4:
lcd.print("Thurs ");
break;
case 5:
lcd.print("Fri ");
break;
case 6:
lcd.print("Sat ");
break;
case 0:
lcd.print("Sun ");

break;
}
lcd.print(DateTime.Day);
lcd.print("/");
lcd.print(DateTime.Month+1);
lcd.print("/");
lcd.print(DateTime.Year+1900);
}
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and lead
ing 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}
int checkpassword(char atty[])
{
int co=0;
int i;
for ( i = 0; i < 6 ; i++ )
{
if (qwerty[i]==atty[i])
{
co++;
}
}
int lk=0;
if (co==2)
{
lk=1;
lcd.print("

Got It!!");

delay(100);
lcd.clear();
}
else
{
lk=0;
}
for (int zzz=0; zzz<2; zzz++)
{
qwerty[zzz]='0';
}
return(lk);
}
int salaryKeypad(char salarypass[])
{
int gh;
int kl=0;
while(kl<2)
{
char key='c';
while(1)
{
key = kp.getKey();

if(key)
{
break;
}
}
if (key)
{
lcd.print("#");
delay(200);
qwerty[j]=key;
j++;
switch(key)
{
case '*':
j=0;
allclear();
kl=1;
break;
case '#':
j=0;
delay(200); // for extra debounce
lcd.clear();
gh=checkpassword(salarypass);
kl=1;
break;
}
}
kl++;
}//outermost while
return (gh);
}

Вам также может понравиться