Hey all, I have a UNO and Parallax RFID reader I am using to unlock a car door, the code work great but I am wanting to add a second card to the code to unlock but not to sure on how to do it. Looking for some suggestions or example on how to . Current code I am using below.
Thanks for any help.
char tag[12] = {'0', '7', '0', '0', '8', '0', 'B', 0', '6', 'F'}; //rfid code
char code[12];
int bytesread = 0;
int doorPin = 13; // Connect red LED to pin 13
int rfidPin = 2; // RFID enable pin connected to digital pin 2
int val=0;
long lastUpdate=0;
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(rfidPin,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(doorPin,OUTPUT); // Set doorPin to output
digitalWrite(rfidPin, LOW); // Activate the RFID reader
}
void loop()
{ char tagString[13];
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
if(strcmp(code, tag) == 0) {
Serial.print("ACCESS GRANTED : ");
Serial.println(code);
digitalWrite(rfidPin, HIGH); // diable rfid reader
digitalWrite(doorPin,HIGH); // good read unlock door
delay(800); // wait a second
digitalWrite(doorPin,LOW); // turn off door lock relay
delay(600); //wait about half a second
digitalWrite(doorPin,HIGH); // unlock door
delay(800); // wait a second
digitalWrite(doorPin,LOW); // turn off door lock relay
delay(2000); // wait 2 seconds
digitalWrite(rfidPin,LOW); // enable rfid reader
Serial.flush(); // flush all rfid reads, stops multiple reads from one rfid read
}
else {
Serial.print("ACCESS DENIED : ");
Serial.println(code);
digitalWrite(rfidPin, HIGH); // disable rfid reader
delay(3000); // wait 3 seconds
digitalWrite(rfidPin,LOW); // enable rfid reader
Serial.flush(); // flush all rfid reads, stops multiple reads from one rfid read
}
}
bytesread = 0;
delay(500); // wait for a 1/2 second
}
}
}