RFID based security system using AVR ATmega32 microcontroller

RFID-enabled-security-system

RFID technology brought a great revolution in our life as it simplifies the machine communication. RFID’s are used almost everywhere today Schools, hospitals, industries and much more. This article teaches you to build a simple RFID based security system using AVR microcontroller which is reliable and cost efficient. You gotta be familiar with working principle and interfacing RFID so kindly go through this ” How to interface RFID with AVR Microcontroller ” tutorial before proceeding with this project.

DESIGN OF RFID BASED SECURITY SYSTEM:

rfid-based-security-system-avr-microcontroller

 

This system uses a RFID reader module and RFID tags which uses serial communication UART for communication. This RFID module senses the 12 bit ID of the tag once it is brought within the range. The unique ID is then sent to the Microcontroller for further processing via UART protocol. Since the module operates at RS232 logic +25V to -25V , we need to use level converter IC MAX232 to convert the data to TTL logic for Microcontrollers.

Three Relays must be connected to the PORTB for activation of the doors, for simplicity of the schematic design only one relay was shown in the above diagram. You can ignore the MAX232 if you obtain data as TTL logic in RFID reader.

rfid-reader-module-tag

SCENARIO:

In this project school level security scenario was chosen to explain the working of this system. Here Each tags will allow you to through a corresponding security level. For example a professor (MASTER TAG) have access to all the rooms and floors in a school whereas student  (STUDENT TAG) only has access to classrooms and guest  have access  only to the lobby. Three Relays from PORTB was used as door activator for these rooms. .

I am having three  RFID TAG namely “MASTER” “STUDENT” “GUEST”. When MASTER TAG was used RFID READER , all three relays gets activated (i.e professor access  all rooms) , when STUDENT TAG was used only the relay to class room gets activated. Finally when Guest tag was used with RFID reader the relay to the lobby door only will get activated.

ALGORITHM:

  1. Initialize UART communication in the controller.
  2. Initialize scanning for any tags through RFID reader.
  3. Read the 12 byte RFID ID one by one through UART when any tag is placed.
  4. Match the ID with the existing records and seek for the security level of the corresponding ID.
  5. Activate the relay/door based on the security level.
  6. Wait for five seconds and deactivate the relay to prevent tail gating.

COMPONENTS USED:

  1. AVR Atmega32 microcontroller
  2. RFID reader module
  3. RFID TAG
  4. LCD module
  5. MAX232 circuit
  6. Jumper wires

CODE:

#include<avr/io.h>
#include
#include
void usartinit();
//unsigned char a;
unsigned char value[15];
unsigned int b;
unsigned int k=0,i=0,j,l;
unsigned char value1[]={"140071D1A612"};         //Predefined ID
unsigned char value2[]={"51005D6899FD"};

int main ()
{
 DDRC=0xFF;
 DDRB=0xFF;
 PORTB=0x00;
 usartinit();

 while(1)
 {
  while((UCSRA)&(1<<RXC))
{
value[i]=UDR;
_delay_ms(1);
i++;
if(i==12)
{
value[i]='';
for(j=0;value1[j]!='';j++)
{
if(value[j]==value1[j])
k++;
}
if(k==12)                           //Match with the predefined ID
{
PORTB|=(1<<0)|(1<<1)|(1<<2);        //Master have access to all rooms
_delay_ms(5000);
PORTB=0x00;
}
else
{
k=0;
for(j=0;value2[j]!='';j++)
{
if(value[j]==value2[j])
k++;
}
if(k==12)
{
PORTB|=(1<<1);                 //Student have access to class rooms only
_delay_ms(5000);
PORTB=0x00;
} 
else 
{ 
PORTB|=(1<<2);                //Guest have access to lobby only
_delay_ms(5000);
PORTB=0x00;
} } } } } } 
void usartinit() 
{ 
UBRRH=00; 
UBRRL=77; 
UCSRB|=(1<<RXEN); 
UCSRC|=(1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); 
}

 

WORKING VIDEO:

NOTE:

  • Three LED’s have been used instead of Relay (door activators) for simplicity of the circuit.
  • If your RFID reader provides the data in TTL logic eliminate the MAX232 part from the above design.
  • The school scenario is just used to illustrate the functioning of this security system.

Leave a Comment

Your email address will not be published. Required fields are marked *