Hi and Sorry for late reply, been working on my mechanical crafting certificate this week.
Heres my code
#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial RFID(7, 8);
byte b;
byte buffer[30];
uint8_t idx;
boolean RFIDstart = false;
byte XOR;
byte inverted;
uint32_t value;
int yellowLED(3);
int redLED(4);
int blueLED(5);
Servo myServo;
void setup()
{
Serial.begin (9600);
RFID.begin (9600);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
myServo.attach(12);
}
void loop()
{
myServo.detach();
String content = "";
while (RFID.available())
{
b = RFID.read();
if (b == 0x02) // Start byte
{
idx = 0;
RFIDstart = true;
}
if (RFIDstart) // Ignore anything received until we get a start byte.
{
buffer[idx++] = b;
if (b == 0x03) // End byte
{
RFIDstart = false;
// Display the received data.
Serial.print("Received data: ");
for (int x = 0; x < idx; x++)
{
if (buffer[x] < 0x10)
{
Serial.print("0"); // Pad with leading 0
}
Serial.print (buffer[x], HEX);
Serial.print (" ");
}
Serial.println("");
// Check we received the message ok. XOR checksum on bytes 01-26 should match byte 27.
XOR = buffer[1];
for (int x = 2; x <= 26; x++)
{
XOR ^= buffer[x];
}
Serial.print("Calculated checksum: ");
Serial.print(XOR, HEX);
if (XOR == buffer[27])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Check the inverted XOR checksum
inverted = ~XOR;
Serial.print("Inverted checksum: ");
Serial.print(inverted, HEX);
if (inverted == buffer[28])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Extract the card number from bytes 01 (LSB) - 10 (MSB).
value = 0;
for (int x = 10; x >= 1; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Card number: ");
Serial.println(value);
//If the chip is scanned, action will happen. LED just for indecators. Servo for feeding
if(value == 3611416205)
{
Serial.println("Todd");
// Diffrent commands
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
myServo.attach(12);
myServo.write(90);
delay(2000);
myServo.write(0);
delay(2000);
myServo.write(90);
delay(2000);
myServo.detach();
delay(600000);
}
// Extract the country number from bytes 11 (LSB) - 14 (MSB).
value = 0;
for (int x = 14; x >= 11; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Country number: ");
Serial.println(value);
// Extract the Data Block from byte 15.
Serial.print("Data block: ");
Serial.println(buffer[15] - '0');
// Extract the Animal Flag from byte 16.
// LED on off just for testing
Serial.print("Animal flag: ");
Serial.println(buffer[16] - '0');
digitalWrite(redLED, HIGH);
delay(2000);
digitalWrite(redLED, LOW);
delay(2000);
Serial.println("\r");
}
}
}
}
The problem is, when the cats stay in the feeder, the RFID dosent turn of, even with delay at the end, and scans the same chip 2-3 times, and when the delay is over it start feeding 2 more times when the cat is gone.
Thank you for your time.