// This #include statement was automatically added by the Particle IDE.
#include <MFRC522.h> // Library for the RFID reader
#define SS_PIN SS // pins for RFID
#define RST_PIN D2 // pins for RFID
MFRC522 myRFID(SS_PIN, RST_PIN); // Create MFRC522 instance.
String id = "";
String data_sent = "";
void setup() {
// Initialize serial communications with the computer
Serial.begin(9600);
myRFID.setSPIConfig(); // sets up SPI config
myRFID.PCD_Init(); // Initialize RC522 card
Serial.println("Start Scanning");
}
void loop() {
// Look for new cards
if ( ! myRFID.PICC_IsNewCardPresent()) {
return;
}
// Read tapped card data
if ( ! myRFID.PICC_ReadCardSerial()) {
return;
}
for (byte i = 0; i < myRFID.uid.size; i++) {
// Create a RFID Hexdecimal String by adding and converting the binary
id += String(myRFID.uid.uidByte[i], HEX);
}
id.toUpperCase(); // Convert to Uppercase
// Print the RFID identifier to the Serial Port
Serial.print(id);
// If it is this card,
if (id == "AB6E3E7E") { //call mom!
data_sent = "soonish";
Particle.publish("call_mom", data_sent, PRIVATE);
}
if (id == "BFC3D7E") { //remember something at home!
data_sent = "remember_me";
Particle.publish("at_home", data_sent, PRIVATE);
}
if (id == "5BF43E7E") { //draft and email!
data_sent = "send_mail";
Particle.publish("email_at_work", data_sent, PRIVATE);
}
// Reset Id
id = "";
Serial.println();
// Stop the reading after one tap
myRFID.PICC_HaltA();
/* Used to exit the PCD from its authenticated state. Remember to call this function after
communicating with an authenticated PICC - otherwise no new communications can
start .*/
myRFID.PCD_StopCrypto1();
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .