Ok i have replaced my ASCII character comparison to a string the reader now works but, any rfid card that is scanned works. Here is my code. Why is it that any card that is scanned sets relayPin HIGH? I only want the specified card code to work.
// Modified by Worapoht K.
#include <SoftwareSerial.h>
char cardString[13] = "0800E1514A";
int val = 0;
char code[10];
int bytesread = 0;
const int relayPin = 10;
#define rxPin 8
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8
void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
pinMode(relayPin, OUTPUT);
}
void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0; // wait for a second
delay(500);
}
if(code[10] == cardString[13])
{
delay(35);
digitalWrite(relayPin, HIGH);
delay(1500);
digitalWrite(relayPin, LOW);
}
}