Hi i'm new to the forums and i desperately need you help. i've lost so much sleep over this simple little project.
I have a Parralax RFID reader connected to my arduino duemilanove.
I am just trying to get a door switch and RGB LED to light up when i scan a card. it won't read the card at all it seems because i don't see a light light up.
Also, when i told the arduino to Serial.print the tag it was reading it just kept reading
1
1
1
1
on and on and on.
PLEASE help me.
Here is my code
void setup () {
Serial.begin(2400);
pinMode(2, INPUT);
Serial.begin(2400);
pinMode(3,OUTPUT);
}
int RFIDValue = digitalRead(2); //the readout of pin 2 is the RFID tag number
int Tag1 = '0F03040DE4'; // add intergers for more tag numbers make sure to include new tag in RFID 'LOOP' value
int Tag2 = '0415D8B304';
void loop(){ // check Tag Numbers
if ((RFIDValue == Tag1) || (RFIDValue == Tag2))
{
unlock();
}
else if (RFIDValue == 1){
Readylight();
}
else{
Locklight();
}
}
void unlock(){
digitalWrite(9, HIGH); // Unlock signal to door
digitalWrite(4,HIGH); // Light the Green LED
digitalWrite(13,HIGH); // Sound beep for confirming Tag is Read
delay(3000);
}
void Locklight(){
digitalWrite(5, HIGH); //Turn RED LED pin on
digitalWrite(13,HIGH); //Sound beep for confirming Tag is Read
delay(3000);
}
void Readylight(){
digitalWrite(6,HIGH); //Blue ready light until tag is read
}
If only this were the case and reading RFIDs were this simple... But he is right. A little time with Google will go along way. Not only with this question, but you will also learn of places and resources that will be able to help you. I got my Arduino less than 10 days ago and got it up and running in my first night. I didn't have the Parallax RFID reader, but the ID-20 from Innovation. There are many more resources for the Parallax Reader. A few great sites that may help you out to get it running is Arduino.cc itself, or a site like Instructables.com.
Thanks for your help guys. i've been googling my ass off for a while. everyone's code is different as to how to read the tag and i'm just trying to simplify the code. everyone else is doing alot more than just checking a tag like i am so its hard to adapt someones else's code. Do you perhaps know of how to get the readout of the RFID reader? i mean the parallax LED turns red like its ready to scan. i've even read half a book on javascript coding which i found out yesterday i should have been reading C programming but its pretty similar so not a total waste. i need a point in the right direction :~
This is some code i pulled from the Arduino.cc website on how to use it and print the tag and i modified it to try and do what i want it to. although i have no luck whatsoever getting it to do anything such as print (good tag) or something after it has successfully scanned the "goodcode"
//Sout pin is connected to 1 and enable pin is connected to pin 3 th OUTPUT pin.
int val = 0;
char code[10];
int bytesread = 0;
const int goodcode = '0F03040DE4';
int RFIDstate = 0;
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(3,OUTPUT); // Set digital pin 3 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(3, LOW); // Activate the RFID reader
pinMode(4,LOW);
}
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(1);
if (val == goodcode){
digitalWrite(4,HIGH);
}
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);
}
bytesread = 0;
delay(500); // wait for a second
}
}
}
// extra stuff
// digitalWrite(2, HIGH); // deactivate RFID reader
Does this even compile? The read method does not take any arguments.
const int goodcode = '0F03040DE4';
Int? That value is not an int. Try:
const char goodcode[] = "0F03040DE4";
Notice the double quote, not single quote, delimiters for a string of characters. Notice that goodcode is an array, not a scalar.
if (val == goodcode){
digitalWrite(4,HIGH);
}
This will never be true. You have read one character of a 10 character tag. Of course it will not be equal to the whole tag.
Does this:
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code);
}
result in data in the serial monitor?
If so, add some code to it:
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code);
if(strcmp(code, goodcode) == 0) // Do the tags match?
{
Serial.println("The scanned tag is the right one");
}
}
delay(500); // wait for a second
500 milliseconds is not a second. The purpose of this statement is pretty obvious. The comment contributes nothing to understanding what the code is doing.
Sorry lol the serial.read(1) was a quick change i made in desperateness. i changed it back to no parameters.
also the 500 ms delay was there from Arduino.cc as well as the comment i'll try out that extra code you added. i've never seen that strcmp command.