microrobotics icon

Arduino interfaced with RC522

microrobotics | PRO | 08/30/24 06:10:46 AM UTC | 0 ⭐ | 15404 👁️ | Never ⏰ | []
Arduino |

980 B

|

None

|

0 👍

/

0 👎

#include <SPI.h>
#include <MFRC522.h>
 
#define SS_PIN 10  // SDA pin
#define RST_PIN 9  // RST pin
 
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
 
void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin();        // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522
  Serial.println("Scan an RFID tag...");
}
 
void loop() {
  // 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 :");
  String content = "";
  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();
  delay(1000);
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎