DF mini player integrating with arduino uno

Does anybody knows how to play 2 mp3s in same code using Df mini mp3 player module, Cause my module only plays one mp3 twice

Please post your code following the advice in How to get the best out of this forum

1 Like
 if (rfidCard == "53 05 79 37 02 85 00") {
      // Play the first MP3 file on the SD card
     Serial.println("Playing 0001.mp3");
     digitalWrite(LED_PIN, HIGH);
     delay(200);
     digitalWrite(LED_PIN, LOW);
     myDFPlayer.stop();  
  //   myDFPlayer.start();          
     myDFPlayer.play("0001.mp3");   //Play the first mp3
     delay(10000); 
     //myDFPlayer.loop(1); 
     //Blinking the LED
     digitalWrite(LED_PIN, HIGH);
     delay(200);
     digitalWrite(LED_PIN, LOW);
     myDFPlayer.stop();
     //myDFPlayer.pause(); 
  } 
  else if (rfidCard == "53 C5 1D 3F 02 1D 00"){
     Serial.println("Playing 0002.mp3");
     digitalWrite(LED_PIN, HIGH);
     delay(200);
     digitalWrite(LED_PIN, LOW);
     // Play the second MP3 file on the SD card
     myDFPlayer.stop();
  //   myDFPlayer.start();
     myDFPlayer.play("0002.mp3");  //Play the second mp3
     //myDFPlayer.loop(2); 
     delay(10000); 
     //Blinking the LED
     digitalWrite(LED_PIN, HIGH);
     delay(200);
     digitalWrite(LED_PIN, LOW);
     myDFPlayer.stop();
     //myDFPlayer.next(1);
    // myDFPlayer.pause();  
  }

And the rest of your code ?

For instance, what data type is rfidCard and how do you set its value ?

The whole code cannot be submitted to the forum because Im new to the platform, To get you and idea of the project. In this project
The aim is to play different mp3s to certain certain rfid tags. RFID tag reading sensor is used for this task. But the problem is only the first mp3 plays though other mp3s are assigned to play. I appreciate your help in this.

OK, so how about the specific question about the data type of rfidCard and how its value is set ?

The data type is string and the value is set according to previous decided values of rfid tags

Do you mean a string (a zero terminated array of chars) or a String ( an object created using the String library) ?

Have you tried printing the value of rfidCard before testing it ?
If not then do it now. Print “>” immediately before it and “<” immediately after it so that you can see any leading or trailing spaces or control characters

Do you see the values that you expect ?

Yeah the problem is not in the rfid, I see the tags been read correctly. But it only plays the same mp3.

When it plays the wrong file what messages do you see in the Serial monitor ?

A suggestion. Hard code the value of rfidCard to match the second card ID just before you test it. Does the correct file play ?

No it it identifies the second rfid goes inside the if else case and plays the first mp3 only. Thats the probelm

Have you by any chance got more than one variable named rfidCard in your sketch ?

What message does the forum software give you if you try to post your code here ?

Sorry, new users can only put 2 links in a post. this is the message they are displaying

You have a PM

The OPs full code

//#include <DFPlayerMini_Fast.h>

//Including the relevant libraries
#include <SPI.h>
#include <RFID.h>
//#include "SoftwareSerial.h"
#include <DFPlayerMini_Fast.h>

#if !defined(UBRR1H)
#include <SoftwareSerial.h>
SoftwareSerial mySoftwareSerial(3, 2); // RX, TX
#endif


//Defining the pins for SS and RST in RFID TAG.
#define SS_PIN 10
#define RST_PIN 9
//Initializing the pins with help of RFID library
RFID rfid(SS_PIN, RST_PIN);
//Declaring the pin for the LED bulb wused
int LED_PIN = 5;

// Create the Player object
DFPlayerMini_Fast player;

//Declaring the function for the RFID work.
void RFID_function();

// Use pins 2 and 3 to communicate with DFPlayer Mini

DFPlayerMini_Fast myDFPlayer;
void printDetail(uint8_t type, int value);

String rfidCard;

void setup()
{
  // Init serial port for DFPlayer Mini
  mySoftwareSerial.begin(9600);
  // Init USB serial port for debugging
  Serial.begin(115200);
  Serial.println("Starting the RFID Reader...");
  //Starting the RFID
  //configure pin 7 as an input and enable the internal pull-up resistor
  pinMode(7, INPUT_PULLUP);
  SPI.begin();
  rfid.init();
  //Declaring the nature of the pin which is and LED so its declared as an output
  pinMode(LED_PIN, OUTPUT);
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  if (!myDFPlayer.begin(mySoftwareSerial))    //Use softwareSerial to communicate with mp3.
  {
    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)
    {
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));
  //  myDFPlayer.setTimeOut(500);
  myDFPlayer.volume(30);  //Set volume value. From 0 to 30
  //myDFPlayer.play(1);  //Play the first mp3
  // myDFPlayer.start();
  //  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
}

void loop()
{
  //read the pushbutton value into a variable
  //  if (myDFPlayer.available()) {
  //  printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  // }
  int Button_val = digitalRead(7);
  //print out the value of the pushbutton
  Serial.println(Button_val);
  // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
  // HIGH when it's open, and LOW when it's pressed.
  // button's pressed, and off when it's not:
  if (Button_val == HIGH)
  {
    Serial.println(" Button Not Pressed Cant Proceed further");
    digitalWrite(LED_PIN, HIGH);//If a tag is not matched then LED is on
    delay(500);
  }
  else
  {
    Serial.println("Button Pressed");
    Serial.println("Processing the RFID functions");
    delay(500);
    RFID_function();
  }
}

void RFID_function()
{
  //Reading the RFID
  if (rfid.isCard())
  {
    if (rfid.readCardSerial())
    {
      rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]) + " " + String(rfid.serNum[4]) + " " + String(rfid.serNum[5]) + " " + String(rfid.serNum[6]);
      Serial.println(rfidCard);
      //Matching the RFID according to their tag.
      if (rfidCard == "53 05 79 37 02 85 00")
      {
        // Play the first MP3 file on the SD card
        Serial.println("Playing 0001.mp3");
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        //   myDFPlayer.start();
        myDFPlayer.play("0001.mp3");   //Play the first mp3
        delay(10000);
        //myDFPlayer.loop(1);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        //myDFPlayer.pause();
      }
      else if (rfidCard == "53 C5 1D 3F 02 1D 00")
      {
        Serial.println("Playing 0002.mp3");
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the second MP3 file on the SD card
        myDFPlayer.stop();
        //   myDFPlayer.start();
        myDFPlayer.play("0002.mp3");  //Play the second mp3
        //myDFPlayer.loop(2);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        //myDFPlayer.next(1);
        // myDFPlayer.pause();
      }
      else if (rfidCard == "53 15 38 3D 02 DA 00")
      {
        Serial.println("Playing 0003.mp3");
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        /// Play the second MP3 file on the SD card
        myDFPlayer.stop();
        //    myDFPlayer.start();
        myDFPlayer.play("0003.mp3");  //Play the second mp3
        //myDFPlayer.loop(3);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the third MP3 file on the SD card
        // myDFPlayer.next();
        myDFPlayer.stop();
        //myDFPlayer.pause();
      }
      else if (rfidCard == "53 55 3C 35 02 B5 00")
      {
        Serial.println("Playing 0004.mp3");
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the second MP3 file on the SD card
        myDFPlayer.stop();
        //    myDFPlayer.start();
        myDFPlayer.play(4);  //Play the second mp3
        // myDFPlayer.loop(4);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        // myDFPlayer.pause();
      }
      else if (rfidCard == "53 C4 7D 3D 02 55 00")
      {
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the second MP3 file on the SD card
        // myDFPlayer.stop();
        //myDFPlayer.start();
        myDFPlayer.play(5);  //Play the second mp3
        // myDFPlayer.loop(5);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        //myDFPlayer.pause();
      }
      else if (rfidCard == "53 05 5C 96 02 61 00")
      {
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the second MP3 file on the SD card
        myDFPlayer.stop();
        //      myDFPlayer.start();
        myDFPlayer.play(6);  //Play the second mp3
        //myDFPlayer.loop(6);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        // myDFPlayer.pause();
      }
      else if (rfidCard == "53 9D 09 9E 02 11 00")
      {
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the second MP3 file on the SD card
        myDFPlayer.stop();
        //    myDFPlayer.start();
        myDFPlayer.play(7);  //Play the second mp3
        //myDFPlayer.loop(7);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the seventh MP3 file on the SD card
        // myDFPlayer.next();
        myDFPlayer.stop();
        // myDFPlayer.pause();
      }
      else if (rfidCard == "53 CD 09 B6 02 01 00")
      {
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the second MP3 file on the SD card
        myDFPlayer.stop();
        //   myDFPlayer.start();
        myDFPlayer.play(8);  //Play the second mp3
        //myDFPlayer.loop(8);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the eighth MP3 file on the SD card
        // player.play(8);
        myDFPlayer.stop();
        //myDFPlayer.pause();
      }
      else if (rfidCard == "53 54 58 9E 02 0E 00")
      {
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        // Play the second MP3 file on the SD card
        //         myDFPlayer.start();
        myDFPlayer.play(9);  //Play the second mp3
        // myDFPlayer.loop(9);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        // Play the nineth MP3 file on the SD card
        //player.play(9);
        myDFPlayer.stop();
        //myDFPlayer.pause();
      }
      else if (rfidCard == "53 1C 69 B4 02 B6 00")
      {
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        // Play the second MP3 file on the SD card
        //          myDFPlayer.start();
        myDFPlayer.play(10);  //Play the second mp3
        //myDFPlayer.loop(10);
        delay(10000);
        //Blinking the LED
        digitalWrite(LED_PIN, HIGH);
        delay(200);
        digitalWrite(LED_PIN, LOW);
        myDFPlayer.stop();
        //myDFPlayer.pause();
      }
      else
      {
        digitalWrite(LED_PIN, HIGH);//If a tag is not matched then LED is on
      }
    }
    rfid.halt();
  }
  delay(1000);//If you need to make the process fast please remove the delays.
}

Can I know the changes you’ve made to the code.

All I did was to Auto format it in the IDE with my formatting settings. The contents and logic of the sketch were not changed, just the layout

To be clear, you say that if you do this

      rfidCard = "53 C5 1D 3F 02 1D 00";
      //Matching the RFID according to their tag.
      if (rfidCard == "53 05 79 37 02 85 00")
      {
        // Play the first MP3 file on the SD card
//etc, etc

then the code plays the first file ?
What messages do you see printed ?


Here it is

I am not clear what “it” is

The warning/error messages seem to indicate that the play() function is expecting an int to be passed to it, not the actual name of the track

The integer was also passed to play function, But it also gave the same result that s why I tried this method