Advertisement
belrey10

RFID

Aug 6th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3.  
  4. #define RST_PIN 9
  5. #define SS_PIN  10
  6.  
  7. MFRC522 mfrc522(SS_PIN, RST_PIN);
  8.  
  9. void setup() {
  10.     serial.begin(9600);
  11.     while (!Serial);
  12.     SPI.begin();
  13.     mfrc522.PCD_Init();
  14.     delay(4);
  15.     mfrc522.PCD_DumpVersionToSerial();
  16.     Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  17. }
  18.  
  19. void loop() {
  20.  
  21.     if ( ! mfrc522.PICC_IsNewCardPresent() ) {
  22.         return;
  23.     }
  24.  
  25.     if ( ! mfrc522.PICC_ReadCardSerial() ) {
  26.         return;
  27.     }
  28. String uid = "";
  29.     for (byte i = 0; i < mfrc522.uid.size; i++) {
  30.         uid.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  31.         uid.concat(String(mfrc522.uid.uidByte[i], HEX));
  32.     }
  33. uid.toUpperCase();
  34. Serial.println(uid);
  35. delay (3000);
  36.  
  37.     if (uid.substring(1) == "F5 7E 7E 63")      //Replace this with the HEX value that your card has
  38.     {
  39.      Serial.println("ID Accepted");
  40.     }
  41.     else
  42.     {
  43.      Serial.println("ID Denied");
  44.     }
  45.  
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement