RFID – ID-12 & ID-20

“Radio-frequency identification (RFID) is the use of an object (typically referred to as an RFID tag) applied to or incorporated into a product, animal, or person for the purpose of identification and tracking using radio waves.” http://en.wikipedia.org/wiki/Radio-frequency_identification

You can use RFID technology to identify individual objects or users in your projects. Each tag has its unique code that can be read by an RFID reader. The readers also interface quite easily with microcontrollers such as the Arduino.

This blender also used RFID technology to recognize the fruit.

Beat Blender #1 from Matti Niinimäki on Vimeo.

The ID Innovations ID-12 and ID-20 are simple to use RFID readers and the data they output can be easily read with an Arduino.

  • Input voltage 5V
  • Baud rate: 9600
  • Reading range: 12 cm (ID-12) 16 cm (ID-20)
  • Three data output formats – ASCII, Weigand26 or Magnetic Track
  • Supported tags: EM 4001 or compatible 125 kHz tags

The simplest way to connect these readers to an Arduino is to use the RFID Shield I’ve built out of one of the proto shields. It looks like this and should always have one of the ID-12 readers connected to it:

If you need a bigger range, you can unplug the reader and plug in the ID-20. The other side has 5 and the other 6 pins, so make sure you plug the reader the right way on the shield!

You can also build the circuit on a breadboard if the RFID shield is in use or you need to fit the reader in a smaller space. Here is the schematic (from http://slab.concordia.ca/2008/arduino/rfid/)

Arduino Code

/* From http://slab.concordia.ca/2008/arduino/rfid/
 * RFID reader ID-12 for Arduino http://www.arduino.cc/playground/Code/ID12
 * Based on code by http://people.interaction-ivrea.it/h.barragan and http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/
 * Checksum by http://www.martijnthe.nl/
 */

void setup()
{
  // Open Serial Port
  Serial.begin(9600);
}

void loop ()
{
  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(Serial.available() > 0)
  {
    // Check for the STX Header (02 ASCII Value)
    if((val = Serial.read()) == 2)
    {
      bytesread = 0;
      // Read the RFID 10 digit code & the 2 digit checksum
      while (bytesread < 12)       {         if( Serial.available() > 0)
        {
          val = Serial.read();
          // Check for ETX | STX | CR | LF
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02))
          {
            // Stop Reading - There is an Error.
            break;
          }

          // Convert Hex Tag ID
          if ((val >= '0') && (val <= '9'))          {             val = val - '0';          }          else if ((val >= 'A') && (val <= 'F'))          {             val = 10 + val - 'A';          }           // Every two hex-digits, add byte to code:           if (bytesread & 1 == 1)          {             // make some space for this hex-digit by             // shifting the previous hex-digit with 4 bits to the left:             code[bytesread >> 1] = (val | (tempbyte << 4));             if (bytesread >> 1 != 5)
            {
              // If we're at the checksum byte,
              // Calculate the checksum... (XOR) - Exclusive OR
              checksum ^= code[bytesread >> 1];
            };
          }
           else
          {
            tempbyte = val;
          };
          // ready to read next digit
          bytesread++;
        }
      }

      // Print
      if (bytesread == 12)
      {
        Serial.print("5-byte code: ");
        for (i=0; i<5; i++)
        {
          if (code[i] < 16) Serial.print("0");
          Serial.print(code[i], HEX);
          Serial.print(" ");
        }
        Serial.println();

        Serial.print("Checksum: ");
        Serial.print(code[5], HEX);
        Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
        Serial.println();
      }

      bytesread = 0;
    }
  }
}

Useful links

Sparkfun sells a handy USB board that lets you connect any of the ID-series readers easily to your computer. Check it out here.

Download the datasheet.