Connecting And Checking The RFID Sensor With Arduino

Introduction

 
In this blog, I am going to explain about connecting and checking the RFID sensor with Arduino. It will be used to tell the usage of the bar code and the senses in the serial monitor.
 
Parts Of Lists
  • Arduino Uno
  • RIFD Sensor
  • Barcode Things
  • Bread Board
  • Hook-Up Wires 
Connection
 
Connect the sensor to the Arduino board of the 06,05. It will be used to detect which type of things are there. It will be used to display the message in the Serial monitor. 
 
Programming
  1. #include <SoftwareSerial.h>    
  2.     
  3. #define ADD_TAG_CODE "210014DFE309"  //change this ID with your own card TAG    
  4. #define DEL_TAG_CODE "210014E2BD6A"  //change this ID with your own card TAG    
  5.     
  6. SoftwareSerial rfid = SoftwareSerial(5, 6);    
  7. String msg;    
  8. String ID ;  //string to store allowed cards    
  9.     
  10. void setup()      
  11. {    
  12.   Serial.begin(9600);    
  13.   Serial.println("Serial Ready");    
  14.     
  15.   rfid.begin(9600);    
  16.   Serial.println("RFID Ready");    
  17. }    
  18.     
  19. char c;    
  20.     
  21. void loop(){    
  22.       
  23.   while(rfid.available()>0){    
  24.     c=rfid.read();     
  25.     msg += c;    
  26.     Serial.println(msg);      
  27.     Serial.println(msg.length());    
  28.   }    
  29.   msg=msg.substring(1,13);    
  30.   if(msg.indexOf(ADD_TAG_CODE)>=0) add();     
  31.   else if(msg.indexOf(DEL_TAG_CODE)>=0) del();      
  32.   else if(msg.length()>10) verifica();    
  33.   msg="";    
  34.       
  35. }    
  36.     
  37. void add(){    
  38.   Serial.print("What TAG do you wanna grant access?: ");    
  39.   msg="";    
  40.   while(msg.length()<13){    
  41.     while(rfid.available()>0){    
  42.       c=rfid.read();     
  43.       msg += c;    
  44.     }    
  45.   }    
  46.   if(ID.indexOf(msg)>=0) {    
  47.     Serial.println("\nAccess already granted for this card.");    
  48.     msg="";    
  49.   }    
  50.   else{    
  51.     Serial.print("Card: ");    
  52.     Serial.println(msg);     
  53.     ID += msg;    
  54.     ID += ",";    
  55.     //Serial.print("ID: ");    
  56.    // Serial.println(ID);    
  57.     msg="";    
  58.     Serial.println("Access granted for this card.");    
  59.   }    
  60.     
  61. }    
  62.     
  63. void del(){    
  64.   msg="";    
  65.   Serial.print("What TAG do you wanna deny access?: ");    
  66.   while(msg.length()<13){    
  67.     while(rfid.available()>0){    
  68.       c=rfid.read();     
  69.       msg += c;    
  70.     }    
  71.   }    
  72.   msg=msg.substring(1,13);    
  73.   if(ID.indexOf(msg)>=0){    
  74.     Serial.println(msg);    
  75.     Serial.println("TAG found. Access for this card denied.");    
  76.     //ID.replace(card,"");    
  77.     int pos=ID.indexOf(msg);    
  78.     msg="";    
  79.     msg += ID.substring(0,pos);    
  80.     msg += ID.substring(pos+15,ID.length());    
  81.     ID="";    
  82.     ID += msg;    
  83.     //Serial.print("ID: ");    
  84.     //Serial.println(ID);    
  85.   } else Serial.println("\nTAG not found or already denied");    
  86.   msg="";    
  87. }    
  88.     
  89. void verifica(){    
  90.     msg=msg.substring(1,13);    
  91.     if(ID.indexOf(msg)>=0) Serial.println("Access granted.");    
  92.         
  93.     else Serial.println("Access denied.");    
  94. }   
     
Explanation
 
In this RFID sensor, it will be used to detect the message in the serial monitor. If the tags are found, they will send the message as "TAG FOUND"  and afterward, it will show as the "Access denied ".
 
Output
 
 
Figure1: Output