Help please with RFID Dog Bowl project.

I am working on an electronic dog bowl project that opens when the dog comes near (with an RFID tag on his collar) and closes once he leaves. The problem with my code is that I want the lid to stay open while the tag is still detected (dog still eating). At the moment, it opens when it detects the tag (which is good), however, doesn't remain open while the dog is standing at the bowl. Lid is controlled by a servo that opens when 'raise_lid' function is called, and closes when 'lower_lid' function is called. Both of these functions work correctly.

Any ideas on how to fix my code would be greatly appreciated.

Sorry, I am a beginner and don't know my way around Arduino very well.

Regards
Boyd

#include <SoftwareSerial.h>
SoftwareSerial id20(3,2); // virtual serial port
char i;
int pos = 80;
int counter = 0;
boolean open_door = false;
#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 


void setup() 
{
 Serial.begin(9600);
 id20.begin(9600);
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 myservo.write(80);
}


void loop () 
{
 if(id20.available()) {
 Serial.println("tag detected");
 while (counter < 16){
   i = id20.read(); // receive character from ID20
   Serial.println(counter);
   counter ++;
 }
 counter = 0;
 open_door = true;
 }

 if (open_door == true){
   raise_lid();
   open_door = false;
   delay(1000);
 }

 else (open_door == false);{
   lower_lid();
 }
delay (2000);
 
}



void lower_lid()
{
  Serial.println(pos);
  if (pos <= 30){
    Serial.println("lower lid");
     for(pos = 30; pos<=80; pos++){    // goes from 90 degrees to 0 degrees 
       myservo.write(pos);              // tell servo to go to position in variable 'pos' 
       Serial.print(pos);
       Serial.print(",");
       delay(15);                       // waits 15ms for the servo to reach the position 
     }
     Serial.println("");
  }
}  
  
  
  
  
void raise_lid()
{
  Serial.println(pos);
  if (pos >= 80){
    Serial.println("raise lid");
     for(pos = 80; pos>=30; pos-=1)     // goes from 90 degrees to 0 degrees 
     {                                
       myservo.write(pos);              // tell servo to go to position in variable 'pos' 
       Serial.print(pos);
       Serial.print(",");
       delay(15);                       // waits 15ms for the servo to reach the position 
     }
     Serial.println("");
  }
}

Any ideas on how to fix my code would be greatly appreciated.

What you have to fix are your expectations. An RFID reader sends output ONCE when it sees a tag. It does not send out a continuous stream of data while the tag is in range, nor does it send a "Hey, the tag left" packet.

Perhaps you could add a ping type sensor, where you independently determine if the dog is still there, once you know that is is present.

PaulS,

Thanks very much, I get your point.

I may look at putting an IR proximity detector on the front of the dog bowl to detect if the dog is still standing there. If he is, then I won't lower the bowl lid.

Greatly appreciate your help. First time I have used an RFID sensor.

Boyd.

Look at the documentation for your reader - in some cases you can set them into a mode where they do continue to send the tag ID while they can still see it.

Look at the documentation for your reader - in some cases

In my experience, that should be "in rare cases..."

Another idea is a mat with flex sensors where the dog stands. As long as the dog is there (and not too fat), leave the lid open. When the dog leaves, or gets too fat, close the lid.