#include #include #include #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above #define RX_PIN 2 // HC-05 RX pin #define TX_PIN 3 // HC-05 TX pin MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance SoftwareSerial bluetoothSerial(RX_PIN, TX_PIN); // Create SoftwareSerial instance void setup() { Serial.begin(9600); // Initialize serial communications with the PC bluetoothSerial.begin(9600); // Initialize Bluetooth serial communications SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 card Serial.println(F("Read personal data on a MIFARE PICC:")); // Shows in serial that it is ready to read } void loop() { // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory. MFRC522::MIFARE_Key key; for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF; // Some variables we need byte block; byte len; MFRC522::StatusCode status; // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. if (!mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if (!mfrc522.PICC_ReadCardSerial()) { return; } Serial.println(F("**Card Detected:**")); mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); // Dump some details about the card Serial.print(F("Name: ")); byte buffer1[18]; block = 4; len = 18; // Get Item Name status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); if (status != MFRC522::STATUS_OK) { Serial.print(F("Authentication failed: ")); Serial.println(mfrc522.GetStatusCodeName(status)); return; } status = mfrc522.MIFARE_Read(block, buffer1, &len); if (status != MFRC522::STATUS_OK) { Serial.print(F("Reading failed: ")); Serial.println(mfrc522.GetStatusCodeName(status)); return; } // Print Item Name for (uint8_t i = 0; i < 16; i++) { if (buffer1[i] != 32) { Serial.write(buffer1[i]); bluetoothSerial.write(buffer1[i]); } } Serial.print(" "); bluetoothSerial.print(" "); // Get Tag Number byte buffer2[18]; block = 1; status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); if (status != MFRC522::STATUS_OK) { Serial.print(F("Authentication failed: ")); Serial.println(mfrc522.GetStatusCodeName(status)); return; } status = mfrc522.MIFARE_Read(block, buffer2, &len); if (status != MFRC522::STATUS_OK) { Serial.print(F("Reading failed: ")); Serial.println(mfrc522.GetStatusCodeName(status)); return; } // Print Tag Number for (uint8_t i = 0; i < 16; i++) { Serial.write(buffer2[i]); bluetoothSerial.write(buffer2[i]); } Serial.println(F("\n**End Reading**\n")); delay(1000); // Change value if you want to read cards faster mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); }