Df player mini, can any one help me

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
DFRobotDFPlayerMini mp3(8,9);
int left_trigPin = 7;
int left_echoPin = 6;
int right_trigPin = 2;
int right_echoPin = 3;
int center_trigPin = 4;
int center_echoPin = 5;
void setup() {
pinMode(left_trigPin,OUTPUT);
pinMode(left_echoPin,INPUT);
pinMode(right_trigPin,OUTPUT);
pinMode(right_echoPin,INPUT);
pinMode(center_trigPin,OUTPUT);
pinMode(center_echoPin,INPUT);
Serial.begin(115200);
mp3.begin(9600);
mp3.reset();
mp3.setVolume(50);
mp3.setLoopMode(MP3_LOOP_NONE);
}
void loop(){
left();
right();
center();
}
void left(){
delay(500);// reading will be taken after ....miliseconds
Serial.println("\n");
int duration, distance;
digitalWrite (left_trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (left_trigPin, LOW);
duration = pulseIn (left_echoPin, HIGH);
distance = (duration/2) / 29.1;
//distance= duration*0.034/2;
if (distance < 30) { // Change the number for long or short distances.
Serial.print("Left Distance");
Serial.print(distance);
mp3.playFileByIndexNumber(2);
}
}
void right(){
delay(500);// reading will be taken after ....miliseconds
Serial.println("\n");
int duration, distance;
digitalWrite (right_trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (right_trigPin, LOW);
duration = pulseIn (right_echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <30) { // Change the number for long or short distances.
Serial.print("Right Distance");
Serial.print(distance);
mp3.playFileByIndexNumber(3);
}
}
void center(){
delay(500);// reading will be taken after ....miliseconds
Serial.println("\n");
int duration, distance;
digitalWrite (center_trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (center_trigPin, LOW);
duration = pulseIn (center_echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <30) { // Change the number for long or short distances.
Serial.print("Center Distance");
Serial.print(distance);
mp3.playFileByIndexNumber(1);
}
}

i dont know to solve this code can u help me

What's the problem?
Why is there so much code?
Please remember to use code tags when posting code

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

I had been using this code to combined with arduino uno, 3*us sensor, and df player for object detection to get a output in audio format. simultaneously i am getting the error "Mp3 scope not found"

Please post actual error messages, cut and pasted, with actual line numbers
Do not try to paraphrase error messages.


Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"

In file included from C:\Users\91701\Documents\Arduino\sketch_aug28c\sketch_aug28c.ino:3:0:
C:\Program Files (x86)\Arduino\libraries\DFRobotDFPlayerMini-1.0.5/DFRobotDFPlayerMini.h:44:23: error: expected unqualified-id before numeric constant
#define DFPlayerError 6
^
C:\Users\91701\Documents\Arduino\sketch_aug28c\sketch_aug28c.ino:4:1: note: in expansion of macro 'DFPlayerError'
DFPlayerError mp3(8,9);
^~~~~
C:\Users\91701\Documents\Arduino\sketch_aug28c\sketch_aug28c.ino: In function 'void setup()':
sketch_aug28c:19:3: error: 'mp3' was not declared in this scope
mp3.begin(9600);
^~~
sketch_aug28c:22:19: error: 'MP3_LOOP_NONE' was not declared in this scope
mp3.setLoopMode(MP3_LOOP_NONE);
^~~~~
C:\Users\91701\Documents\Arduino\sketch_aug28c\sketch_aug28c.ino: In function 'void left()':
sketch_aug28c:42:6: error: 'mp3' was not declared in this scope
mp3.playFileByIndexNumber(2);
^~~
C:\Users\91701\Documents\Arduino\sketch_aug28c\sketch_aug28c.ino: In function 'void right()':
sketch_aug28c:57:5: error: 'mp3' was not declared in this scope
mp3.playFileByIndexNumber(3);
^~~
C:\Users\91701\Documents\Arduino\sketch_aug28c\sketch_aug28c.ino: In function 'void center()':
sketch_aug28c:72:5: error: 'mp3' was not declared in this scope
mp3.playFileByIndexNumber(1);
^~~
exit status 1
'mp3' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

@sathu08 Please do as requested and post your full sketch and error messages in code tags as advised in How to get the best out of this forum

You seem to have changed the code from:
DFRobotDFPlayerMini mp3(8, 9);
to
DFPlayerError mp3(8,9);

Is that because you got the error I got?

sketch_aug28b:4:29: error: no matching function for call to 'DFRobotDFPlayerMini::DFRobotDFPlayerMini(int, int)'
 DFRobotDFPlayerMini mp3(8, 9);
                             ^

Looks like you are creating the DFPlayer object incorrectly. This is how it is done in the "GetStarted" example from the DFPlayer library.

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  
  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.volume(10);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int left_trigPin = 7;
int left_echoPin = 6;
int right_trigPin = 2;
int right_echoPin = 3;
int center_trigPin = 4;
int center_echoPin = 5;
void setup() {
pinMode(left_trigPin, OUTPUT);
pinMode(left_echoPin, INPUT);
pinMode(right_trigPin, OUTPUT);
pinMode(right_echoPin, INPUT);
pinMode(center_trigPin, OUTPUT);
pinMode(center_echoPin, INPUT);
Serial.begin(115200);
mySoftwareSerial.begin(9600);
Serial.begin(115200);

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.volume(10);
//myDFPlayer.setLoopMode(myDFPlayer_LOOP_NONE);
}
void loop() {
left();
right();
center();
}
void left() {
delay(500);// reading will be taken after ....miliseconds
Serial.println("\n");
int duration, distance;
digitalWrite (left_trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (left_trigPin, LOW);
duration = pulseIn (left_echoPin, HIGH);
distance = (duration / 2) / 29.1;
//distance= duration*0.034/2;
if (distance < 30) { // Change the number for long or short distances.
Serial.print("Left Distance");
Serial.print(distance);
myDFPlayer.play(2);
}
}
void right() {
delay(500);// reading will be taken after ....miliseconds
Serial.println("\n");
int duration, distance;
digitalWrite (right_trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (right_trigPin, LOW);
duration = pulseIn (right_echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < 30) { // Change the number for long or short distances.
Serial.print("Right Distance");
Serial.print(distance);
myDFPlayer.play(3);
}
}
void center() {
delay(500);// reading will be taken after ....miliseconds
Serial.println("\n");
int duration, distance;
digitalWrite (center_trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (center_trigPin, LOW);
duration = pulseIn (center_echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < 30) { // Change the number for long or short distances.
Serial.print("Center Distance");
Serial.print(distance);
myDFPlayer.play(1);
}
}


I use the above code ...i.,e the three ultra sonic sensor on object detection, the df player mini module will play th mp3 audio file in sd card by speaker...the code seems got verified by arduino software but i dont get an audio output on object detection...(we use us sensor Hc-SRO4,dfplayer mini, ardrino UNO, 5 watt speaker...
kindly any one help me out with this ie,. is there any technical error!

thank you

@sathu08

No code tags again. Why not ?

Still too much code.

(Uncompiled, untested)

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

struct Sensor {
  const byte triggerPin;
  const byte echoPin;
  const byte playFile;
  const char* direction;
} sensors [] = { {7, 6, 2, "Left" },
                      {2, 3, 3, "Right"},
                      {4, 5, 1, "Centre"}};

void setup() 
{
  for (auto& sensor : sensors) {
    pinMode(sensor.triggerPin, OUTPUT);
    digitalWrite (sensor.triggerPin, LOW);
    pinMode (sensor.echoPin, INPUT);
  }
  Serial.begin(115200);
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);

  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.volume(10);
  //myDFPlayer.setLoopMode(myDFPlayer_LOOP_NONE);
}

void loop() 
{
  for (auto& sensor : sensors) {
    delay(500);
    Serial.println("\n");
    digitalWrite (sensor.triggerPin, HIGH);
    delayMicroseconds (10);
    digitalWrite (sensor.triggerPin, LOW);
    uint32_t duration = pulseIn (sensor.echoPin, HIGH);
    uint32_t distance = (duration / 2) / 29.1;
    if (distance < 30) { 
      Serial.print(sensor.direction);
      Serial.print(F(" Distance "));
      Serial.print(distance);
      myDFPlayer.play(sensor.playFile);
    }  
  }
}

Can you get the DFRobotDFPlayerMini library GetStarted example to play the first three seconds of each of your songs? That would prove that the DFPlayerMini was wired correctly and working and that your song files are in the right format.