Skip to content

Instantly share code, notes, and snippets.

@huhn511
Created April 24, 2019 21:22
Show Gist options
  • Save huhn511/d49c0e382468b1fb73e7d03771f140c5 to your computer and use it in GitHub Desktop.
Save huhn511/d49c0e382468b1fb73e7d03771f140c5 to your computer and use it in GitHub Desktop.
ESP8266 RFID Example with MF522 Reader
#include "MFRC522.h"
#define RST_PIN 0
#define SS_PIN 15
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment