Guide for using RFID Module with Arduino

f5mgyuriggyflk2-medium

Radio Frequency Identification or RFID is a wireless system that uses electromagnetic fields to transmit data from one object to another, without the two objects touching. You might have used RFID cards before or seen its implementation ( Ex- Metro Stations ). There are various kinds of RFID tags available like the one shown below.

basiccard-keyfobs

Note : Most of the Card Readers operate at a frequency of 125kHz. Basically, the RFID Protocol includes two low frequency bands at 125kHz and 134.2KHz and high frequency at 13.56MHz.

rfid-tag-manufacturer

Overview

  • RFID Tags : As explained, RFID Tags / Cards send out short-range radio signals which are picked up by an RFID Reader. RFID Tags can either be Active, Passive, Battery-Assisted Passive. An Active tag has an board battery and then transmits its signal. A Battery Assisted Passive Tag has an on board battery but gets active in the vicinity of an RFID Reader. A Passive Tag has no battery uses radio energy transmitted by the reader. They aare powered by the energy from an electromagnetic field produced by the RFID Reader. This field is transmitted by a fine coil of wire, which also acts as the antenna for the transmission of data between the Card and the Reader. Inside an RFID Tag is a tiny integrated circuit that can be accessed by a specialized Reader.

Parts Required

  1.  Arduino UNO
  2.  Jumper Wires
  3.  RIFD Tags
  4.  RFID Reader

Pin Wiring

Sensor Pin          Arduino Pin

  VCC                  5V
  GND                 GND
  RX                   D0
  TX                   D1

Note : Remove the Rx and Tx pins when uploading the code.

Testing the RFID Module

int dataq = 0;

void setup()
 {
    Serial.begin(9600); // Baud Rate : 9600 ( Bits / sec )
 }

void loop()
{
  if(Serial.available()>0) // Checks for the characters available in the receive buffer to read
   {
      dataq = Serial.read(); // Read the Data
      Serial.print("  ");
      Serial.print(dataq,DEC);
   }
}

Open the Serial Monitor and place the Card ( or place it near the Reader ) on the Reader and there you go! It will display your card number which is unique ID of a particular Tag.

Accepting or Rejecting a Card

Now when we know how to use the RFID Module and Tag, let us make a simple RFID System. If you place the correct card, then only the Reader would accept it or else it would be rejected.

int dataq = 0;
int ot= -1;
int tag1[12]= { X,X,X,X,X,X,X,X,X,X,X,X }; // Place your Card Number here
int tag2[12]= { }; // I left it blank but you can insert another Card Number
int newtag[12]= {0,0,0,0,0,0,0,0,0,0,0,0};

void setup()
{
  Serial.flush(); // Serial.read() reads the data at the front of the queue and Serial.flush clears the entire queue
  Serial.begin(9600);
}

boolean comparetag(int aa[12], int bb[12]) // Compares the tag with tag read
{
  boolean ff= false;
  int fg=0;
  for(int cc=0;cc<12;cc++)
   {
      if(aa[cc]==bb[cc])
       {
         fg++;
       }
    }
      if(fg==12)
       {
         ff= true;
       }
      return ff;
}

void checkmytags()
{
  ot= 0;
  if(comparetag(newtag,tag1)== true)
   {
     ot++;
   }
}

void loop()
{
  ot= -1;
  if(Serial.available()>0) // If there is a read
   {
     delay(100); // Time for the data to come in
     for(int z=0;z<12;z++)
      {
        dataq= Serial.read();
        newtag[z]= dataq;
      }
   Serial.flush();
   checkmytags();
}

if(ot>0) // If matches
{
  Serial.println("Card Accepted!");
  ot=-1;
}
else if(ot==0) // If no match
{
  Serial.println("It is a cruel World, Card Rejected!");
  ot= -1;
}
}

The System Can Be Hacked

Usually the RFID’s are encrypted but if you find an RFID which is not encrypted then in that case you can try a hack :

  • The RFID Tags convert the Card Number into Hexadecimal, then send it over.
  • Take an Active RFID Receiver in the vicinity of any card ( say ID Card )
  • You need to go near a person with the Receiver in your pocket to note down the card number.
  • The Receiver will automatically catch the Card Number of the RFID Tag.
  • Convert the Number into Hexadecimal.
  • You also need to be sure of the frequency at which the card operates. You can check the lock system to find a label with the frequency given.
  • Make a Radio Oscillator of the same frequency and transmit the hexadecimal data to break the lock.

Nowdays, most of the RFID’s are encrypted which makes it very difficult to be hacked.

 Applications

  • Logistics and Supply Chain.
  • Inventory Trackin.
  • Security Systems.
  • Access Control
  • Materials Management, etc.
  • Well, Laundromat ?

 

I hope you found the guide useful. If you have any questions, feel free to ask.

Saumitra Kapoor

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Leave a Reply

Bitnami