Hi,
Spent a lot of time researching why this happens but can’t seem to figure out.
Issue: All I want to achieve is for the DFPlayer to play an mp3 when the button is pressed.
Current status: Every button press automatically moves to playing the next mp3 track. Also, there’s no action when I remove the mp3_next(); function or the delay which is even more weird!!
Please help!
Code:
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "B36@2.4G_Ext";
char pass[] = "9686535411";
char auth[] = "05815e4be7254709aa3b23e6e033f8fe";
static int flag1 = 0;
SoftwareSerial mySerial(D1, D3); // RX, TX
BLYNK_WRITE(V4){
if (param.asInt()){
Serial.println("Direction is forward ");
flag1 =1;
}
}
void setup () {
Serial.begin (115200);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (15);
Blynk.begin(auth, ssid, pass);
}
//
void loop () {
Blynk.run();
if (1==flag1)
{
mp3_play (3);
delay (2000);
mp3_next ();
// delay (2000);
flag1 = 0;
}
}
'''
- Lose the static int. Just declare it as a bool (it’ll save some space too).
- Get rid of everything but Blynk.run() in the loop(). Loop gets executed thousands of times per second.
- No delays!!!
- No delays!!!
Check out the PushData example to see how you can run a timed procedure as not to clogg up all the CPU from Blynk.
-edit
And do the if(flag1 == 1) < better readability 
Thanks for that quick response…
a. Agree…got rid of that…
b. If I were to lose everything in the loop(), I would have to check for the flag in the BLYNK_WRITE(V4) proc…alternatively, I removed all of the flag stuff and just called the mp3_play() from the BLYNK_WRITE(V4)…this doesn’t work…
c. Yep…I’ve read this several times but for some strange reason my code doesn’t work without this and hence the inclusion.
d. 
As for the PushData example, it seem that in this case, we are attempting to push data from the Arduino /MC to Blynk…I believe I’m doing the converse…
Removed the flag check altogether and thanks for the readability tip…
Regards
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxx";
char pass[] = "yyyy";
char auth[] = "abcd";
//bool int flag1 = 0;
SoftwareSerial mySerial(D1, D3); // RX, TX
BLYNK_WRITE(V4){
if (param.asInt()){
Serial.println("Direction is forward ");
mp3_play (3);
}
}
void setup () {
Serial.begin (115200);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (15);
Blynk.begin(auth, ssid, pass);
}
//
void loop () {
//static int i=1;
Blynk.run();
}
Does it print the serial.println when you push V4 on the App? That’ll indicate if it’s working. If it does the serial.println it probably is something else in the connection or whatnot.
What happens if you attach the MP3 module to a usb-serial convertor? Do you happen to have one handy so you can confirm the MP3 player works withouth Blynk or the Arduino?
Yes the serial print is printing out the text indicating that its working…the real issue is this DFPlayer function mp3_play() that seems to be the cluprit…
Even independently, it seems to need a next() and the delay() functions…
Can’t seem to find too many folks who have tried this combination of WeMos + DFPlayer Mini…
I still need to order one for a doorbell project, but I’m between houses at the moment so I dare not order from China at this moment.
You can simulate a delay with the timer.setTimeout() function.