Security System Using RFID and 8051 Microcontroller

Arduino Arduino RFID Projects

In this project we are further builing on out previous post Attendance System using RFID and we will build a more secure system that uses RFID (radio frequency identification and detection), 8051 controller and a security keypad. Again the count of attendance will be done by using a RFID system and keypad will be used to input password as a further security measure.

Equipment

Equipment used for this system is mentioned below.

  • RFID Reader and RFID Cards or tags
  • 8051 Microcontroller
  • 16×2 LCD Display
  • DC Motor L293D
  • Buzzer using BC547 NPN transistor
  • 4×4 matrix keypad

The working is pretty much self explanatory from the diagram mentioned below.

The reader section is basically an RFID reader system that is used for input via RFID cards or tags. This working is exactly similar to that of ATM machine reading ATM cards with a magnetic strip for identification.  The RFID reader does not has a very large range and one has to put card or tag pretty close to reader to start the reading process. In few models range can be enhanced via using different antennas.

We are also using a 4×4 matrix keypad for entering the password to the system. This will further enhance the security of the system overall.

8051 microcontroller is used as a control section for this system. It will receive input from RFID reader and display it on LCD for display purpose. The Driver section is present there to mange the opening of gate and a buzzer with a transistor for indications.

The authentication system works in two steps. In first step when a user scans RFID tag then it is compared with the pre-define value. If the value is matched then the system asks for the password by displaying the message the message on LCD display. At this point the user enters the password using the keypad. This password is then compared for authentication. If both steps are validated only then gate will be open otherwise access will be denied.

Code

 

/***********************************************************************
At the start we are including all the header fiels and define variables. Also we will define input and output pins.
***********************************************************************/

boolean flag = 0;
void setup()
{
pinMode(2,OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
Serial.begin(9600);

#include
#include
#include
#define lcdport P1

/***********************************************************************
This section define pins for keypad module.
After this we have created a function for delay.
***********************************************************************/

sbit col1=P0^0;
sbit col2=P0^1;
sbit col3=P0^2;
sbit col4=P0^3;
sbit row1=P0^4;
sbit row2=P0^5;
sbit row3=P0^6;
sbit row4=P0^7;

sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P1^2;

sbit m1=P2^4;
sbit m2=P2^5;
sbit buzzer=P3^1;

char i,rx_data[50];

char rfid[13],ch=0;

/***********************************************************************
for storing and comparing the password entered via keypad. As it has the length of 4 characters then it shows that the password will not be more then 4 digits.
***********************************************************************/

char pass[4];

/***********************************************************************
The most handy fucntion i.e. delay
***********************************************************************/

void delay(int itime)
{
int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}

void daten()
{
rs=1;
rw=0;
en=1;
delay(5);
en=0;
}

/***********************************************************************
This functin is to make use of LCD and initiliaze it.
***********************************************************************/

void lcddata(unsigned char ch)
{
lcdport=ch & 0xf0;
daten();
lcdport=(ch<<4) & 0xf0;
daten();
}

void cmden(void)
{
rs=0;
en=1;
delay(5);
en=0;
}

void lcdcmd(unsigned char ch)
{
lcdport=ch & 0xf0;
cmden();
lcdport=(ch<<4) & 0xf0;
cmden();
}

void lcdstring(char *str)
{
while(*str)
{
lcddata(*str);
str++;
}
}

void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x0e);
lcdcmd(0x01);
}

/***********************************************************************
In this function we have configured 9600bps baud rate at 11.0592MHz Crystal Frequency. This function is also responsible for receiving and monitoring the data in SBUF registers.
***********************************************************************/

void uart_init()
{
TMOD=0x20;
SCON=0x50; regis
TH1=0xfd;
TR1=1;
}
char rxdata()
{
while(!RI);
ch=SBUF;
RI=0;
return ch;
}

void keypad()
{
lcdcmd(1);
lcdstring(“Enter Ur Passkey”);
lcdcmd(0xc0);
i=0;
while(i<4)
{
col1=0;
col2=col3=col4=1;
if(!row1)
{
lcddata(‘1′);
pass[i++]=’1’;
while(!row1);
}

else if(!row2)
{
lcddata(‘4′);
pass[i++]=’4’;
while(!row2);
}

else if(!row3)
{
lcddata(‘7′);
pass[i++]=’7’;
while(!row3);
}

else if(!row4)
{
lcddata(‘*’);
pass[i++]=’*’;
while(!row4);
}

col2=0;
col1=col3=col4=1;
if(!row1)
{
lcddata(‘2′);
pass[i++]=’2’;
while(!row1);
}

else if(!row2)
{
lcddata(‘5′);
pass[i++]=’5’;
while(!row2);
}

else if(!row3)
{
lcddata(‘8′);
pass[i++]=’8’;
while(!row3);
}

else if(!row4)
{
lcddata(‘0′);
pass[i++]=’0’;
while(!row4);
}

col3=0;
col1=col2=col4=1;
if(!row1)
{
lcddata(‘3′);
pass[i++]=’3’;
while(!row1);
}

else if(!row2)
{
lcddata(‘6′);
pass[i++]=’6’;
while(!row2);
}

else if(!row3)
{
lcddata(‘9′);
pass[i++]=’9’;
while(!row3);
}

else if(!row4)
{
lcddata(‘#’);
pass[i++]=’#’;
while(!row4);
}

col4=0;
col1=col3=col2=1;
if(!row1)
{
lcddata(‘A’);
pass[i++]=’A’;
while(!row1);
}

else if(!row2)
{
lcddata(‘B’);
pass[i++]=’B’;
while(!row2);
}

else if(!row3)
{
lcddata(‘C’);
pass[i++]=’C’;
while(!row3);
}

else if(!row4)
{
lcddata(‘D’);
pass[i++]=’D’;
while(!row4);
}
}

}

void accept()
{
lcdcmd(1);
lcdstring(“Welcome”);
lcdcmd(192);
lcdstring(“Password Accept”);
delay(200);
}

void wrong()
{
buzzer=0;
lcdcmd(1);
lcdstring(“Wrong Passkey”);
lcdcmd(192);
lcdstring(“PLZ Try Again”);
delay(200);
buzzer=1;
}

void main()
{
buzzer=1;
uart_init();
lcd_init();
lcdstring(” RFID Based “);
lcdcmd(0xc0);
lcdstring(“Security system “);
delay(400);
while(1)
{
lcdcmd(1);
lcdstring(“Place Your Card:”);
lcdcmd(0xc0);
i=0;
for(i=0;i<12;i++)
rfid[i]=rxdata();
rfid[i]=’′;
lcdcmd(1);
lcdstring(“Your ID No. is:”);
lcdcmd(0xc0);
for(i=0;i<12;i++)
lcddata(rfid[i]);
delay(100);
if(strncmp(rfid,”160066A5EC39″,12)==0)
{
keypad();
if(strncmp(pass,”4201″,4)==0)
{
accept();
lcdcmd(1);
lcdstring(“Access Granted “);
lcdcmd(0xc0);
lcdstring(“Person1″);
m1=1;
m2=0;
delay(300);
m1=0;
m2=0;
delay(200);
m1=0;
m2=1;
delay(300);
m1=0;
m2=0;
}
else
wrong();
}

else if(strncmp(rfid,”160066BD7AB7″,12)==0)
{
keypad();
if(strncmp(pass,”4202”,4)==0)
{
accept();
lcdcmd(1);
lcdstring(“Access Granted “);
lcdcmd(0xc0);
lcdstring(“Person2″);
m1=1;
m2=0;
delay(300);
m1=0;
m2=0;
delay(200);
m1=0;
m2=1;
delay(300);
m1=0;
m2=0;
}
else
wrong();
}

else if(strncmp(rfid,”160066203060″,12)==0)
{
keypad();
if(strncmp(pass,”4203”,4)==0)
{
accept();
lcdcmd(1);
lcdstring(“Access Granted “);
lcdcmd(0xc0);
lcdstring(“Person3”);
m1=1;
m2=0;
delay(300);
m1=0;
m2=0;
delay(200);
m1=0;
m2=1;
delay(300);
m1=0;
m2=0;
}
else
wrong();
}

else
{
lcdcmd(1);
lcdstring(“Access Denied”);
buzzer=0;
delay(300);
buzzer=1;
}
}
}

 

RFID and Keypad Based Security System using 8051 Microcontroller

Leave comment for this post......