User Tools

Site Tools


arduino:rfid_reader_id-12

RFID reader (ID-12) with Arduino

The RFID ID-12 is a simple reader that reads 125 kHz (EM 4001 or compatible) tags.

The datasheet provides data structure, wiring and pinout details. The reader outputs simple ASCII data in the following format:

I have made a simple Arduino sketch to use the ID-12 (or its larger ID-20 or smaller ID-2 siblings). It uses the NewSoftSerial Arduino library (website). There are some other examples on the Arduino Playground: ID12, ID12 with Tag Remove

Download the Arduino code: rfid_newsoftserial.zip

#include <NewSoftSerial.h>
 
NewSoftSerial rfidSerial(2, 3); // (RX, TX)
String myTag, myTagClean;
 
void setup(){
  Serial.begin(9600);
  Serial.println("Hello World : RFID reader, from hardware serial");
 
  // set the data rate for the NewSoftSerial port
  rfidSerial.begin(9600); // communication speed of ID-12 reader
  rfidSerial.println("Hello World : RFID reader, from software serial");
 
  // just some random println tests
  //Serial.println("lorem");
  //Serial.println(13, BYTE);
  //Serial.println("lorem");
 
}
 
void loop(){
 
  // read serial if available
  if (rfidSerial.available()) {
 
    // read and cast to char incoming data
    char incoming = (char)rfidSerial.read(); 
 
    //Serial.print("receiving " );
    //Serial.print(incoming);
    //Serial.print("  => ");
    //Serial.print(incoming, DEC);
    //Serial.println(' '); // Serial.print(10, BYTE);
 
    // packet structure, see ID-12 datasheet
    // STX A B C D E F G H I J CR LF ETX
    //   2 - - - - - - - - - - 13 10 3
 
    // if I read the final delimiter
    if(incoming == 3){
 
      Serial.println("Incoming Tag");
      //Serial.println(myTag);
      //Serial.println(myTag.length());
 
      // clean up String
      // we skip the first char, and take the following 12 chars
      myTagClean = myTag.substring(1, 13);
 
      // reset myTag
      myTag = "";      
 
      Serial.println(myTagClean);
      //Serial.println(myTagClean.length());
 
      // test and compare
      if(myTagClean == "13004C8ED302"){
        Serial.println("White Card"); 
      }
 
      if(myTagClean == "01023C245D46"){
        Serial.println("Keychain"); 
      }
 
    }
 
    // standard char, we add it to the String
    else{
      myTag = String (myTag + incoming);
    }
 
  }
 
}
arduino/rfid_reader_id-12.txt · Last modified: 2010/10/16 06:38 by 213.21.77.115