Just a small number of tags will be issued 5 at max. I think using part of your code will work
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
//create a Serial object RFID
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];
int val = 0;
int bytesread = 0;
char Red[] = "3900A502C35D"; // Tag ID.
char Blue[] = "39009F2DAD26"; // Tag ID.
char Yellow[] = "39005082A843"; // Tag ID.
char Card1[] = "140029A6079C"; // etc..
char Card2[] = "14002943BFC1"; // etc..
int ledCnt = 5;
int LED[] = {13, 11, 9, 7, 5};
void setup()
{
Serial.begin(9600); //open serial hardware
RFID.begin(9600); //open serial software
pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
pinMode(txPin, OUTPUT); //this is not important
for(int i=0; i<ledCnt; i++)
{
pinMode(LED[i], OUTPUT);
}
}
void loop()
{
val = 0;
bytesread = 0;
while(bytesread < 12)
{
// read 12 digit code
val = RFID.read();
if(val == 3)
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
if(val != 2)
{
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
code[bytesread] = '\0'; // add the NULL
}
}
if(bytesread >= 12)
{ // if 12 digit read is complete
Serial.print("Tag: [");
for(int i=0; i<bytesread; i++)
{
Serial.print(code[i]);
}
Serial.println("]"); //print the whole 13 bytes
int tag = FindValidTag(code);
Serial.print("Tag number: ");
Serial.println(tag);
for(int i=0; i<ledCnt; i++)
digitalWrite(LED[i], LOW);
if(tag > 0 && tag <= ledCnt)
digitalWrite(LED[tag-1], HIGH);
}
}
int FindValidTag(char *code)
{
if(strcmp(code, Red) == 0)
return 1;
else if(strcmp(code, Blue) == 0)
return 2;
else if(strcmp(code, Yellow) == 0)
return 3;
else if(strcmp(code, Card1) == 0)
return 4;
else if(strcmp(code, Card2) == 0)
return 5;
else
return 0;
}
However how to modify this to include the keypad, LCD, and triggering a relay instead of LED's is what I'm working on now.
How can I eliminate the LED's and just pull one pin high on a matched read regardless of the number? I also need to be able to manually enter a code and pull a pin high to energize a relay module I have to power the electric door latch.