Reading RFID tags

From Mech
Jump to: navigation, search

Contents

Overview

Image from Parallax.

Radio Frequency Identification (RFID) is a generic term used to describe technology that uses radio waves to identify objects via transponder tags. The tags emit a radio frequency that is a unique serial code which is its identification code. This is read by an RFID reader. Active RFID transponders contain their own battery supply which allows a constant signal, but they are bulky and expensive, therefore they are usually restricted to larger objects such as crates for shipping supplies. With passive RFID transponders, the RFID reader emits a radio frequency which causes a coiled antenna in the RFID transponder tag to generate a magnetic field which powers the RFID transponder. This generated power allows the RFID transponder tag to emit its specific radio frequency to the reader which it uses to identify the tag. The passive tags are cheaper then active tags, and require no power unlike the active tags.


The mechatronics lab uses the Parallax RFID Card Reader, Serial (#28140) and kit [1]. The reader reads passive RFID transponder tags up to 4 inches away from the reader. The RFID communicates using rs232 and transmits a 12-byte ASCII string. The first byte (start byte) is always $0A and the last byte (stop byte) is always $0D. These bytes are represented as characters not integers. The 10 middle digits are the 10 unique id digits that are unique to every RFID transponder. It outputs at a baud rate of 2400.

Note: The PIC waits for an RF signal and will not proceed until a tag is placed within reading range. For a more extensive summary on how RFID in general works, see the How Stuff Works page on RFID tags.


Circuit

Rfid diag.jpg
Rfid cirt.jpg

It is very simple to connect the RFID reader to the PIC. All you need to do is plug the RFID reader into your breadboard and then connect the inputs to the RFID reader to the PIC. In our example we powered our RFID reader off the PIC, so we connected the VCC to the +5 on the PIC and the GND to the ground on the PIC. The RFID reader needs to be powered by a 5V source. Its specified limits on input voltage are 4.5V to 5.5V. The RFID reader is enabled when the /ENABLE pin is set to ground, and not enabled when it is set to 5V. A red light turns on when it is enabled, and a green light turns on when it is not enabled. When the RFID read is idle, it uses 10mA of current, while when it is active, it uses 100mA of current.

We used the TTL-232R cord to output the RFID tag from the PIC to the PC as a proof of concept for our setup. For more details on how the TTL-232R cord works, see the TTL-232R page.

  • As a way to check the RFID reader, it can be directly connected to the TTL-232R cord and read to the PC. Similar to above, the yellow wire of the TTL-232R cord connects to the SOUT of the RFID reader and the black wire goes to the common ground.




A summary of the connections:

RFID SOUT to PIC RC7
RFID VCC to PIC +5 
RFID GND to PIC GND
RFID /ENAMBLE to PIC RC7
PIC RC6 to TTL-232R Yellow Wire (note: this is output signal to view on PC)
PIC GND to TTL-232R Black Wire (note: this is connecting the grounds together)











Code

The following code reads in the RFID tag from the RFID Card Reader and then writes it out to a ps232 connection. In our tests we used a TTL-232R with a baud of 2400. This allows you to view the RFID unique ID on the computer. This code is a great way to check that your PIC is reading the RFID tag correctly, since it outputs the tag's unique ID to the computer. This issue with the code is that you have to click reset in between uses, and cannot run though a while loop.

/*
   RFID_Input.c James Cooper and Chris Ryan 2009-2-04
   Read in from RFID Card on pin RC7
   Write out RFID unique number on pin RC6
*/
#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT        
#use delay(clock=40000000)         // 40 MHz crystal on PCB
#use rs232(baud=2400, UART1)      // hardware UART; uses  RC6/TX and RC7/RX

int16 i;
char value[12];//12 values of tag ID

void main() {
     output_low(PIN_D7); //Set enable to low

     for (i=0; i<12; i++) { //read in the 12 values
           value[i]=getc();
     }
     printf("rfid# %c %c %c %c %c %c %c %c %c %c \r\n", value[1] value[2] value[3] value[4] value[5] value[6] value[7] value[8] value[9] value[10]); //display 10 unique id digits
}

In order to see how to read the printf output, please see the TTL-232R page. Be sure to use a baud rate of 2400 and not the baud rate used the example on that page.

Note: The values read in are characters, not integers, so be sure to take that into account in the coding. Also, the 10 unique id digits are value[1] through value[10]. Value[0] is the beginning character that always stays the same, and value[11] is the end character that always stays the same.

Additional Code

The following code is an example of the RFID value running repetitively, lighting a specific LED (D3, D4, D5, D6).

/*
   RFID_Input.c James Cooper and Chris Ryan 2009-2-11
   Read in from RFID Card on pin RC7
   Prints out lights to pins D3, D4, D5, and D6 depending on which RFID tag is near
*/
#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT        
#use delay(clock=40000000)         // 40 MHz crystal on PCB
#use rs232(baud=2400, UART1)      // hardware UART; uses  RC6/TX and RC7/RX

int16 i;
char value[12];//12 values of tag ID

void main() {
     output_low(PIN_D7); //Set enable to low

   while (true){
     for (i=0; i<12; i++) { //read in the 12 values
              value[i]=getc();
     }
     
     //light pin for if value matches RFID value for tag
     output_low(PIN_D6);
     output_low(PIN_D5);
     output_low(PIN_D4);
     output_low(PIN_D3);
     if(value[1]=='3' && value[2]=='6' && value[3]=='0' && value[4]=='0' && value[5]=='6' && value[6]=='2' && value[7]=='1' && value[8]=='0' && value[9]=='6' && value[10]=='9'){
     output_high(PIN_D6);
     }if(value[1]=='0' && value[2]=='4' && value[3]=='1' && value[4]=='5' && value[5]=='D' && value[6]=='9' && value[7]=='0' && value[8]=='4' && value[9]=='A' && value[10]=='0'){
     output_high(PIN_D5);
     }if(value[1]=='0' && value[2]=='4' && value[3]=='1' && value[4]=='6' && value[5]=='2' && value[6]=='C' && value[7]=='A' && value[8]=='1' && value[9]=='1' && value[10]=='2'){
     output_high(PIN_D4);
     }if(value[1]=='1' && value[2]=='7' && value[3]=='0' && value[4]=='0' && value[5]=='7' && value[6]=='D' && value[7]=='4' && value[8]=='0' && value[9]=='C' && value[10]=='5'){
     output_high(PIN_D3);
     }
   }
}

Further Reading

Product Website

Data Sheet

How Stuff Works page on RFID

Wikipedia RFID page

Privacy Concerns

Personal tools