Enginursday - RFID technology

Radio-Frequency IDentification is a technology that allows machines to identify an object without touching it, or even without a clear line of sight. How does it work?

Favorited Favorite 0

Radio-Frequency IDentification (RFID) is technology that allows machines to identify an object without touching it, even without a clear line of sight. Furthermore, this technology can be used to identify several objects simultaneously. RFID can be found everywhere these days - anything from your cat to your car contains RFID technology. This post will cover how RFID works, some practical uses, and maybe even some example code for reading RFID data. Somehow I always end up on vacation when my post is due...

alt text

An RFID tag. Source: http://www.rfidworld.ca/

What is RFID?

RFID is a sort of umbrella term used to describe technology that uses radio waves to communicate. Generally, the data stored is in the form of a serial number. Many RFID tags, including ours, contain a 32-bit hexadecimal number. At its heart, the RFID card contains an antenna attached to a microchip. When the chip is properly powered, it transmits the serial number through the antenna, which is then read and decoded.

RFID tags come in lots of shapes and sizes. For hobbyists, the most common type of tags are known as active and passive tags. Active tags contain a power source used for transmission, whereas passive tags rely on the RFID reader to power the circuitry. Active tags generally cost more because of the added hardware required. However, because of this, active tags have a much greater range. Anywhere from 100 feet (30.5 meters) to 300 feet (100 meters) is possible, compared to maybe 20 feet (6 meters) with passive tags. Of course this is all depending on the tags and environmental factors. These tiny capsules have a range of only a few inches. Passive tags are often meant to be disposable.

The exact frequency the tags transmits at is variable and depends on its purpose. This is usually done to avoid interference with other electronics or RFID tags and readers in the vicinity. RFID systems can use a system found in the cellular world known as Time Division Multiple Access (TDMA) to make sure the wireless communication is handled properly.

alt text

An RFID chip for a pet. Source: How Stuff Works

Security Issues

Skimming: when someone uses an RFID reader to scan data from an RFID chip without the holder's knowledge. Eavesdropping: when someone reads the frequencies emitted from the RFID chip as it is scanned by a reader.

Right now, some credit cards have RFID technology built into them for fast and easy checkout. The buyer can simply tap their card on the scanner and complete the checkout. This is prone to some security issues, however. Skimmers can scan your card while it is in your wallet and steal valuable information. As a fix, some wallets have metal woven into them. This prevents a reader from powering the chip, preventing the code from being transmitted. You can read about that here. US passports also contain an RFID chip. The Department of Homeland Security insists that the e-passport is perfectly safe to use, and that proper precautions have been taken to ensure user confidentiality. For protection against skimming, the passports also contain a metallic anti-skimming device. When the e-passport is closed, it can't be scanned at all; when it's open, it can only be read by a scanner that is less than 4 inches (10 centimeters) away. To guard against eavesdropping, some areas where the passport is scanned are thoroughly covered and enclosed so that signals cannot be picked up beyond the RFID reader.

alt text

A credit card with RFID technology. Source: http://humnwallet.com/

Some Code

I've had awesome luck using this RFID module from Parallax. I've embedded it in things ranging from my car to my house door. Below is some code for this reader; maybe you'll find it useful.

char card[12] = {''8','3','1','7','5','7','2','A','8','3'};
char code[12];
int bytesread = 0;
int lockPin = 13; // Connect LED to pin 13
int rfidPin = 2; // RFID enable pin connected to digital pin 2
int val=0;

void setup() 
{
  Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
  pinMode(rfidPin,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
  pinMode(lockPin,OUTPUT); // Set lockPin to output
  digitalWrite(rfidPin, LOW); // Activate the RFID reader
}

void loop() 
{
  digitalWrite(rfidPin, LOW);

  if(Serial.available() > 0)    // if data available from reader
  {     

     if((val = Serial.read()) == 10)    // check for header
     {   
      bytesread = 0;
      while(bytesread<10)   // read 10 digit code
      {       

        if( Serial.available() > 0) 
        {
          val = Serial.read();

          if((val == 10)||(val == 13))  // if header or stop bytes before the 10 digit reading
            break;               // stop reading

          code[bytesread] = val;       // add the digit
          bytesread++;           // ready to read next digit
        }
      }
      if(bytesread >= 10)       // if 10 digit read is complete
      {       
        digitalWrite(rfidPin, HIGH);        // De-Activate the RFID reader

        if(strcmp(code, card) == 0) 
        {
          Serial.print("Code is accecpted: ");
          Serial.println(code);
          unlock();
        }
        else 
        {
          Serial.print(code);
          Serial.println(" is not valid!");
        }
      }
      bytesread = 0;
      delay(500);                // wait for a second
     }
  }
}

void unlock() 
{
  //do business here
}

The End

Alright, back to vacation for me. Do you have any cool RFID projects? Let's hear about them! Thanks for reading and have a good Thursday!


Comments 29 comments

  • aruisdante / about 11 years ago / 7

    Unless I'm being stupid, I'm pretty sure the C++ specification does not guarantee that the extra elements you've initialized in your arrays will be 0 / '\0' which is what you're relying on for your strcmp call to work. Maybe the Arduino compiler does something different, but that code definitely wouldn't be portable.

    • BurnerJeremy / about 11 years ago * / 2

      This is correct. Up-voting to possibly save someone a future debugging headache.

      A quick and easy way to insure initialization is like so: int someVals[5] = {}; //c++ only

    • BradLevy / about 11 years ago / 1

      Static data is initialized to zero in the C and C++ standards, before any explicit initializers are applied. It would certainly not hurt to include '\0' at the end of the card initializer constants, though. Also, it looks like there is an extraneous extra single quote before the first initializer in the code listing.

  • jma89 / about 11 years ago * / 5

    As someone who has delved deep into RFID and all that goes with it I feel obliged to post. First a couple basic notes:

    • RFID (particularly "low frequency" (LF) 125 kHz) is a minefield of encoding and formatting schemes. There are some very popular ones (HID and all their variants; EM4100 and all those variants), but there's no ISO-level standard defining any communication mechanism in this range. (At least none that I could find.)
    • Most 125 kHz (LF) cards broadcast all the time if they are energized. This means that if two cards are held side-by-side neither will be read. There is a way to figure out the values (I know one developer from ID-Innovations claims to have figured it out, but I haven't had contact with him in a couple years) but there isn't anything on the market that can read two at the same exact time. This does not hold true for the higher frequencies where cards tend to be smarter and don't just shout when they are powered up. (A wonderful expception to this in the 125 kHz range is the T5557. More on that later.)
    • Just because a reader and a card are both 125 kHz it does not mean that they will work together. While all the hardware might check out, the reader's firmware is often looking for a particular encoding, both in the wireless transmission (FSK, MSK, etc) and in the card's contents (Manchester is common). If they don't all match up then you won't get a read. (That's why you can't use any of the ID-2/12/20 series readers with an HID tag. There is, however, an ID-12HE available that can read both card types - The firmware has been expanded to expect both card types.)

    Here's a nifty page I found a while back that gives some more technical detail into how RFID works: http://www.priority1design.com.au/rfid_design.html

    On that same site there's a lot of nitty-gritty on EM4100-type cards, especially regarding their encoding: http://www.priority1design.com.au/em4100_protocol.html

    Here are some details on the T5557 Read/Write RFID Transponder: http://www.priority1design.com.au/t5557_rfid_transponder.html

    I've left a lot off since I'm getting to the end of my lunch break. If you have any questions reply to this comment and I'll try my best to either answer/explain or to point you in the right direction. (Hint: Yay Wikipedia!)

    • Member #491631 / about 11 years ago / 1

      Aloha jma89, Working on a project... have SNV-RFID tags.... any idea what it will take to copy/write this type of tag? Appreciate any help or information you may have.

    • ArtK / about 11 years ago / 1

      For RFID encoding standards one place to look is GS1 and not ISO. http://www.gs1.org/gsmp/kc/epcglobal/tds/tds_1_6-RatifiedStd-20110922.pdf That standard is mostly related to commerce. Things like product codes and serial numbers.

  • Related to RFID security, this is one of my favorite videos from Adam Savage from Mythbusters.

  • Member #419717 / about 11 years ago / 2

    As an avid swimmer, I have thought it would be cool to put a waterproof RFID tag on my swim goggles and have an arduino or other microcontroller count my laps and show my split times on a waterproof wall mounted display. Using RFID tags would allow multiple swimmers per lane to use the same display.

  • 172pilot / about 11 years ago / 2

    I used an arduino and the parallax serial RFID reader to make a cool garage door opener, and I have it reporting via Syslog to my splunk server whenever anything happens. I even have it set to close the garage door after 3 minutes if it was opened from the inside, to avoid coming home from a weeks vacation to an open garage door (happened once!)

    I use the Arduino EEPROM to store valid codes and descriptions, and even wrote code to add/delete cards via TELNET connection (WiFly)

    Next steps are to create a web page to monitor and open/close the garage (ironically, the arduino part of this is done, but my web skills are lacking!).. I'd be happy to upload it somewhere.. Never having had anything useful like this to share, I'm at a loss as to where to put it. Can anyone recommend somewhere?

    • We've been pushing all of our example code to our GitHub repositories. It allows anyone to download the files even without an account, but also allows others to send you improvements or point out possible bugs in your code.

      Edit: The Arduino forum is also a great place to post any code for any Arduino based project.

  • Member #602721 / about 10 years ago * / 1

    I also agree with aruisdante. You are absolutely right. Anyhow, you have made a great job. Thanks for sharing the nice information with us. Looking forward for another great post from your side.For Android related content you can check <a href="http://aandriodmobile.com"></a>. Thanks once again for this awesome article.

  • Member #155210 / about 11 years ago / 1

    Holy heck, Paul. Glad to see you're still alive. I hope you still have the arduino-infused ford fiesta.

    Sincerely, your friends from sdsmt robotics

  • Member #479168 / about 11 years ago * / 1

    Arduino RFID shield - Access Table for Doors & Log Table - ID-12 Innovation

    This is a tutorial to have a complete system for access with rfid tags, storing data on the cloud using dataino.it

    ciao

  • pma / about 11 years ago / 1

    I've developed an automated model railway control system which uses 125kHz RFID tags under locomotives to identify their running characteristics to the controllers. Allows me to tailor acceleration curves, and the DC waveform digitally to suit older and less reliable 3-pole motors as well as newer 5-pole ones.

  • Carbon-rod / about 11 years ago / 1

    I had an RFID tag implanted in my hand, I use to use it to start my old motorbike, http://www.youtube.com/watch?v=8OVSi8OdkKI I also use it for access control to my home as well as an automated electric side gate. Future projects include my hilux, however it is difficult and somewhat dangerous project so that might be a little further down the track.

  • PhilWheat / about 11 years ago / 1

    My favorite fun project was one where I took an ID-12 reader and a pair of XBee radios to make an auto-login system for my desktop computer. I put the ID-12 set to serial mode, and the XBees to be a wireless serial port under my desk chair seat. Then put my RFID card in my wallet. When I sat down, the system would transmit the ID to the desktop computer and if it was the correct ID, the computer would unlock. I later tweaked it to pick up the loss of "tag in range" signal from the reader to re-lock the system. Worked surprisingly well (while the batteries lasted.)

  • Member #466248 / about 11 years ago / 1

    I've been working on a system to automate pickup soccer games at an indoor facility. My demo works by issuing the players 125hz RFID cards or tokens which are read by ID20's. The system would be able to take money, set up teams and games, keep score, and bring in new players. It runs off of an old Ubuntu laptop and is coded with Python.

  • Mark Fickett / about 11 years ago / 1

    I made a pill tracker using the ID-12. The idea was to help my mom remember which pills (on various schedules) she'd already taken. The code is on github, and includes a very simple implementation for reading IDs from the ID-12 (using NewSoftSerial, so it doesn't conflict with the default serial).

  • TheRegnirps / about 11 years ago / 1

    "32 bit hexadecimal number". A minor thing, but does that mean 16 ASCII characters? Four times the memory needed for a 32 bit binary number?

  • burhanmz / about 11 years ago / 1

    "compared to maybe 20 feet (6 meters) with passive tags...", is there any retail product available to this claim?

    I haven't been able to find a single reader for passive tags that would read properly a tag off over even a meter stretch of distance. Do you stock any / or perhaps you'd put up a follow-up on this article and write a diy of increasing reading range.

    • Usually the long range readers are for inventory tracking. I used one of these in a previous life. They are fairly pricey as you have the hardware to push enough energy to reach tags at 20ft.

  • StowellCM / about 11 years ago / 1

    You guys should be plugging your ID20s ;) I have used both the Parallax and ID-20s sold here at Sparkfun. The Parallax can read a greater variety of tags but I have had serious range issues when hooking up to 3.7v lipos even when boosting to 5v. The ID20s are not nearly as picking and work great in my mobile project. The code on the tutorial page isn't the greatest but the Arduino playground has some great code to get an ID up and running. http://playground.arduino.cc/Code/ID12

  • jweather / about 11 years ago / 1

    We have a museum exhibit where iPads are placed in podiums while the user interacts with a video wall. Each iPad (provided by the museum for the exhibit) has an RFID tag inside the back of its case, and the podiums have the Parallax RFID modules built in. The user interacting with the video wall then has the ability to save items to the iPad, and the RFID allows the computer running the video wall to know which iPad is sitting on the podium so it can update the app on that iPad. Very seamless, and fun to prototype too. Adds some useful physical knowledge to the software world.

  • imJack / about 11 years ago / 1

    We've taken Paul hostage and we're not asking ransom! Mwah-ha-ha-haaaaaa... But if you offer a million bucks and housekeeper we might take it into serious consideration. (sorry Paul, Heather made me do it... you know how wanty she is.)

  • anwesender / about 11 years ago / 1

    The "These tiny capsule"-Link is broken.

  • R_Phoenix / about 11 years ago / 1

    I'm looking in to RFID to use on our Makerspace: Goshen_ entry door. This looks like a good start. Thanks for posting the info.

Related Posts

Recent Posts

Raspberry Pi SD Cards

Sweet as AI Pi

Tags


All Tags