Hi All,
I am working on an automatic pet feeder addition project where I need to use a pet injectable microchip to activate a servo motor when the RFID chip reader reads the correct chip and does not open for any other chip. When the correct chip is read a flap will open for as long as the animal is still being picked up by the ultrasonic sensor. Once the animal moves away the flap closes after say 5-10 seconds. If another animal's chip is read in that countdown period, the flap will automatically default to closing.
The hardware I have for this is in the images below. I am using an Arduino Uno R3 for the controller.
The code found and been able to get working so far for the scanning is below. I am unsure how to incorporate the servo and the sensor into the mix.
If you have any suggestions that would be appreciated. Thanks!
/* Test scanner to activate servo
Test Tag = Cat 3 = TAG: 978 142000100827
*/
#include <SoftwareSerial.h>
#include <Rfid134.h>
// implement a notification class,
// its member methods will get called
//
class RfidNotify
{
public:
static void OnError(Rfid134_Error errorCode)
{
// see Rfid134_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPacketRead(const Rfid134Reading& reading)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
char temp[8];
Serial.print("TAG: ");
// since print doesn't support leading zero's, use sprintf
sprintf(temp, "%03u", reading.country);
Serial.print(temp);
Serial.print(" ");
if (reading.id == 14200010827) {
Serial.print("CAT!");
};
// since print doesn't support leading zero's, use sprintf
// since sprintf with AVR doesn't support uint64_t (llu/lli), use /% trick to
// break it up into equal sized leading zero pieces
sprintf(temp, "%06lu", static_cast<uint32_t>(reading.id / 1000000));
Serial.print(temp);
sprintf(temp, "%06lu", static_cast<uint32_t>(reading.id % 1000000));
Serial.print(temp);
Serial.print(" ");
if (reading.isData)
{
Serial.print("data");
}
if (reading.isAnimal)
{
Serial.print("animal");
}
Serial.println();
}
};
// instance a Rfid134 object,
// defined with the above notification class and the hardware serial class
//
//Rfid134<HardwareSerial, RfidNotify> rfid(Serial1);
// Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
// comment out the above definition and uncomment these lines
SoftwareSerial secondarySerial(3, 2); // RX, TX
Rfid134<SoftwareSerial, RfidNotify> rfid(secondarySerial);
void setup()
{
Serial.begin(9600);
Serial.println("initializing...");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
// due to design differences in (Software)SerialConfig that make the serial.begin
// method inconsistent between implemenations, it is required that the sketch
// call serial.begin() that is specific to the platform
//
// hardware
//Serial1.begin(9600, SERIAL_8N2);
// software ESP
//secondarySerial.begin(9600, SWSERIAL_8N2);
// software AVR
secondarySerial.begin(9600);
rfid.begin();
Serial.println("starting...");
}
void loop()
{
rfid.loop();
//look for motion
}


