Error with DFPlayer mini

Hi, I'm creating a plant vase who speaks when you walk in front of it, i'm having problems with the instructions who should make the vase talk.
when i type mp3.play(x) it doesn't produce any sound and when i type mp3.next() it produce a part of the 2 audio track and after a small amount of time it produce a small part of the consecutive audio. i tried to use the example with the DFPlayer mini library but it doesn't work.
any ideas?

Post your code.
In code tags

And your wiring circuit, please.

#include "DFRobotDFPlayerMini.h"
#include"Arduino.h"
#include"SoftwareSerial.h"
#define TRIG_PIN 12 //pin rilevatore ultrasuoni
#define ECHO_PIN 8 //pin rilevatore ultrasuoni

int BOTTONE = 13; //pin bottone
int Led_v = 5; // pin led verde
int Led_r = 4; // pin led rosso
int giorno = 0; //variabile per il primo ciclo
int stato_bottone=0; //stato del bottone premuto o non premuto
int minuto = 0; // variabile per il secondo ciclo

SoftwareSerial ss(10,11); //inizializzazione pin per mp3
DFRobotDFPlayerMini mp3; //inizializzazione mp3

void setup() {
pinMode(Led_v, OUTPUT);
digitalWrite(Led_v,LOW);
pinMode(Led_r, OUTPUT);
digitalWrite(Led_r,LOW);
pinMode(BOTTONE, INPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
digitalWrite(TRIG_PIN,LOW);

Serial.begin(9600);
ss.begin(9600);
Serial.println("inizio");
if(!mp3.begin(ss)){ //controllo se mp3 va
Serial.println("controlla cavi");
while(true);
}
Serial.println("programma iniziato");//se appare nel monitore seriale funziona l'mp3
mp3.volume(20);
}

void loop() {
digitalWrite(Led_v,HIGH); //led che indica che ha bevuto si accende
digitalWrite(Led_r,LOW);
delay(7000); //aspetta che la pianta abbia sete 518400 6 giormni
digitalWrite(Led_r,HIGH); // led che indica che ha sete si accende
digitalWrite(Led_v, LOW); // led che indica che sta bene si spegne

Ciclo_1: //ritorna qua se non viene rilevata nessuna persona

for(giorno=0;giorno<60000;giorno=giorno+1){ //inizio ciclo controllo movimento 86400 2 minuti ora 30 secondi
delay(1);
digitalWrite(TRIG_PIN,HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN,LOW);
unsigned long tempo = pulseIn(ECHO_PIN,HIGH);
float distanza = 0.0348 * tempo / 2;
Serial.println("distanza:"+String(distanza)+"cm");//scrive distanza sul monitor seriale
if(distanza<20){
goto bere;} //se rileva movimento esce anticipatamente dal ciclo
}

mp3.play(2); //dice di aver sete senza movimento
Serial.println("ho sete, c'è nessuno?");
digitalWrite(2,HIGH);
delay(6000);
digitalWrite(2,LOW);
goto Ciclo_1; // torna prima del ciclo

bere: //movimento rilevato
mp3.play(1); //chiede al passante di dare da bere
delay(2000);
Serial.println("hey tu,dammi da bere");
digitalWrite(3,HIGH);
for(minuto=0;minuto<16000;minuto=minuto+1){ //secondo ciclo
delay(1);
stato_bottone=digitalRead(BOTTONE); //leggi se bottone è premuto o no
if (stato_bottone==HIGH)
{
Serial.println("bottone premuto");
goto ringrazia; //bottone premuto
}
}
goto bere; //bottone non premuto torna a prima del 2 ciclo

ringrazia:
digitalWrite(3,LOW);
digitalWrite(6,HIGH);
delay(2000);
digitalWrite(6,LOW);
digitalWrite(Led_v,HIGH); //led che indica che ha bevuto si accende
digitalWrite(Led_r,LOW); //led che indica che ha sete si spegne
mp3.volume(15);
mp3.play(3); //ringrazia per l'acqua
Serial.println("grazie per l'acqua");
} //ricomincia
sorry, i am new on this platform, i'm not allowed to post photos of the content of the SD card or the wirings
i read about other guys having problems with the DFPlayermini, i can garantee i have named every file like this 0001.mp3, 0002.mp3, 0003.mp3 and the SD card has been format in fat32

1 Like

So you've got a lot going on with the code, and I think that's where your problem lies. Remember that DELAY is a blocking function and stops all commands in the program, so not the best use of it in a program where we want to mix LED lighting and DF Mini Player MP3 sounds. You need to rewrite using Millis timing. Study the Blink Without Delay example to learn.
Also this line:
delay(1);

Delays need to be longer than 1 millisecond.

And:
digitalWrite(3,LOW);
digitalWrite(6,HIGH);

Those two pins are nowhere in your sketch.

Please remember to use code tags when you post code. They are the </> symbol in the posting area,

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.