Study of RFID System
Study of RFID System
Objectives:
a. To understand the basic Pin-out structure of Arduino Uno Board.
b. To study the basics of RC522 RFID Reader/Writer module.
c. To write a Arduino Uno program for Accepting or Denying RFID Card with
interfacing its RFID Reader using Arduino.
1
Pin Connection for RFID and LCD:
Pins of RFID Module Pins of Arduino UNO
RST D9
SS (SDA) D10
MOSI D11
MISO D12
SCK D13
VCC +3.3V
(Already Connected)
GND GND
(Already Connected)
Pins of 16 X 2 C-LCD Module
LCD_D4 A0
LCD_D5 A1
LCD_D6 A2
LCD_D7 A3
LCD_EN A4
LCD_RS A5
LED D3
BUZZER D4
Procedure:
2
Program: Typical pin layout used:
#include<SPI.h>
#include<MFRC522.h>
#include<LiquidCrystal.h>
#define SS_PIN 10
#define RST_PIN 9
#define LCD_D4 A0
#define LCD_D5 A1
#define LCD_D6 A2
#define LCD_D7 A3
#define LCD_EN A4
#define LCD_RS A5
#define OK_LED 3
#define ERROR_BUZ 4
MFRC522::MIFARE_Key key; //Unique ID of RFID Tag, which you want to give access.
void setup()
pinMode(OK_LED, OUTPUT);
pinMode(ERROR_BUZ, OUTPUT);
digitalWrite(OK_LED, LOW);
digitalWrite(ERROR_BUZ,LOW);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("--FCT--");
delay(1000);
Serial.setTimeout(30);
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); //InitMFRC522
}
void loop()
{
//First Assume detected card (Or tag) is My_Card, Then later we will check is it
My_Card or not!
lcd.clear();
lcd.print("PutYourID-Card");
My_Card =true;
if(!rfid.PICC_IsNewCardPresent())
return;
if(!rfid.PICC_ReadCardSerial())
return;
MFRC522::PICC_TypepiccType=rfid.PICC_GetType(rfid.uid.sak);
if( piccType !=MFRC522::PICC_TYPE_MIFARE_MINI &&
piccType!=MFRC522::PICC_TYPE_MIFARE_1K&&
piccType!=MFRC522::PICC_TYPE_MIFARE_4K)
{
//Serial.println(F("YourtagisnotoftypeMIFAREClassic."));
return;
}
4
printHex(rfid.uid.uidByte,rfid.uid.size); //display card number on serial monitor
Serial.println();
delay(500);
//If RFID Tag is My_Card then give access to enter into classroom else don’t open
the door.
if(My_Card)
{
Serial.println("\nWelcome To Class Room ");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("WelcometoClass");
lcd.setCursor(0, 1);
lcd.print("AccessGranted");
delay(1000); //Turn on the Green LED as an indication of permission is given to access
the classroom.
digitalWrite(ERROR_BUZ,LOW);
digitalWrite(OK_LED, HIGH);
delay(1000);
digitalWrite(OK_LED, LOW);
}
else
{
Serial.println("\nDon't enterintheClassRoom");
lcd.clear();
lcd.print("CardNOTFOUND!");
lcd.setCursor(0, 1);
lcd.print("AccessDenied");
delay(1500);
digitalWrite(OK_LED, LOW);
5
digitalWrite(ERROR_BUZ,HIGH);
delay(1500);
digitalWrite(ERROR_BUZ,LOW);
}
// Halt PICC
rfid.PICC_HaltA();
//Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
/* Helper routine to dump a byte array as hex values to Serial. */
void printHex(byte*buffer,bytebufferSize)
{
lastSent= "";
for (byte i = 0; i<bufferSize; i++)
{
byte n1 = (buffer[i] >> 4) & 0x0F;
byten2=buffer[i] & 0x0F;
lastSent += n1 < 10 ? '0' + n1: 'A' + (n1-10);
lastSent += n2 < 10 ? '0' + n2: 'A' +(n2 -10);
Serial.print(buffer[i]<0x10?"0":"");
Serial.print(buffer[i],HEX);
}
}
Steps to execute Program
1. Make connections as given above.
2. Open „rfidsys.ino‟ file in Arduino IDE
3. Compile and upload the program.