Serial RFID Problem

I'm currently playing around with RFID and Arduino at the minute, however I'm a little stuck. The RFID reader is connected to the RX and TX pins on the Arduino, communicating via serial.

What I want the code do to is to recognise when the RFID chip is actively in range of the reader and blink the LED on and off. When I remove the RFID chip away, it should turn off the LED.

What it's currently doing is turning on the LED... and not much else. I've been reading the serial references, but to no prevail.

int led = 7;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);  
}
void loop()
{
  if(Serial.available())
  {
    digitalWrite(led, HIGH);
    delay(1000);              
    digitalWrite(led, LOW);   
    delay(1000);              
  }
}

When you wave the tag by the reader, the reader sends some serial data to the Arduino. Once that arrives, you do nothing to remove it from the buffer (Serial.read() does that), so once there is serial data, Serial.available() reports a positive number of characters, so you turn the LED on, wait a second, turn it off, wait a second, and then check that the serial data is still there.

It would seem more useful to actually read the data. Further, it would seem more useful to actually light the LED is a specific tag was recognized.

Ideally, the light would stay on whenever the tags being read (for an indefinite amount of time). Any reason why this would be?

I guess that depends on your concept of ideal. The RFID reader was designed to read the tag once when it comes into range, and then ignore it. It is not mean as a proximity detector.

Is there no way that I could store the incoming data in a buffer and get the Arduino to check every 5 seconds or so? If the buffer is empty then turn off the LED, if it contains the ID, keep it on?

I need the LED to turn on whenever someone unique touches (or is very close) to the hotspot.

Is there no way that I could store the incoming data in a buffer

Of course there is.

and get the Arduino to check every 5 seconds or so?

Check what?

If the buffer is empty then turn off the LED, if it contains the ID, keep it on?

The buffer won't be empty if a new tag has been scanned. Of course, you can check whether that is the same tag you saw last time. But, typically, if the tag has not moved out of range, it won't be read again.

I need the LED to turn on whenever someone unique touches (or is very close) to the hotspot.

For how long?

...Get Arduino to check for a before/after difference within the buffer.

The tag is continually read every 50ms or so by the reader, even if it's still within range, so that's not an issue.

The LED will stay on until the tag is removed away from the reader (when the buffer is empty?) when it'll turn off.

--

Assuming this is the best avenue forward, could you give me some pointers to get started? Getting a little lost somewhat.

Thanks Paul :)

could you give me some pointers to get started?

Sure:

char *pCharPtr;
int *pIntPtr;
float *pFloatPtr;

Perhaps you could post a link to the RFID reader you are using.

Sure, that probably would have been helpful to begin with: http://www.seeedstudio.com/depot/125khz-rfid-module-uart-p-171.html

That looks like the same one I have. I don’t recall that it scanned the tag over and over. I’ll check this afternoon when I get home.

S89: What I want the code do to is to recognise when the RFID chip is actively in range of the reader and blink the LED on and off. When I remove the RFID chip away, it should turn off the LED.

I just tested with my RFID reader. When you hold the card near it, it actives once. No matter how long you leave the card there. It isn't a proximity sensor, as PaulS said. No doubt the software in the sensor is configured to only send the same ID once. After all, if you are scanning a bag of chips at the supermarket, you don't want to be charged for 5 bags if they hold the bag in front of the sensor for a couple of seconds.

The datasheet from their web page says:

Reading Type:

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.

Do you have standard design? Or special design?

I know I dont have same RFID hardware...

but I know my datasheet explains/outlines.. that it will take the first number in the 'area' and hold it in a 'buffer' (or whatever) to ensure that no other cards get mixed up if in the same vicinity.