/* Project: RFID RC522 module, LEDs, LCD1602 i2C module Function: Simple security access */ //*************************************************************************** #include //include library code for SPI comms #include //include library code for RFID #include //include library code for LCD1602 I2C module //define RFID pins const int SS_PIN = 10; const int RST_PIN = 9; MFRC522 mfrc522(SS_PIN, RST_PIN); //create MFRC522 instance. const int redLEDpin = 8;//red LED attached to Arduino Uno digital pin 8 const int greenLEDpin = 7;//green LED attached to Arduino Uno digital pin 7 const int buzzerPin = 6;//active piezo buzzer attached to Arduino Uno digital pin 6 LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);//initialize the library with the numbers of the interface pins //*************************************************************************** void setup() { Serial.begin(9600); //initiate a serial communication SPI.begin(); //initiate SPI bus mfrc522.PCD_Init(); //initiate MFRC522 pinMode(redLEDpin, OUTPUT); //sets redLEDpin as OUTPUT pinMode(greenLEDpin, OUTPUT);//sets greenLEDpin as OUTPUT pinMode(buzzerPin, OUTPUT);//sets buzzerPin as OUTPUT Serial.println("Put your RFID tag close to the reader..."); Serial.println(); lcd.begin(16, 2); //16X2 lcd display lcd.setBacklightPin(3, POSITIVE); //switch on the backlight lcd.setBacklight(HIGH); lcd.setCursor(0, 0); //setting display position lcd.print(" SIMPLE ACCESS "); lcd.setCursor(0, 1); //setting display position lcd.print(" CONTROL "); delay(2000); lcd.clear(); } void loop() { lcd.setCursor(0, 0); //setting display position lcd.print("Scan your tag or"); lcd.setCursor(0, 1); //setting display position lcd.print("card..."); // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); // Sound the buzzer when a card is read tone(buzzerPin, 2000); delay(100); noTone(buzzerPin); delay(100); String content = ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); lcd.clear(); lcd.setCursor(0, 0); //setting display position for (byte i = 0; i < mfrc522.uid.size; i++) { lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); lcd.print(mfrc522.uid.uidByte[i], HEX);} } Serial.println(); Serial.print("Message : "); content.toUpperCase(); if (content.substring(1) == "00 40 86 19") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized"); digitalWrite(greenLEDpin, HIGH); delay(500); digitalWrite(greenLEDpin, LOW); lcd.setCursor(0, 1); //setting display position lcd.print(" Authorized "); delay(500); lcd.clear(); } else { Serial.println("No access"); digitalWrite(redLEDpin, HIGH); delay(500); digitalWrite(redLEDpin, LOW); lcd.setCursor(0, 1); //setting display position lcd.print(" No access "); delay(500); lcd.clear(); } }