Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <MFRC522.h>
- #include <LiquidCrystal_I2C.h>
- // Blue Tag = D9 B8 21 B9
- // White Card = D0 3A ED 32
- #define SS_PIN 27 /*Slave Select Pin*/
- #define RST_PIN 26 /*Reset Pin for RC522*/
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- void setup() {
- Serial.begin(9600); /*Serial Communication begin*/
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Hello, World!");
- SPI.begin(); /*SPI communication initialized*/
- mfrc522.PCD_Init(); /*RFID sensor initialized*/
- Serial.println("Put your card to the reader...");
- Serial.println();
- delay(1000);
- lcd.clear();
- }
- void loop() {
- /*Look for the RFID Card*/
- if ( ! mfrc522.PICC_IsNewCardPresent())
- {
- return;
- }
- /*Select Card*/
- if ( ! mfrc522.PICC_ReadCardSerial())
- {
- return;
- }
- /*Show UID for Card/Tag on serial monitor*/
- Serial.print("UID tag :");
- 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));
- }
- Serial.println();
- Serial.print("Message : ");
- content.toUpperCase();
- lcd.setCursor(0, 0);
- lcd.print(content.substring(1));
- if (content.substring(1) == "D0 3A ED 32")
- {
- Serial.println("Authorized access");
- Serial.println();
- }
- else {
- Serial.println(" Access denied");
- }
- delay(1000);
- lcd.clear();
- }//end of Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement