Hi guys
I am making a prop for an Escape Room which involves a RC522 RFID scanner and MP3.
I have everything working apart from the reader is constantly reading the tag and restarting the MP3 without a full play through.
I am using the below code and have tried a few things to stop the multi read but not had much luck.
I must say this is only my 2nd project having never coded before.
Any help would be very appreciated.
#include <Arduino.h>
#include <DFRobotDFPlayerMini.h>//library for DFplayer
#include <SoftwareSerial.h>
#include <MFRC522.h>
#include <SPI.h>
#define SDA_Pin 10//Define SDA Pin in digital pin 10
#define RST_Pin 9//Define Reset Pin in digital pin 9
char* instrumentUIDs[] = {"57 95 A8 60"};
SoftwareSerial mySoftwareSerial(6, 7); // RX, TX Arduino
MFRC522 MFRC(SDA_Pin , RST_Pin); //Create Instance for MFRC522
DFRobotDFPlayerMini myDFplayer; //Create DFPlayer Instance/Object
void setup(){
mySoftwareSerial.begin(9600); //DFPlayer Initialization
Serial.begin(115200);//Initialize Serial Communication
SPI.begin();//Initialize SPI bus
MFRC.PCD_Init();//Initialize MFRC522
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFplayer.begin(mySoftwareSerial))
{
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true) //Incase DFPlayer Failed, it wont start at all.
{
delay(0);
}
}
Serial.println(F("DFPlayer Mini online."));
myDFplayer.play(001); //Startup MP3
Serial.println("Insert Your Card.......");
Serial.println();
}
void loop(){
if ( ! MFRC.PICC_IsNewCardPresent()) {
Serial.println("No Card");
return;
}
if ( ! MFRC.PICC_ReadCardSerial()) {
return;
}
if ( ! MFRC.PICC_IsNewCardPresent()) { // ****************
ObjectTagChecker();
}
MFRC.PICC_HaltA(); // Halt PICC
MFRC.PCD_StopCrypto1();
}
//To Show the UID on Serial Monitor
void ObjectTagChecker() {
String content= "";
byte letter;
for (byte i = 0; i < MFRC.uid.size; i++)
{
Serial.print(MFRC.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(MFRC.uid.uidByte[i], HEX);
content.concat(String(MFRC.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(MFRC.uid.uidByte[i], HEX));
}
for (int i = 0; i < (sizeof(instrumentUIDs)/2); i++) {
if (content.substring(1) == instrumentUIDs[i]) {
Serial.print("Card Present: Item number ");
Serial.print(i);
Serial.println(" has been selected");
}
}
Serial.println("Access Granted");
Serial.println();
myDFplayer.play(005); //Access Granted MP3 File
}`Preformatted text`