Offline
Newbie
Karma: 0
Posts: 41
|
 |
« on: November 07, 2012, 06:03:58 am » |
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); } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 334
Posts: 36433
Seattle, WA USA
|
 |
« Reply #1 on: November 07, 2012, 06:49:07 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 334
Posts: 36433
Seattle, WA USA
|
 |
« Reply #2 on: November 07, 2012, 08:58:22 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #3 on: November 07, 2012, 09:07:22 am » |
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.
|
|
|
|
« Last Edit: November 07, 2012, 09:10:16 am by S89 »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 334
Posts: 36433
Seattle, WA USA
|
 |
« Reply #4 on: November 07, 2012, 09:27:36 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #5 on: November 07, 2012, 09:36:49 am » |
...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 
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 334
Posts: 36433
Seattle, WA USA
|
 |
« Reply #6 on: November 07, 2012, 09:44:04 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #7 on: November 07, 2012, 09:48:19 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 334
Posts: 36433
Seattle, WA USA
|
 |
« Reply #8 on: November 07, 2012, 10:53:25 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14097
Lua rocks!
|
 |
« Reply #9 on: November 08, 2012, 05:26:12 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14097
Lua rocks!
|
 |
« Reply #10 on: November 08, 2012, 05:29:10 am » |
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?
|
|
|
|
« Last Edit: November 08, 2012, 05:30:54 am by Nick Gammon »
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 6
Posts: 950
Arduino rocks
|
 |
« Reply #11 on: November 08, 2012, 01:41:28 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
|