I've got some code from someone else to finally read tags and do an action based on what tag is read however no mater what i do when i put an RGB LED in the mix to light up a certain color based on the tag (just adding one line of code to light up a pin) it doesn't work for shit. when i hook it up the LED is ALWAYS on. Please tell me where im messing up.
int val = 0;
char code[12];
int bytesread = 0;
char tagArray[12]; // the array for the tags
char Devin[12] = {'0', '4', '1', '5', 'D', '8', 'B', '3', '0', '4'};
char Paige[12] = {'0', 'F', '0', '3', '0', '4', '0', 'D', 'E', '4'};
int RedLED=4;
int GreenLED=5;
int BlueLED=6;
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 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(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop() {
if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.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
}
if(strcmp(code,Devin) == 0) {
Serial.println("Devin, you're in");
digitalWrite(GreenLED, HIGH);
}
if(strcmp(code,Paige) == 0) {
Serial.println("Paige, you're in");
digitalWrite(GreenLED, HIGH);
}
if ((strcmp(code,Devin) !=0) && (strcmp(code,Paige)!=0)){
Serial.println("Illegal attempted entry");
Serial.println(code);
digitalWrite (RedLED,HIGH);
}
bytesread = 0;
delay(3000); // wait for a second
digitalWrite(GreenLED,LOW);
}
}
}
// extra stuff
// digitalWrite(2, HIGH); // deactivate RFID reader