Go Down

Topic: Very strange problem with my rfid reader. (Read 1 time) previous topic - next topic

Biggie747

I figured out the fix it, but I can't post it because I'm new and I need to burn my first message so I can put my code on here.

Biggie747

I don't know if anyone else has this problem but I did and it was frustrating. I am using the parallax RFID reader and connected it through serial to my arduino just like the Arduino Playground suggested to:

http://www.arduino.cc/playground/Learning/PRFID

On the above page it shows that you can change the state of the RFID reader pin called "Enable" to LOW to activate the reader. The code available has the reader enabled all of the time. To stop the repeating when you swipe the RFID, I changed the state of pin 2 to high (disabling the reader) right after the first "If" statement.

Code: [Select]

// 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[11];
int bytesread = 0;
char pass[11] = {'0','F','0','3','0','2','9','F','6','5'};
int ledgPin = 8;
int ledrPin = 9;


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
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);

}  


void loop() {
 
   digitalWrite(2, LOW);
 if(Serial.available() > 0) {    // if data available from reader
 
 [glow]  digitalWrite(2, HIGH);[/glow]

   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
       if(strcmp(code, pass) == 0) {
         digitalWrite(ledgPin, HIGH);
         delay(1500);
         digitalWrite(ledgPin, LOW);
       }
       else {
         digitalWrite(ledrPin, HIGH);
         delay(300);
         digitalWrite(ledrPin, LOW);
         delay(300);
         digitalWrite(ledrPin, HIGH);
         delay(300);
         digitalWrite(ledrPin, LOW);
         delay(300);
         digitalWrite(ledrPin, HIGH);
         delay(300);
         digitalWrite(ledrPin, LOW);
         delay(300);
       }
         
       Serial.print("TAG code is: ");   // possibly a good TAG
       Serial.println(code);            // print the TAG code
     }
     bytesread = 0;
          delay(500);                       // wait for a second
   }
 }
 
}



Don't forget to change the state back to LOW just before the IF statement, as seen in the coding above.
Have Fun!

Go Up