Code for using the Arduino with the Parallax RFID reader

  • NOTE: This page is for use ONLY with the blue, read-only Parallax RFID reader (model # 28140). For help with the new, black, read/write module (model # 28440), please visit its page

This code lets the Arduino read the Parallax brand RFID reader. Once connected and programmed, prints the tag number in the serial monitor window. Note that the serial monitor window runs at an astonishing 2400 baud, so make sure you have your seat belt buckled!

Four easy hardware connections:

  • Arduino RX to RFID TX
  • Arduino GND to RFID GND
  • Arduino Digital pin 2 to RFID enable
  • Arduino +5V to RFID Vcc pin.

// RFID reader for Arduino 
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> 
// Modified for Arduino by djmatic


int  val = 0; 
char code[10]; 
int bytesread = 0; 

void setup() { 

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


 void loop() { 

  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 
        Serial.print("TAG code is: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code 
      } 
      bytesread = 0; 
      digitalWrite(2, HIGH);                  // deactivate the RFID reader for a moment so it will not flood
           delay(1500);                       // wait for a bit 
           digitalWrite(2, LOW);                  // Activate the RFID reader
    } 
  } 
} 

// extra stuff
// digitalWrite(2, HIGH);             // deactivate RFID reader 




another case using SoftwareSerial rxPin=8

  • Arduino Digital pin 8 to RFID TX
  • Arduino GND to RFID GND
  • Arduino Digital pin 2 to RFID enable
  • Arduino +5V to RFID Vcc pin.

// Modified by Worapoht K.
#include <SoftwareSerial.h>

int  val = 0; 
char code[10]; 
int bytesread = 0; 

#define rxPin 8
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8

void setup()
{ 
  Serial.begin(2400);  // Hardware serial for Monitor 2400bps

  pinMode(2,OUTPUT);       // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(2, LOW);    // Activate the RFID reader 
}


void loop()
{ 
  SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); 
  RFID.begin(2400);

  if((val = RFID.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = RFID.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 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code 
    }
    bytesread = 0; 
    delay(500);                       // wait for a second
  } 
} 




The Parallax 28140 RFID Reader and operation with Arduino C++...

I have tried to use the Parallax RFID Reader with both Basic Stamp, PIC Basic Pro, and Arduino C++ code.

I have several 125kHz Tags with known, 10-digit codes; three "credit card" style tags, one "round World Tag" tag, and two "key fob" style tags.

These tags have actual printed 10-digit decimal numbers on them, but when used with the Basic Stamp, PIC Basic Pro, or Arduino C++ code, produce hexadecimal garbage results as indicated in the list below:

	DECIMAL		HEXIDECIMAL
	0009238622		6F008CF85E
	0009213929		6F008C97E9
	0363842563		0415AFCC03
	0004350367		010042619F
	0004089722		01003E677A
	0050598842		0F030413BA

I have a cheap Chinese USB connected RFID Reader which correctly reads the 10-digit decimal codes from these tags.

Looking at the bottom of the Chinese unit, I found a code 8H10D-1. Researching this code led me to the information on the 8H10D output format described below.

The Unique ID(UID) from the tag is converted using the 8H10D conversion rule from Hexidecimal to Decimal.

For Example:

Original Tag UID (HEX): 10 00 62 D9 B2

The 8H10D rule says take the last eight hexadecimal digits, 00 62 D9 B2, and convert it to a maximum 10 decimal digits.

Hexadecimal 0062D9B2 = Decimal 6478258

So its 8H10D format is: 0006478258

With this in mind, I modified the Arduino RFID software to meet the 8HD10 format as shown below:

// RFID reader for Arduino 
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> 
// Modified for Arduino by djmatic
//Modified 1-12-2015 to produce the correct tag number by M. Robertson

int  val = 0; 
char code[10]; 
int bytesread = 0; 
int i = 0;
int myNum[10];
unsigned long int multArray[] = {1,1,268435456,16777216,1048576,
65536,4096,256,16,1};
unsigned long int trueTag = 0;

void setup() { 

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


 void loop() { 

  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 
        code[0] = 48;			 //Zero out the first two elements of the code array
        code[1] = 48;
        //Cycle through the code array and create int elements in myNum
 for(i=0;i<10;i++)
 {
 if(code[i] == '0')		//I am not a programmer, but this is the only way I could
  myNum[i] = 0;
 else if(code[i] == '1')      //find to convert elements of a char array to ints...
  myNum[i] = 1;
 else if(code[i] == '2')
  myNum[i] = 2; 
 else if(code[i] == '3')
  myNum[i] = 3;  
 else if(code[i] == '4')
  myNum[i] = 4;  
 else if(code[i] == '5')
  myNum[i] = 5;  
 else if(code[i] == '6')
  myNum[i] = 6;  
 else if(code[i] == '7')
  myNum[i] = 7;  
 else if(code[i] == '8')
  myNum[i] = 8;  
 else if(code[i] == '9')
  myNum[i] = 9;
else if(code[i] == 'A')
  myNum[i] = 10;
else if(code[i] == 'B')
  myNum[i] = 11;
else if(code[i] == 'C')
  myNum[i] = 12;
else if(code[i] == 'D')
  myNum[i] = 13;
else if(code[i] == 'E')
  myNum[i] = 14;
else if(code[i] == 'F')
  myNum[i] = 15;
else
  myNum[i] = 9999;		//Oops! an error 
 }
 				//With trueTag initialized to 0, create the true tag number by summing trueTag with each element of the
				//integer myNum array multiplied by the corresponding element of the multArray.
for(i=0;i<10;i++)
{
 trueTag = trueTag + (myNum[i]*multArray[i]);
}
 Serial.print("TAG = ");    //print real TAG number
  Serial.println(trueTag); 
      } 
      bytesread = 0; 
      trueTag = 0;			      //Zero out trueTag for next iteration of the loop	
      digitalWrite(2, HIGH);                  // deactivate the RFID reader for a moment so it will not flood
           delay(1500);                       // wait for a bit 
           digitalWrite(2, LOW);                  // Activate the RFID reader
    } 
  } 
} 

// extra stuff
// digitalWrite(2, HIGH);             // dea

A more compact version of the above, based on Worapoht's SoftwareSerial rxPin=8 version. This uses the strtol function to do the conversion from hexadecimal. — Joseph Chapman?

  • Arduino Digital pin 8 to RFID TX
  • Arduino GND to RFID GND
  • Arduino Digital pin 2 to RFID enable
  • Arduino +5V to RFID Vcc pin
// RFID reader for Arduino 
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> 
// Modified for Arduino by djmatic, further modified by Worapoht K.
//Modified to produce the correct tag number by M. Robertson, refactored by J. Chapman
#include <SoftwareSerial.h>

int  val = 0; 
char code[11]; 
int bytesread = 0;
long decval = 0;

#define rxPin 8
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8

void setup()
{ 
  Serial.begin(2400);  // Hardware serial for Monitor 2400bps

  pinMode(2,OUTPUT);       // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(2, LOW);    // Activate the RFID reader 
}

void loop()
{ 
  SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); 
  RFID.begin(2400);

  if((val = RFID.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = RFID.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  
    }
    code[10] = 0;                 // NULL terminate 

    if(bytesread == 10)
    {  // if 10 digit read is complete 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code

      // Values printed on some tags are decimal with the first
      // byte omitted.
      decval = strtol(&code[2], 0, 16);
      Serial.print("Decimal code is: ");
      Serial.println(decval, DEC);
    }
    bytesread = 0; 
    delay(500);                       // wait for a second
  } 
} 

Share