Dual rfid antenna issues--works but...

Hi, I’ve got a pet door setup with two antennas. The IN antenna lets the cats in all the time, the OUT antenna checks ambient light against a photoresistor and decides whether to let the cats out or not. Everything is working BUT, and it’s a major “but,” the range on the antennas seems to have gone from 3-4 inches to .1 inch. Now I practically have to hold the tag against the antenna for it to work. Other issue: I 've switched from an atmega328 to a MEGA.

Any ideas? i’ve changed the materials it was mounted on. I’ve tried unhooking one antenna…

Has anyone resolved a similar issue?

My code is below. I’ve been putting delay statements indifferent places to see if I need to slow things down.

#include <AFMotor.h>
//Set up different variables.
AF_Stepper motor(130, 1); //130 is the number of steps the motor has, 1 tells the controller which motor
int lightPin = 2; //This is analog pin 2.  We will read it and use that value to determine whether cats can leave of not.
int  val = 0; //This is used to get data from the antennas.
char code[12]; //The arduino.cc code shows a [10].  You may need to put [12] in here.  This solved a major frustration for me.
int bytesread = 0; //This is used to get data from the antennas.
char Biscuit[12] = {'3', '6', '0', '0', '7', '3', '8', '1', '8', '3'};       //These are obviously the tags.  With thse arrays, the strcmp function worked.
char Marathon[12] = {'3', '6', '0', '0', '8', 'A', '9', '4', '4', '3'};
char Max[12] = {'3', '6', '0', '0', '5', 'C', '6', 'F', '3', '6'}; 
char Sage[12] = {'3', '6', '0', '0', '5', 'C', '2', 'F', 'B', '2'};
char Veeps[12] = {'3', '6', '0', '0', '5', 'B', '8', '6', 'C', '6'};


//Initialize the following ports and pins once then begin loop.
void setup() { 

Serial.begin(115200); 
Serial1.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
Serial2.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(52,OUTPUT); //another antenna output
digitalWrite(2, LOW);                  // Activate the RFID reader
digitalWrite(52,LOW); //set to high because we'll be multiplexing
motor.setSpeed(200);  // 240 rpm   
}  


 void loop() { 

 if(Serial1.available() > 0) {          // if data available from reader 
    if((val = Serial1.read()) == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( Serial1.available() > 0) { 
          val = Serial1.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         
        {
        if(strcmp(code,Biscuit) == 0) {        //This is my own code.  Not hard.  There's probably a way to do this all in one line by having the the if statement run through the list of tags.
          Serial.println("Biscuit just came in.");
          motor.step(2400, BACKWARD, DOUBLE); 
          motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial1.flush();
            Serial.flush();
            ;
        }
          if(strcmp(code,Marathon) == 0) {
            Serial.println("Marathon just came in.");
            motor.step(2400, BACKWARD, DOUBLE); 
            motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial1.flush();
            Serial.flush();
            ;
          }
          if(strcmp(code,Max) == 0) {
            Serial.println("Max just came in.");
            motor.step(2400, BACKWARD, DOUBLE); 
            motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial1.flush();
            Serial.flush();
            ;
          }
          if(strcmp(code,Sage) == 0) {
            Serial.println("Sagebrush just came in.");
            motor.step(2400, BACKWARD, DOUBLE); 
            motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial1.flush();
            Serial.flush();
            ;
          }
          if(strcmp(code,Veeps) == 0) {
            Serial.println("Veeps just came in.");
            motor.step(2400, BACKWARD, DOUBLE); 
            motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial1.flush();
            Serial.flush();
            ;
  
          }
          if((strcmp(code,Biscuit) !=0) && (strcmp(code,Marathon) != 0) && (strcmp(code,Max) !=0) && (strcmp(code,Sage) !=0) && (strcmp(code,Veeps) !=0)) { 
          Serial.println("Illegal attempted entry");  //Any cat that shows up with an rfid will be denied and it will go on record.
          Serial.println(code);
          Serial1.flush();
      }}}
         
      bytesread = 0; 
           ;                       // wait a bit 
    }
bytesread = 0; 
           val = 0;
}      
delay(500);
  if(Serial2.available() > 0) {          // if data available from reader 
    if((val = Serial2.read()) == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( Serial2.available() > 0) { 
          val = Serial2.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("S2 TAG code is: ");   // possibly a good TAG 
        Serial.println(code);     // print the TAG code   
        bytesread = 0;
        if((strcmp(code,Biscuit) == 0) && (analogRead(lightPin) > 15)) {        //This is my own code.  Not hard.  There's probably a way to do this all in one line by having the the if statement run through the list of tags.
          Serial.println("Biscuit just went out.");
            Serial.print("Ambient light level: "); 
            Serial.println(analogRead(lightPin));
          motor.step(2400, BACKWARD, DOUBLE); 
          motor.step(2600, BACKWARD, DOUBLE); 
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial2.flush();
            Serial.flush();
            ;
        }
          if((strcmp(code,Marathon) == 0) && (analogRead(lightPin) > 15)) {
            Serial.println("Marathon just went out..");
            Serial.print("Ambient light level: "); 
            Serial.println(analogRead(lightPin));
            motor.step(2400, BACKWARD, DOUBLE);
           motor.step(2600, BACKWARD, DOUBLE); 
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial2.flush();
            Serial.flush();
            ;
          }
          if((strcmp(code,Max) == 0) && (analogRead(lightPin) > 15)) {
            Serial.println("Max just went out.");
            Serial.print("Ambient light level: "); 
            Serial.println(analogRead(lightPin));
            motor.step(2400, BACKWARD, DOUBLE);
           motor.step(2600, BACKWARD, DOUBLE); 
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial2.flush();
            Serial.flush();
            ;
          }
          if((strcmp(code,Sage)&& (analogRead(lightPin) > 15)) == 0) {
            Serial.println("Sagebrush just went out.");
            Serial.print("Ambient light level: "); 
            Serial.println(analogRead(lightPin));
            motor.step(2400, BACKWARD, DOUBLE); 
            motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
            motor.step(2600, FORWARD, DOUBLE);
            motor.release();
            Serial2.flush();
            Serial.flush();
            ;
          }
          if(strcmp(code,Veeps) == 0) {
            Serial.println("Veeps just went out.");
            Serial.print("Ambient light level: "); 
            Serial.println(analogRead(lightPin));
            motor.step(2400, BACKWARD, DOUBLE); 
            motor.step(2600, BACKWARD, DOUBLE);
            delay(20000);
            motor.step(2400, FORWARD, DOUBLE);
 


etc..

The problem with trying to run two RFID devices close to each other is that they interfere and reduce the range. Even though they are on the other side of the door they are very close together.

The best way get round this is to mount the antennas on ferrite sheet or tiles. This will cut down on the backwards field without draining too much power from the coil.

Ferrite tiles are used in screened chambers and might be difficult to get hold of.

Ferrite tiles are used in screened chambers and might be difficult to get hold of

And even if you do get hold of them, they're very difficult to lift ;D

Thanks for the help. I had a sneaking suspicion this was the case. Ferrite tiles, huh. When I find some maybe I'll try it just for the heck of it. Until then, I'll leave the rfid on the outside and put a ping sensor on the inside.

Thanks a lot for the quick replies. Probably saved me 3 hours of troubleshooting.

Andy

For those who are interested, I found these ferrite EMI disks on digikey:

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=240-2267-ND

I'm going to order a few because they are so cheap, but I'm still going to go ahead an use a ping sensor, just for reliability purposes.

Thanks again.

I'm curious what you're using for an RFID reader because I'm just starting an RFID project myself. One thing I discovered is many boards state they must be 1-2 meters from another ACTIVE antenna. I emphasized active because at least one board, the PhidgetRFID, can select whether the antenna is enabled or not. This allows close proximity by using the software to enable only one antenna at a time. Perhaps controlling power to a reader could have the same result?

http://www.phidgets.com/products.php?category=14&product_id=1023

That's a good point--you're talking about multiplexing, I tried that with little success--I'm not sure why. (The antenna's don't fully deactivate?).

I also tried it with an ATMEGA 328 and it basically ruined the bootloader. Someone with more experience might have better luck. Definitely start with a big delay between the antennas and make it smaller until you figure it out.

Good luck. I'm now using a motion detector for exit and rfid for entry. There are still some challenges with antenna placement vs. cat behavior.

Perhaps controlling power to a reader could have the same result?

Not normally as all readers have processors in them and these need a second or so to initializes, therefore if you multiplex them too fast they won't have time to start working.

Look at:- http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html and you see I have three RFID readers working at the same time within only a few inches. You do get a reduced range however because the signals from one antenna are picked up by the others.