Attempting to use RFID

Hi all,

This is my first attempt at working with RFID on arduino and I have a few questions to put out there. I am very new to arduino so if anyone has any suggestions I would greatly appreciate it!

I was given a box of old arduino stuff from a friend of mind and I found an RFID reader and a couple of tags. Obviously I became interested in seeing if I could get it to work and it has consumed me since I opened the box.

My question is pretty simple. Is there a way to read the tag ID numbers? I don't know them since they were just in a box with a bunch of other things. It seems that I need this number before I can make the RFID start to work for me.

I've searched around and found a great site that walks through a RFID project (gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/)
but I still seem to be having issues.

I've uploaded the code verbatim as written on the website and I have triple checked to make sure it is wired properly.

Thanks again!

-cgreen

What sort of RFID reader is it?
How does it output its data? It could be serial, wegand, or TTL

Without knowing this you just can't start.

Is there a way to read the tag ID numbers?

Yes that's what the RFID reader does.

Hi Mike,

Good questions, I should have thought to include that in my first post.

The reader is made by parallax and I am quite sure it uses serial data.

This is the website I found that at the parallax store that has all of its info:
http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/rfid/List/0/SortField/4/ProductID/114/Default.aspx

I'm glad you responded, thanks!

-cgreen

but I still seem to be having issues.

And those issues are secret? The Arduino Physic Network is closed for remodeling. Please try again later.

Hi Paul,

Nothing appears to happen once I upload the code. The "TX" indicator continuously flashes (which I understand means it is transmitting data), however I am unable to open my serial monitor in arduino. My arduino interface also seems to be stuck at "uploading to i/o board..."

Thanks if you can help!

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;
delay(500); // wait for a second
}
}
digitalWrite(2, HIGH); // deactivate RFID reader
}

I got the above code from the arduino playground.

Is anything attached to the Arduino when you try uploading the code? This, by the way, is a completely separate issue from your original post?

If there is anything attached, what pins does the stuff use?

Yes, there are other things attached. The arduino +5v is connected to parallax vcc. Arduino Ground to parallax ground. Digital pin 2 is connected to parallax /enable. and arduino rx is connected to parallax sout.

It also says "serial port com 4 already in use." when I try to upload a new sketch to the arduino.

arduino rx is connected to parallax sout.

The Arduino's RX and TX pins are used to upload new sketches. When you have external hardware attached to those pins, that can (and often does) interfere with uploading sketches.

You'll need to unplug anything connected to these pins before you can upload a sketch.

It also says "serial port com 4 already in use." when I try to upload a new sketch to the arduino.

Do you have the Serial Monitor open? Do you have any bluetooth crap connected to the PC?

Paul,

You're the man, I really appreciate it.

Such a simple fix!

All I had to do was unplug the RX and it works perfect!

Thanks!

-cgreen

Sorry to jump in on someone elses thread, but what does the line

   if((val = Serial.read()) == 10) {   // check for header

do?

I've sat here for 20 minutes trying to see how it works, guess its time to read more :slight_smile:

EDIT: I think I've been thrown off by the = and ==. Is it setting the variable val then comparing to see if it equals 10?

Is it setting the variable val then comparing to see if it equals 10?

Exactly what it is doing.

Cheers Paul :slight_smile:

While on the RFID topic, I am using a parallax reader using the following code on my MEGA 1280. Everything is running great.

The SOUT pin is attached to the RX pin 0
The ENABLE pin is attached to the PWM pin 2
THE VCC is attached to the 5V pin
THE GND is attached to the GND

Before uploading my code I unplug the RX pin 0, after its done I plug it back into the MEGA.

How would I be able to run a function in my loop with it only reconizing a specific tag, ie:0F03041400.

As of now any tag that it reads will run a my code.

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


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

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 
pinMode(7,OUTPUT);
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 
    
    digitalWrite(buzzer, HIGH);
    delay(300);
    digitalWrite(buzzer, LOW);
    

    {
    }
    } 
      bytesread = 0; 
    } 
  } 
}

The tag that is read in is stored in an array, code.

You could, when the tag read is complete, properly NULL terminate code (be sure to make the array one element larger, to hold the NULL), and then use strcmp to compare the value read in with the value that you want to do something useful. Then, do something useful only if the tags match.