Skip to content

Instantly share code, notes, and snippets.

@suhajdab
Last active March 27, 2022 16:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save suhajdab/f4c473ad25654e76fc16 to your computer and use it in GitHub Desktop.
Save suhajdab/f4c473ad25654e76fc16 to your computer and use it in GitHub Desktop.
Particle Photon + RC522 RFID implant reader
#include "MFRC522/MFRC522.h"
/*
Function Core Pin MRFC522 Pin
Reset D2 RST
SPI SS D1 SDA
SPI MOSI A5 MOSI
SPI MISO A4 MISO
SPI SCK A3 SCK
*/
#define SS_PIN D1
#define RST_PIN D2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
mfrc522.setSPIConfig();
mfrc522.PCD_Init(); // Init MFRC522 card
RGB.control(true); // take control of onboard RGB led
}
void blink() {
RGB.color(0, 0, 255);
delay(150);
RGB.color(0, 0, 0);
delay(100);
RGB.color(0, 0, 255);
delay(150);
RGB.color(0, 0, 0);
}
void loop() {
// Look for new cards
if ( mfrc522.PICC_IsNewCardPresent()) {
// Serial.println("New card present...");
if ( mfrc522.PICC_ReadCardSerial()) {
// Dump debug info about the card. PICC_HaltA() is automatically called.
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
String UID = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
UID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
UID += String(mfrc522.uid.uidByte[i], HEX);
}
mfrc522.PICC_HaltA();
Serial.print("UID: ");
Serial.println(UID);
Particle.publish("rfid-read", UID, 5, PRIVATE); // publish UID to rest of system
blink(); // visual feedback of read using onboard led
}
}
}
@tywalch
Copy link

tywalch commented May 20, 2017

Stripped down, thank you for posting this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment