stevie135s
Published © GPL3+

Android DFPlayer Mini Bluetooth control

Android app controlled DFPlayer Mini using esp32 Wroom

BeginnerFull instructions provided7,045
Android DFPlayer Mini Bluetooth control

Things used in this project

Hardware components

Arduino esp32 WROOM32
×1
DF Player using TF Card
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Folder Version

Download and install on Android Phone

Schematics

Circuit

This will work just fine

Code

Folder Version

Arduino
Flash the esp32 using arduino IDE
#include <BluetoothSerial.h>
#include <Arduino.h>
#include <DFRobotDFPlayerMini.h>
DFRobotDFPlayerMini myDFPlayer;


BluetoothSerial SerialBT;

#define BT_DISCOVER_TIME	10000
int action = 0;
int Song = 0;
static bool btScanAsync = true;
static bool btScanSync = true;

void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) {
	Serial.printf("Found a device asynchronously: %s\n", pDevice->toString().c_str());
}

void setup() {
 Serial2.begin(9600);
 Serial.begin(115200);
  if (!myDFPlayer.begin(Serial2)) {  //Serial2 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); //Set serial communictaion time out 500ms
  
  SerialBT.begin("ESP32"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");


  if (btScanAsync) {
    Serial.print("Starting discoverAsync...");
    if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) {
      Serial.println("Findings will be reported in \"btAdvertisedDeviceFound\"");
      delay(10000);
      Serial.print("Stopping discoverAsync... ");
      SerialBT.discoverAsyncStop();
      Serial.println("stopped");
    } else {
      Serial.println("Error on discoverAsync f.e. not workin after a \"connect\"");
    }
  }
  
  if (btScanSync) {
    Serial.println("Starting discover...");
    BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME);
    if (pResults)
      pResults->dump(&Serial);
    else
      Serial.println("Error on BT Scan, no result!");
  }
  myDFPlayer.volume(10);
}

void loop() {
  action = SerialBT.read();
  if (action != -1) {
 Serial.println (action);    //Print what we receive 

    switch (action) {
      case 1:
       myDFPlayer.previous();  //Play previous mp3
       break;
       
       case 2:
       myDFPlayer.pause(); //Stop
       Song = 0;
       break;
       
       case 3:  
       if (Song == 0) {
        myDFPlayer.play(1);  //Play from beginning  
        myDFPlayer.enableLoopAll();
        Song = 1;     
       }
       else {
        myDFPlayer.start(); //Play from Pause
        myDFPlayer.disableLoopAll();
       }
       break;
       
       case 4:
       myDFPlayer.pause(); //Pause
       break;
       
       case 5:
       myDFPlayer.next(); //Next
       break;
       
       case 6:
       myDFPlayer.volumeDown(); //Volume +
       break;
       
       case 7:
       myDFPlayer.volumeUp(); //Volume -
       break;

       case 8:
       myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
       break;

       case 9:
       myDFPlayer.EQ(DFPLAYER_EQ_POP);
       break;

       case 10:
       myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
       break;

       case 11:
       myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
       break;

       case 12:
       myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
       break;

       case 13:
       myDFPlayer.EQ(DFPLAYER_EQ_BASS);
       break;

       case 14:
       myDFPlayer.loopFolder(1);
       break;

       case 15:
       myDFPlayer.loopFolder(2);
       break; 
           
       case 16:
       myDFPlayer.loopFolder(3);
       break;
       
       case 17:
       myDFPlayer.loopFolder(4);
       break;
       
       case 18:
       myDFPlayer.loopFolder(5);
       break; 

       case 19:
       myDFPlayer.loopFolder(6);
       break; 

       case 20:
       myDFPlayer.loopFolder(7);
       break;

       case 21:
       myDFPlayer.loopFolder(8);
       break;
       
       case 22:
       myDFPlayer.loopFolder(9);
       break;

       case 23:
       myDFPlayer.loopFolder(10);
       break; 
                      
    }
    
  }
  }

Credits

stevie135s

stevie135s

25 projects • 11 followers

Comments