Repeated reads on RFID Reader

hi all,

I am starting off with my first arduino project. What I want t achieve is this:

  • Have a RFID reader that reads IDs from cards.
  • A RF transmitter that transmits data read from the RFID reader.
  • A RF receiver that will receive the data from the transmitter. The receiver will pass the data to an Arduino which will process it and light LEDs, sound buzzers etc.

This is the first step I. The next thing I want to do is have the Arduno send the data over wifi/bluetooth to a cellphone app. basically, I want to replace the LEDs/buzzers etc with the app that will show alerts.

First thing, is this do able? For the RF communication, I am thinking of using the NRF24L01+ 2.4Ghz Wireless Module from Nordic Semi. is this a good choice? Also, for the second part of the project, where I want the Arduino to communicate with the phone, what can I use? The Arduino WiFi shield? And finally, to write the App for the Android phone, what IDE can I use? I will only need to set alarms and alerts for each ID scanned by the RFID reader. I am familiar with Vb.net, but I want to learn a open source language. Is Processing good for apps? Or I should learn something else?

Apps are widely written in Java, so try the program Eclipse. More direct, look at Android App Developers + Eclipse.
Keep in mind, Java is not that easy.

You may find it useful to look at SL4A (Scripting Layer for Android) which lets you program Android in a few different languages. http://code.google.com/p/android-scripting/

...R

There is a book Called "Getting started with RFID". The code is written in arduino platform & well commented. It is easy to understand. This is your exact solution. Download - (link to illegal material removed by moderator)

Your nRF24 solution here... http://maniacbug.wordpress.com/2012/03/30/rf24network/ All the Best.

Now I have a fairly good idea what I need to do.
This is the rough plan:

Now the only issue I have is the data communication between the RFID reader and the nr24 transceiver.
The RFID reader I have has a UART interface, while the transceiver has a SPI interface. How can I interface the two? I don’t want to have another arduino board between them just to help them talk.

Thanks!

The RFID reader I have has a UART interface, while the transceiver has a SPI interface.

They are 2 slave devices - you need a master to control them. Could be a little Pro Mini arduino.

Thank you CrossRoads. A newbie question....what is a slave device in this context? What factor decides that? Is it because neither of them has a capacity to 'process' data?

Yes - the most either of them can do is signal "Hey, I've got some data!" I suppose the UART equipped RFID can send it out, but the SPI Nordic device can't do anything with it.

Which rfid reader are you using ?

Boardburner2: Which rfid reader are you using ?

Its a RDM6300 125KHz reader.

I think that one just squirts out a serial data stream, have you considered using a simple serial data rf module.?

Boardburner2:
I think that one just squirts out a serial data stream, have you considered using a simple serial data rf module.?

I am not sure I know which. I researched a bit, and got this one more than not for the price. Its quite cheap, and I tried it yesterday, it works well enough. Each read gives me a set of 14 numbers, the first and last being the begin and end characters.

hi,
I have made some progress in this now, but have a few issues.

I have implemented the RFID reader part as of now, and have two cards which I read and have relevant LEDs light up according to the card detected.
The pin configuration is as follows:

On RFID reader :

Pin 5 is 5v input from Arduino 5v header.
Pin 4 to ground (ground rail on breadboard connected to Arduino GND pin)
Pin 1 (TX) to Arduino Pin 0 (RX)

On Arduino:
Pins 8, 9: LEDs

The code for it is as follows:

int data1=0; //to store each incoming value from serial port
int id[14]; //will store the entire array of the ID card
const int id1[] ={2,56,52,48,48,56,49,53,68,70,51,65,66,3};
const int id2[] ={2,56,52,48,48,56,49,51,57,70,67,67,48,3};
const int id1led=9;
const int id2led=8;

void setup()
{
  Serial.begin(9600);
  pinMode(id1led, OUTPUT);
  pinMode(id2led,OUTPUT); 
}

void read_card()  //this function reads the cards
{
  int counter=0;
  if(Serial.available()>0)
  {
    
    for(counter=0; counter<14;counter=counter+1)
    {
    Serial.flush();     // Want to figure out a way to stop multiple reads. Doesnt seem to work
    delay(10);
    
    data1=Serial.read();

    id[counter]=data1;
    Serial.flush();
    Serial.println(id[counter]);
    
    }
    
        //Serial.print("Array length is");
        //Serial.println(counter);
    
byte which_card= card_compare(id, counter); //which card has been detected...? Pass the array to this function
//Serial.println("Card is ");
//Serial.println(which_card);

give_output(which_card); //decide which LED to light and what to write to serial acc to detected crad

  }
}


byte card_compare(int newcard[], int length) //pass the read array (CARD ID) to this function
{
  int cc=0;
  int verifier=0; //this checks if the id numbers of detected card matches with id numbers of stored cards
  for(cc=0; cc<length;cc++)
    {
     if (newcard[cc]==id1[cc])
        {
            verifier++;
        }
     else break;
    }
    
if (verifier==14)
    {
    return 1;  //if card 1 is detected, return 1 to which_card function
    Serial.println("Card 1");
    
    }

else  //since card 1 didnt match, compare with values of card 2
  {
    verifier=0;
  for(cc=0; cc<length;cc++)
    {
     if (newcard[cc]==id2[cc])
        {
            verifier++;
        }
     else break;
    }
    
if (verifier==14)
  {return 2;  //return 2 for card 2 to which_card
    Serial.println("Card 2"); 

  }
  }  
  
}


void give_output(byte which_card) //give the desired output as per value of which_card

{
//Serial.println ("Which Card?");
//Serial.println(which_card);

  if (which_card==1)
   {
     Serial.println("Hi Harshad");
     digitalWrite(id1led, HIGH);
     delay(1000);
     digitalWrite(id1led, LOW);
   }
   
  else if (which_card==2)
   {
     Serial.println("Hi Smita");
     digitalWrite(id2led, HIGH);
     delay(1000);
     digitalWrite(id2led, LOW);
   }
   
   else 
   {
     Serial.println("NO MATCH!!");
   }
}


void loop()
{
  read_card(); 
     
}

Now, the issues I am facing are:

  • Whenever I wave a card across the RFID reader’s antenna, the RFID reader reads the card ID more than once. How do I prevent multiple reads?
  • Secondly, if I hold a card over the antenna, the reader reads the tag correctly 4-5 times, then it starts reading incomplete values or something, and i get “NO MATCH”,as I have coded. Why is this happening?

Thanks, UJ.

HazardsMind: Apps are widely written in Java, so try the program Eclipse. More direct, look at Android App Developers + Eclipse. Keep in mind, Java is not that easy.

If I was religious. ...

Java was developed by satan lol...

But yes get the adt bundle, you can use bluetooth or wifi (ethernet shield on an uno) bluetooth uses 2 pins for uart while spi requires a few more pins, the nrfl whatever uses spi then you have to individually address each slave....

Swings and roundabouts.

To stop duplicates simply store the last read id code and make sure they're not the same...

Eg

If (oldid!=newID) ......;

cjdelphi:
To stop duplicates simply store the last read id code and make sure they’re not the same…

Eg

If (oldid!=newID)
…;

If I store the old ID, I will still need to read the new id to compare to the old one. What I want is that the RFID reader reads the ID only once, then stops. Like there should be a delay between consecutive reads or something.

What I want is that the RFID reader reads the ID only once, then stops.

As I understand it, that's usually what RFID readers do. Does your device have a way of setting different modes? Perhaps you have it set to continuous read.

I'd be inclined to write a much simpler sketch that just echoes the RFID input to the serial port to prove to yourself that the issue isn't in your existing code.

wildbill: I'd be inclined to write a much simpler sketch that just echoes the RFID input to the serial port to prove to yourself that the issue isn't in your existing code.

Ok...will try that. As an aside, is there a way to execute the program step-by-step? I remember I could do that in VB6 IDE....and I could read the output of each step and follow the control through the code. great to figure out where I was screwing up.

is there a way to execute the program step-by-step?

No. Debugging arduino code is a trip back to the dark ages - your principal tool is serial.print. There are others, but the serial port is your first stop for debugging.

It seems its my RFID reader.

I tried the following code:

int data1 = 0;
int cardid[14];
int repeat =0;

void setup()
{
  Serial.begin(9600);
}


void loop()
{
  if (Serial.available()>0)
  {
    Serial.print("REPEAT NO  ");
    Serial.println(repeat);
    Serial.flush();
    Serial.println("AVAILABLE");

    for (int counter =0; counter<14;counter++)
    {
      data1=Serial.read();
      delay(100);
      cardid[counter]=data1;
      //Serial.println(cardid[counter]);
   }
    repeat++;
    
  }

}

And when I held the card above the antenna, the output was like this:

The ‘repeat’ variable is printed each time Serial.available>0 and it increments itself by 1 after the for loop is done reading the card ID.
In the datasheet for the reader, there are couple lines which are exactly like this:
Reading Types:
Standard design – card can’t be read again within the range of read antenna after read once. User must
move it out of reading antenna range first, swipe card again & can be read.
Special design – card can be read continuously within the range of read antenna.

How do I set it to the ‘Standard Design’? Or am I missing something?
The datasheet is at the bottom of this page:
http://www.itead-europe.com/index.php/itead-studio-category/wireless/rdm6300.html

Need help here, I can’t figure it out :~