MP3 Player With Arduino Using DF Player Mini

31K2613

Intro: MP3 Player With Arduino Using DF Player Mini

Hi guys, welcome to this tutorial. Today, we will build an mp3 player using an Arduino and the DFPlayer mini MP3 module.The DFplayer mini is a small, low-cost mp3 module with a simplified audio output that can be connected directly to a speaker or an earphone jack. The module can be used as a stand-alone module with attached battery, speaker, and push buttons or used in combination with a microcontroller or development board like the Arduino, enabled for RX/TX (Serial) communication, thus through simple serial commands we can play music and perform other functions like playing the next and previous song, shuffle, pause the song currently being played etc.

STEP 1: Things You Need

The following components are required to build this project;

DFPlayer Mini


Arduino Uno

Breadboard

Push Buttons

Speaker

Resistor


Jumper wires

STEP 2: Features of DF Player Mini

Some of the features of the DF player mini include:Support of sampling rate of 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, up to 48KHz24-bit DAC output, dynamic range support 90dB, SNR supports 85dBSupports FAT16, FAT32 file system, maximum support 32GB TF cardA variety of control modes, serial mode, AD key control modeThe broadcast language spots feature, you can pause the background music being playedBuilt-in 3W amplifierThe audio data is sorted by folder; supports up to 100 folders, each folder can be assigned to close to 1000 songs30 levels of volume adjustable, 10 levels EQ adjustable.

STEP 3: Schmatics

As seen above the connection between the Arduino and the DFplayer mini is very simple as we only need to connect two pins aside VCC and GND. It should be noted that the 1k resistor added in between the Rx pin of the module and the Arduino was added to reduce noise but it’s not necessary if your module setup is not accompanied with noise on the Rx line. The connection is described below for clarity

STEP 4: Code

Please copy the following code and upload it to your arduino Board :

//////////////////////////////////////////
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
# define ACTIVATED LOW
int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;
void setup () {
pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,HIGH);
pinMode(buttonNext, INPUT);
digitalWrite(buttonNext,HIGH);
pinMode(buttonPrevious, INPUT);
digitalWrite(buttonPrevious,HIGH);
mySerial.begin (9600);
delay(1000);
playFirst();
isPlaying = true;
}
void loop () {
if (digitalRead(buttonPause) == ACTIVATED)
{
if(isPlaying)
{
pause();
isPlaying = false;
}else
{
isPlaying = true;
play();
}
}
if (digitalRead(buttonNext) == ACTIVATED)
{
if(isPlaying)
{
playNext();
}
}
if (digitalRead(buttonPrevious) == ACTIVATED)
{
if(isPlaying)
{
playPrevious();
}
}
}
void playFirst()
{
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(20);
delay(500);
execute_CMD(0x11,0,1);
delay(500);
}
void pause()
{
execute_CMD(0x0E,0,0);
delay(500);
}
void play()
{
execute_CMD(0x0D,0,1);
delay(500);
}
void playNext()
{
execute_CMD(0x01,0,1);
delay(500);
}
void playPrevious()
{
execute_CMD(0x02,0,1);
delay(500);
}
void setVolume(int volume)
{
execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
delay(2000);
}
void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}

STEP 5: Playing Mp3

Load an SD card with songs and insert into the DFplayer mini, then upload the code to your Arduino and connect the wires from speaker to the speaker pins of the DFPlayer mini. You should hear songs start streaming out from the connected speaker

8 Comments

Can we make this with ardunio nano
Is there any difference between the df mini player while connecting it to a gsm module and with arduino
How the df mini player works by connecting it to a gsm module
How to change volume in 20 steps on DFPlayer with arduino. I can change it with the code in public domen. But it increases/decreases very fast. And can not be set as required.
DF Player Buzz sound recited by adding IN 5822 diode in series to the RX line of the DF player. And also Gnd both the Gnd pins of the DF player
I was able to make it :-)

but it will be best if you upload your codes to GitHub and provide a link to the place, so the code will be well organized
Thank you
I tried your DF player Uno project and it worked well. I am working on a single sound unit for an exhibition. Basically folk walk pass an exhibit the guide press a radio button and the sound is played as long as the button is pressed. I thought I could replace one switch in your setup with a relay, press the Radio button and hey sound. Also can I replace the Uno with an Nano for space reasons and is possible to reduce the code for a single play. Or do I just ignore the other switches. I should add this is a gift for the exhibition and not a commercial product. Thanks Jim