Advertisement
icorrelate

Arduino RFID

Jul 11th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3.  
  4. constexpr uint8_t RST_PIN = 9;
  5. constexpr uint8_t SS_PIN = 10;
  6. int ledPin = 7;
  7. MFRC522 mfrc522(SS_PIN, RST_PIN);  
  8.  
  9. void setup() {
  10.     Serial.begin(9600);
  11.     while (!Serial);   
  12.     SPI.begin();
  13.   pinMode(ledPin, OUTPUT);
  14. }
  15.  
  16. void loop() {
  17.     if ( ! mfrc522.PICC_IsNewCardPresent()) {
  18.         return;
  19.     }
  20.     if ( ! mfrc522.PICC_ReadCardSerial()) {
  21.         return;
  22.     }
  23.  
  24.   digitalWrite(ledPin, HIGH);
  25.   long code=0;
  26.   for (byte i = 0; i < mfrc522.uid.size; i++)
  27.   {
  28.   code=((code+mfrc522.uid.uidByte[i])*10);
  29.   }
  30.    Serial.println(code);
  31.    delay (2000);
  32.    digitalWrite(ledPin, LOW);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement