Making your Arduino a RFID Reader with Parallax

When I got my first Ardunio, I was blown away with what the tiny board was capable of. First thing I did was work through a lot of labs and guides posted online to get familiar with the how it worked. After getting to know Ardunio, I think its time I take our relationship to the next level and get serious.

The motivation for purchasing an Ardunio in the first place was to put together some projects revolving around RFID and use those in my web applications in both input and output devices. This will be a learning process and I will try to document most of that on this here blog.

As they say, you have to walk before you run. So today, we will be starting with our RFID project from square one.

To get started, you will need the following items:

1. Arduino Uno R3 Qty 1
2. Parallax RFID Reader Qty 1
3. Wires Qty 4
4. USB Cable Qty 1

As far as the Parallax RFID reader is concerned, I recommend buying the sample pack. There are lots of different RFID tags out there and not all are cross compatiable. By getting the sample pack, you start out with a few tags you know for certain will work with your reader.

So far so good? Awesome, you are doing great. You know? I dont care what they say about you, in my book you are A-OK.

Next, we wire up out Parallax RFID Reader and Arduino following the diagram below. Its a whopping 4 wires, so if you cant handle this you should probably find a new hobby.

rfidarduino

Next we need to put some code in our Arduino. Ive found loads of different varaiations, but I found this to be the most reliable.

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

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

 void loop()
 {

  if(Serial.available() > 0)
  {
    // if data available from reader
    // check for header
    if((val = Serial.read()) == 10)
    {
      bytesread = 0;
      // read 10 digit code
      while(bytesread<10)       {         if( Serial.available() > 0)
        {
          val = Serial.read();
          // if header or stop bytes before the 10 digit reading
          if((val == 10)||(val == 13))
          {
            // stop reading
            break;
          }
          // add the digit
          code[bytesread] = val;
          // ready to read next digit
          bytesread++;
        }
      }
      // if 10 digit read is complete
      if(bytesread == 10)
      {
        // possibly a good TAG
        Serial.print("TAG: ");
        // print the TAG code
        Serial.println(code);
      }
      bytesread = 0;
      // deactivate the RFID reader for a moment so it will not flood
      digitalWrite(2, HIGH);
      // wait for a bit
      delay(1500);
      // Activate the RFID reader
      digitalWrite(2, LOW);
    }
  }
}

I am not sure if I am alone in this, but I came across an error when trying to upload that code to my Arduino. I found that If I disconnected the 5V and GND wires and then uploaded the code the error disappeared. I then reattached the wires and it was smooth sailing from there.

Now we are all done. Using the Arduino software, fire up the serial monitor then swipe a RFID tag in front of the reader. Using the code above you will show reads like so…

reader

Now, I know your thinking to yourself “Ben, this is all well and great but when are you going to show us how to make something useful?” Well, my answer to you would be “Hold your horses and stay tuned. There is much more to come.”

Advertisements

2 responses to “Making your Arduino a RFID Reader with Parallax

  1. hey why my parallex 28440 reader didn’t change its state from ideal mode to read mode or the led didn’t chage to red pleas i need a help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s