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.
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
}
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.
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?
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.