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