Hello Everyone!
I made this project ESP32 + BLE with DFPlayerMini to play specific MP3 audio files and this was inspired by this amazing project:- Audio / MP3 music: ESP8266 + DFRobot DFPlayer Mini + Music Player widget + Wifi (NodeMCU, Wemos D1, …) by @federicobusero.
About the project:-
This project helps you to play different MP3/WAV audio files stored in the DFPlayerMini by pressing Virtual buttons allocated for each audio. This Project uses BLE i.e. Bluetooth Low Energy which V4.0 of Bluetooth and works mainly on iOS devices. This project also had a volume control slider which helps to control volume from 0 - 30.
Things used:-
- ESP32 BLE
- DFPlayerMini
- Some Jumper wires
- Breadboard
code-
//This Project was made by Animesh Bhatt https://community.blynk.cc/u/myselfanimesh and posted on Blynk Community
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in the public domain.
*************************************************************
This example shows how to use ESP32 BLE
to connect your project to Blynk.
Warning: Bluetooth support is in beta!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <HardwareSerial.h>
HardwareSerial mySoftwareSerial(1);
#include <Arduino.h>
#include <BlynkSimpleEsp32_BLE.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include "DFPlay.h"
DFPlay dfPlay;
#include <DFRobotDFPlayerMini.h>
DFRobotDFPlayerMini myDFPlayer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
BLYNK_CONNECTED(){
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0)
{
int paramVol = param.asInt();
uint8_t volume = constrain(paramVol, 0, 30);
#ifdef BLYNK_PRINT
BLYNK_PRINT.print("VOLUME: ");
BLYNK_PRINT.println(paramVol);
#endif
myDFPlayer.volume(volume);
}
BLYNK_WRITE(V1)
{ int i=param.asInt();
if (i==1){
Serial.print("V1 value is: ");
Serial.println(i);
myDFPlayer.play(1);
}
else{
}
}
BLYNK_WRITE(V2)
{ int i=param.asInt();
if (i==1){
Serial.print("V2 value is: ");
Serial.println(i);
myDFPlayer.play(2);
}
else{
}
}
BLYNK_WRITE(V3)
{ int i=param.asInt();
if (i==1){
Serial.print("V3 value is: ");
Serial.println(i);
myDFPlayer.play(3);
}
else{
}
}
BLYNK_WRITE(V4)
{ int i=param.asInt();
if (i==1){
Serial.print("V4 value is: ");
Serial.println(i);
myDFPlayer.play(4);
}
else{
}
}
BLYNK_WRITE(V5)
{ int i=param.asInt();
if (i==1){
Serial.print("V5 value is: ");
Serial.println(i);
myDFPlayer.play(5);
}
else{
}
}
BLYNK_WRITE(V6)
{ int i=param.asInt();
if (i==1){
Serial.print("V6 value is: ");
Serial.println(i);
myDFPlayer.play(6);
}
else{
}
}
BLYNK_WRITE(V7)
{ int i=param.asInt();
if (i==1){
Serial.print("V7 value is: ");
Serial.println(i);
myDFPlayer.play(7);
}
else{
}
}
BLYNK_WRITE(V8)
{ int i=param.asInt();
if (i==1){
Serial.print("V8 value is: ");
Serial.println(i);
myDFPlayer.play(8);
}
else{
}
}
BLYNK_WRITE(V9)
{ int i=param.asInt();
if (i==1){
Serial.print("V9 value is: ");
Serial.println(i);
myDFPlayer.play(10);
}
else{
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Serial.println("Waiting for connections...");
Blynk.setDeviceName("Blynk");
Blynk.begin(auth);
mySoftwareSerial.begin(9600, SERIAL_8N1, 16, 17); // speed, type, RX, TX
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(myDFPlayer.readType(),HEX);
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);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.play(9);
}
void loop()
{
Blynk.run();
}
I made this for my hobby project and I posted this on the community in the hope that it helps someone
I had to buy 2,400 Blynk energy for this project but if you do not need more than 5 audios (OR 5 Buttons) then you don’t need to buy
It is just a small contribution to this community.
Did you like it? And any suggestions for improvements? Did I miss anything? Please feel free to criticize
Also, feel free to ask for help.
- Yes
- No
0 voters
-Animesh Bhatt