I’ve updated Arduino For Flash with Flash and Arduino code for the Parallax RFID reader and the Arduino Code for the Parallax RFID Reader with a new example that uses SoftwareSerial for RFID->Arduino communication. Enjoy…
Here’s some Arduino code that improves stability and fixes a couple of errors in the Arduino Playground code for the Parallax RFID reader. The second example uses SoftwareSerial which is handy if you don’t want to block the serial port (note that the wiring is slightly different).
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// Revised by Erik Sjodin <http://www.eriksjodin.net>
//Connect:
/*
* Arduino RX to RFID SOUT
* Arduino GND to RFID GND
* Arduino Digital pin 2 to RFID /ENABLE
* Arduino 5v to RFID VCC
*/
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); // initialise the reader with a reset cycle
delay(100);
digitalWrite(2, HIGH);
delay(100);
digitalWrite(2, LOW);
delay(100);
}
void loop() {
digitalWrite(2, LOW); // activate reader
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
}
}
digitalWrite(2, HIGH);
if(bytesread == 10) { // if 10 digit read is complete
//Serial.begin(115200); // transmit with 115200 bps
Serial.println(code); // print the TAG code
//Serial.begin(2400); // read with 2400 bps
}
Serial.flush();
delay(500); // wait for 500 millisecond
}
}
}
#include <SoftwareSerial.h>
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// Modified to use SoftwareSerial by Erik Sjodin <http://www.eriksjodin.net>
//Connect:
/*
* Arduino pin 3 to RFID SOUT
* Arduino GND to RFID GND
* Arduino Digital pin 2 to RFID /ENABLE
* Arduino 5v to RFID VCC
*/
int val = 0;
char code[10];
int bytesread = 0;
int rx=3;
int tx=4;
// set up a new serial port
SoftwareSerial rfidSerial = SoftwareSerial(rx, tx);
void setup() {
pinMode(rx, INPUT);
pinMode(tx, OUTPUT);
rfidSerial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
Serial.begin(115200);
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // initialise the reader with a reset cycle
delay(100);
digitalWrite(2, HIGH);
delay(100);
digitalWrite(2, LOW);
delay(100);
}
void loop() {
digitalWrite(2, LOW); // activate reader
if((val = rfidSerial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
val = rfidSerial.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
}
digitalWrite(2, HIGH);
if(bytesread == 10) { // if 10 digit read is complete
Serial.println(code); // print the TAG code
}
delay(500); // wait for 500 millisecond
}
}
The Parallax RFID reader is inexpensive and easy to hook up to an Arduino or Wiring board. It has four connectors which can be plugged right into a bread board and there is code for it available at the Arduino Playground. One thing that I really like about the reader is its small footprint. It is about the size of a playing card and just 2-7mm thick. The reading distance is dependent on the tags that are used, I got maximum distance of about six centimeters on the axis that is orthogonal to the reader and 2-3 cm on the parallel axis. A short reading distance can be a good or a bad thing depending on the application. If you like me want to identify a shoe with an embedded RFID tag when the wearer enters an area, then it’s a not so good thing. If you know of another inexpensive and easy to interface reader that has a greater reading distance I’d be very interested in hearing about it…
Update: I have posted some Arduino code that improves stability and fixes a couple of errors in the Arduino Playground code for the Parallax RFID reader.