Android DFPlayer Mini Bluetooth control
Android app controlled DFPlayer Mini using esp32 Wroom
Components and supplies
1
DF Player using TF Card
1
DFPlayer - A Mini MP3 Player
1
esp32 WROOM32
Apps and platforms
1
Arduino IDE
Project description
Code
Folder Version
arduino
Flash the esp32 using arduino IDE
1#include <BluetoothSerial.h> 2#include <Arduino.h> 3#include <DFRobotDFPlayerMini.h> 4DFRobotDFPlayerMini myDFPlayer; 5 6 7BluetoothSerial SerialBT; 8 9#define BT_DISCOVER_TIME 10000 10int action = 0; 11int Song = 0; 12static bool btScanAsync = true; 13static bool btScanSync = true; 14 15void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) { 16 Serial.printf("Found a device asynchronously: %s\ 17", pDevice->toString().c_str()); 18} 19 20void setup() { 21 Serial2.begin(9600); 22 Serial.begin(115200); 23 if (!myDFPlayer.begin(Serial2)) { //Serial2 to communicate with mp3. 24 Serial.println(F("Unable to begin:")); 25 Serial.println(F("1.Please recheck the connection!")); 26 Serial.println(F("2.Please insert the SD card!")); 27 while(true); 28 delay(0); // Code to compatible with ESP8266 watch dog. 29 } 30 Serial.println(F("DFPlayer Mini online.")); 31 32 myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms 33 34 SerialBT.begin("ESP32"); //Bluetooth device name 35 Serial.println("The device started, now you can pair it with bluetooth!"); 36 37 38 if (btScanAsync) { 39 Serial.print("Starting discoverAsync..."); 40 if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) { 41 Serial.println("Findings will be reported in \\"btAdvertisedDeviceFound\\""); 42 delay(10000); 43 Serial.print("Stopping discoverAsync... "); 44 SerialBT.discoverAsyncStop(); 45 Serial.println("stopped"); 46 } else { 47 Serial.println("Error on discoverAsync f.e. not workin after a \\"connect\\""); 48 } 49 } 50 51 if (btScanSync) { 52 Serial.println("Starting discover..."); 53 BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME); 54 if (pResults) 55 pResults->dump(&Serial); 56 else 57 Serial.println("Error on BT Scan, no result!"); 58 } 59 myDFPlayer.volume(10); 60} 61 62void loop() { 63 action = SerialBT.read(); 64 if (action != -1) { 65 Serial.println (action); //Print what we receive 66 67 switch (action) { 68 case 1: 69 myDFPlayer.previous(); //Play previous mp3 70 break; 71 72 case 2: 73 myDFPlayer.pause(); //Stop 74 Song = 0; 75 break; 76 77 case 3: 78 if (Song == 0) { 79 myDFPlayer.play(1); //Play from beginning 80 myDFPlayer.enableLoopAll(); 81 Song = 1; 82 } 83 else { 84 myDFPlayer.start(); //Play from Pause 85 myDFPlayer.disableLoopAll(); 86 } 87 break; 88 89 case 4: 90 myDFPlayer.pause(); //Pause 91 break; 92 93 case 5: 94 myDFPlayer.next(); //Next 95 break; 96 97 case 6: 98 myDFPlayer.volumeDown(); //Volume + 99 break; 100 101 case 7: 102 myDFPlayer.volumeUp(); //Volume - 103 break; 104 105 case 8: 106 myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); 107 break; 108 109 case 9: 110 myDFPlayer.EQ(DFPLAYER_EQ_POP); 111 break; 112 113 case 10: 114 myDFPlayer.EQ(DFPLAYER_EQ_ROCK); 115 break; 116 117 case 11: 118 myDFPlayer.EQ(DFPLAYER_EQ_JAZZ); 119 break; 120 121 case 12: 122 myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC); 123 break; 124 125 case 13: 126 myDFPlayer.EQ(DFPLAYER_EQ_BASS); 127 break; 128 129 case 14: 130 myDFPlayer.loopFolder(1); 131 break; 132 133 case 15: 134 myDFPlayer.loopFolder(2); 135 break; 136 137 case 16: 138 myDFPlayer.loopFolder(3); 139 break; 140 141 case 17: 142 myDFPlayer.loopFolder(4); 143 break; 144 145 case 18: 146 myDFPlayer.loopFolder(5); 147 break; 148 149 case 19: 150 myDFPlayer.loopFolder(6); 151 break; 152 153 case 20: 154 myDFPlayer.loopFolder(7); 155 break; 156 157 case 21: 158 myDFPlayer.loopFolder(8); 159 break; 160 161 case 22: 162 myDFPlayer.loopFolder(9); 163 break; 164 165 case 23: 166 myDFPlayer.loopFolder(10); 167 break; 168 169 } 170 171 } 172 } 173
Folder Version
arduino
Flash the esp32 using arduino IDE
1#include <BluetoothSerial.h> 2#include <Arduino.h> 3#include <DFRobotDFPlayerMini.h> 4DFRobotDFPlayerMini 5 myDFPlayer; 6 7 8BluetoothSerial SerialBT; 9 10#define BT_DISCOVER_TIME 10000 11int 12 action = 0; 13int Song = 0; 14static bool btScanAsync = true; 15static bool btScanSync 16 = true; 17 18void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) { 19 Serial.printf("Found 20 a device asynchronously: %s\ 21", pDevice->toString().c_str()); 22} 23 24void 25 setup() { 26 Serial2.begin(9600); 27 Serial.begin(115200); 28 if (!myDFPlayer.begin(Serial2)) 29 { //Serial2 to communicate with mp3. 30 Serial.println(F("Unable to begin:")); 31 32 Serial.println(F("1.Please recheck the connection!")); 33 Serial.println(F("2.Please 34 insert the SD card!")); 35 while(true); 36 delay(0); // Code to compatible 37 with ESP8266 watch dog. 38 } 39 Serial.println(F("DFPlayer Mini online.")); 40 41 42 myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms 43 44 45 SerialBT.begin("ESP32"); //Bluetooth device name 46 Serial.println("The 47 device started, now you can pair it with bluetooth!"); 48 49 50 if (btScanAsync) 51 { 52 Serial.print("Starting discoverAsync..."); 53 if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) 54 { 55 Serial.println("Findings will be reported in \\"btAdvertisedDeviceFound\\""); 56 57 delay(10000); 58 Serial.print("Stopping discoverAsync... "); 59 SerialBT.discoverAsyncStop(); 60 61 Serial.println("stopped"); 62 } else { 63 Serial.println("Error 64 on discoverAsync f.e. not workin after a \\"connect\\""); 65 } 66 } 67 68 69 if (btScanSync) { 70 Serial.println("Starting discover..."); 71 BTScanResults 72 *pResults = SerialBT.discover(BT_DISCOVER_TIME); 73 if (pResults) 74 pResults->dump(&Serial); 75 76 else 77 Serial.println("Error on BT Scan, no result!"); 78 } 79 myDFPlayer.volume(10); 80} 81 82void 83 loop() { 84 action = SerialBT.read(); 85 if (action != -1) { 86 Serial.println 87 (action); //Print what we receive 88 89 switch (action) { 90 case 91 1: 92 myDFPlayer.previous(); //Play previous mp3 93 break; 94 95 96 case 2: 97 myDFPlayer.pause(); //Stop 98 Song = 0; 99 break; 100 101 102 case 3: 103 if (Song == 0) { 104 myDFPlayer.play(1); 105 //Play from beginning 106 myDFPlayer.enableLoopAll(); 107 Song 108 = 1; 109 } 110 else { 111 myDFPlayer.start(); //Play from 112 Pause 113 myDFPlayer.disableLoopAll(); 114 } 115 break; 116 117 118 case 4: 119 myDFPlayer.pause(); //Pause 120 break; 121 122 123 case 5: 124 myDFPlayer.next(); //Next 125 break; 126 127 128 case 6: 129 myDFPlayer.volumeDown(); //Volume + 130 break; 131 132 133 case 7: 134 myDFPlayer.volumeUp(); //Volume - 135 break; 136 137 138 case 8: 139 myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); 140 break; 141 142 143 case 9: 144 myDFPlayer.EQ(DFPLAYER_EQ_POP); 145 break; 146 147 148 case 10: 149 myDFPlayer.EQ(DFPLAYER_EQ_ROCK); 150 break; 151 152 153 case 11: 154 myDFPlayer.EQ(DFPLAYER_EQ_JAZZ); 155 break; 156 157 158 case 12: 159 myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC); 160 break; 161 162 163 case 13: 164 myDFPlayer.EQ(DFPLAYER_EQ_BASS); 165 break; 166 167 168 case 14: 169 myDFPlayer.loopFolder(1); 170 break; 171 172 case 173 15: 174 myDFPlayer.loopFolder(2); 175 break; 176 177 case 178 16: 179 myDFPlayer.loopFolder(3); 180 break; 181 182 case 183 17: 184 myDFPlayer.loopFolder(4); 185 break; 186 187 case 188 18: 189 myDFPlayer.loopFolder(5); 190 break; 191 192 case 19: 193 194 myDFPlayer.loopFolder(6); 195 break; 196 197 case 20: 198 myDFPlayer.loopFolder(7); 199 200 break; 201 202 case 21: 203 myDFPlayer.loopFolder(8); 204 break; 205 206 207 case 22: 208 myDFPlayer.loopFolder(9); 209 break; 210 211 212 case 23: 213 myDFPlayer.loopFolder(10); 214 break; 215 216 217 } 218 219 } 220 } 221
Downloadable files
Circuit
This will work just fine
Circuit
Circuit
This will work just fine
Circuit
Documentation
Folder Version
Download and install on Android Phone
Folder Version
Comments
Only logged in users can leave comments