Skip to content

Instantly share code, notes, and snippets.

@robertcedwards
Forked from suhajdab/rfid-node.ino
Created August 14, 2016 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertcedwards/c9e7d0c6a9571901ca96139e9a607867 to your computer and use it in GitHub Desktop.
Save robertcedwards/c9e7d0c6a9571901ca96139e9a607867 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
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment