#include <SoftwareSerial.h>
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count = 0; // counter for buffer array
const int tagLength = 13;
const char matchingTag[] = "010F5E146F+";
void setup()
{
Serial.begin(9600); // the Serial port of Arduino baud rate.
Serial.println("RFID module started in Auto Read Mode, Waiting for Card...");
clearBuffer();
}
void loop()
{
if (ChecForTag())
{
if (strcmp(buffer, matchingTag)==0)
{
Serial.println("Tag Matched");
Serial.write(buffer,count);
Serial.println();
} else { Serial.println("Tag Not Matched");
Serial.write(buffer,count);
Serial.println();
}
//clear buff
clearBuffer();
//reset count
count = 0;
}
}
// function to clear buffer array
void clearBuffer()
{
for (int i = 0; i < count; i++)
{
buffer[i] = NULL;
} // clear all index of array with command NULL
}
bool ChecForTag()
{
bool haveTag = false;
//is there a byte
if (Serial.available())
{ //while there is a byte
while (Serial.available())
{ //read a byte
char c = Serial.read();
// SOT, EOT, NL don't include
if (c != 2 && c != 3 && c != 10)
{ //save byte to butter, increase count
if (count < sizeof(buffer)) {
buffer[count] = c;
count++;
}
} else { //EOT recvd, we have a tag
if (c == 3) haveTag = true; //EOT -end of text
if (c == 10) haveTag = true; //NL - also trigger here in case no EOT, for sim
}
}
}
return haveTag;
}