#include #include #include // https://github.com/miguelbalboa/rfid #include const int RST_PIN = 13; // Configurable, see typical pin layout above const int SS_1_PIN = 32; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2 /3 const int SS_2_PIN = 33; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1 / 3 const int Relay_1 = 25; const int Relay_2 = 26; #define NR_OF_READERS 2 // How many readers you have? byte ssPins[] = {SS_1_PIN, SS_2_PIN}; MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance. LiquidCrystal_I2C lcd0(0x26, 16, 2); LiquidCrystal_I2C lcd1(0x27, 16, 2); String currentIDs[] = {"00000000", "00000000", "00000000"}; // Current ID's, changes as you play String correctIDs[] = {"d745b819", "57d85d9", "55fce42a"}; // Which ID's are correct? , stays constant as it checks this with the current ID's void setup() { //Protocol Configuration Serial.begin(9600); // Initialize serial communications with the PC SPI.begin(); // MFRC522 Hardware uses SPI protocol lcd0.begin(); lcd1.begin(); Serial.println(F("Scan Your Card")); // Turn on the blacklight and print a message. lcd0.backlight(); lcd1.backlight(); lcd0.print(F("Welcome")); lcd1.print(F("Welcome")); //Arduino Pin Configuration pinMode(Relay_1, OUTPUT); pinMode(Relay_2, OUTPUT); //Be careful how relay circuit behave on while resetting or power-cycling your Arduino digitalWrite(Relay_1, HIGH); // Make sure door is locked digitalWrite(Relay_2, HIGH); } void loop() { for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) { currentIDs[reader] = "00000000"; digitalWrite(reader + 1, HIGH); delay(40); mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card delay(40); if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) { currentIDs[reader] = getCode(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size); mfrc522[reader].PICC_HaltA(); mfrc522[reader].PCD_StopCrypto1(); } digitalWrite(reader + 2, LOW); } // Print out the current ID's Serial.print(currentIDs[0]); Serial.print(" , "); Serial.println(currentIDs[1]); if (currentIDs[0] == correctIDs[0]) { // If frst ID is correct lcd0.clear(); lcd0.print(F("Access Locker 1")); digitalWrite(Relay_1,LOW); Serial.print(F("Acces 1 OK")); Serial.print(" , "); } else if (currentIDs[0] == correctIDs[2]) { // If frst ID is correct lcd0.clear(); lcd0.print(F("Master Card")); digitalWrite(Relay_1,LOW); Serial.print(F("Acces 1 OK")); Serial.print(" , "); } else{ lcd0.clear(); lcd0.print(F("Scan Your Card!")); digitalWrite(Relay_1,HIGH); } if (currentIDs[1] == correctIDs[1]) { // If second ID is correct lcd1.clear(); lcd1.print(F("Access Locker 2")); digitalWrite(Relay_2,LOW); Serial.print(F("Acces 2 OK")); Serial.print(" , "); } else if (currentIDs[1] == correctIDs[2]) { // If second ID is correct lcd1.clear(); lcd1.print(F("Master Card")); digitalWrite(Relay_2,LOW); Serial.print(F("Acces 2 OK")); Serial.print(" , "); } else{ lcd1.clear(); lcd1.print(F("Scan Your Card!")); digitalWrite(Relay_2,HIGH); } } String getCode(byte *buffer, byte bufferSize) { String code = ""; for (byte i = 0; i < bufferSize; i++) code = code + String(buffer[i], HEX); return (code); }