circuiTician

Arduino Based Music Player Using DFPlayer Mini

Table of Contents

Sometimes adding sound or voice gives an edge to your project. Like the voice of any AI system or robot.

A way to create music is Arduino. But generating sound through Arduino is a very tedious task and the sound clarity is also very poor. The reason behind this is Arduino doesn’t have sufficient storage to store music and the DAC of the Arduino is only 8 bit.

So, to do this we need a music player and in this tutorial, I am going to use DFPlayer Mini with Arduino to build a music player.

What is DF Player Mini?

One of the leading music players that can play music from a storage device and can communicate with a microcontroller is the DFPlayer Mini. It is a tiny music player module that is low cost, low power & can reproduce sound stored on an SD card. As the module has a 24 bit DAC the sound clarity of it is great.

The bonus with this module is a built-in mono amplifier that drives a speaker up to 8 ohm 3 Watt. Another output of the module is stereo output which can be fed to an earphone or an external amplifier.

DFPlayer Mini has a variety of control modes.

  1. IO mode
  2. AD Key mode
  3. USB mode
  4. Serial mode.

DF Player Mini Pin Out

df player mini pin out
  • Pin no. 1 is the Vcc pin and pin no. 7 & 10 is the ground pin. This module is compatible from 3.2 volt to 5 volt. I would recommend using a 3.7 volt li-ion or li-po battery if you connect the speaker directly into it. Otherwise, it will hang and restart again and again if you supply from other supplies.
  • Pin no. 2 & 3 are the Rx & Tx pin of the module respectively. This pin is used for Serial communication purposes.
  • Pin no. 4 & 5 are the stereo output pin for earphones/ headphones and external amplifiers. Pin 4 is the right channel output and pin 5 is the left channel output.
  • Pin no. 6 & 8 are the amplified output pin for the speaker. While connecting the speaker with this pin keep in mind that the speaker rating should not exceed the recommended rating which is 8 ohm 3 watts.
  • Pin no. 9 & 11 are the trigger port pins. Pin 9 is the IO1 pin and pin 11 is the IO2 pin. These to pins are used to provide commands like playing the previous & next music, volume increase or decrease.
  • Pin no. 12 & 13 are AD pins. By using these two pins we can add more functionality to this tiny module which I will discuss later in this article.
  • Pin no. 14 & 15 is the USB- & USB+ pin respectively. These two pins are used for USB communication like playing music from a pen drive.
  • The last pin which pins no. 16 is marked as busy. If this pin is low that means currently music is playing and high when no music is playing. So this pin can be used to know the current status of the module.

File structure inside SD Card/USB Device for DF Player Mini

DFPlayer Mini supports up to 32 GB SD card. Music format supported by this module is .mp3 & .wav. 

But in my case, I am not able to play the .mp3 file so I converted the .mp3 files into .wav files using an mp3 to wav converter and store that into the SD card. There is two way to store the music on the SD card.

First method: You can store the music files directly into the root directory. The maximum no. of music files should not exceed 3000. You also have to name the music files in a particular way. Here file should be like this 0001, 0002, 0003, 0004, ……………………………, 3000 otherwise the music will be not played.

File structure inside SD Card/USB Device for DF Player Mini

Second method: In the second method you can group the sound by creating a folder into the root directory. Here up to 99 folders can be created with the name like 01, 02, 03, 04, …………….., 99. Each folder can contain up to 255 music files having a name like these 001, 002, 003, 004, ………………………, 255.

File structure inside SD Card/USB Device for DF Player Mini
File structure inside SD Card/USB Device for DF Player Mini

After storing the music files insert the card into the DF player mini.

Control Modes

1. IO Mode

The first mode I am discussing here is the IO mode. This mode is for simply playing music files stored on the SD card.

Required components to make the circuit

  1. Bread board
  2. 3.7 volt lithium ion battery
  3. 8 ohm 3 watt speaker
  4. Push buttons
  5. Single strand wire
  6. SD card
io mode circuit diagram

Here I supplied the module with a 3.7 volt li-ion battery. IO pin 1 and 2 are connected to a push-button switch and another end of the switches are connected to the ground.

If you press button 1 for once which is connected to pin IO1 the previous music will be played and if you press button 2 for once which is connected to pin IO2 the next music will be played. By long-pressing buttons 1 & 2, you can decrease and increase the sound output respectively.

2. AD Key Mode

In AD Key mode we can access a total of 20 functionalities. Among these 6 are main functionalities 

  1. Play Mode
  2. Switch between playback mode (SD card mode, USB mode/pen drive mode)
  3. Loop all the songs one by one
  4. Play/ Pause the music
  5. Next music (Short press) and volume up (Long press)
  6. Previous music (Short press) and volume down (Long press)

Rest of the 14 functions for playing specific songs like by pressing button no. 1 you can play music no. 1, button 2 for music, and the last button 14 is for 14 no. music, after that you have to play the music by pressing the next button. To get all functionalities you have to follow this circuit diagram.

Required components to make the circuit

  1. Bread board
  2. 3.7 volt lithium ion battery
  3. 8 ohm 3 watt speaker
  4. Push buttons
  5. Single strand wire
  6. SD card
  7. Resistors (220k, 100k, 47k, 33k, 22k, 15k, 10k, 6.8k, 3.3k)
ad key mode circuit diagram
3. USB Mode

When I was testing the USB mode I am unable to use this mode, because I am using a USB card reader with an SD card inserted into it to access this mode. But then I used a 32 GB pen drive and its worked like a charm. The circuit of the USB mode is the same as the AD Key mode. Only u have to connect a USB socket to the circuit according to the circuit diagram.

Required components to make the circuit

  1. Bread board
  2. 3.7 volt lithium ion battery
  3. 8 ohm 3 watt speaker
  4. Push buttons
  5. Single strand wire
  6. USB socket
  7. Pen drive
  8. Resistors (220k, 100k, 47k, 33k, 22k, 15k, 10k, 6.8k, 3.3k)
usb mode ckt diagram

I supplied the USB socket from a different 5 volt source and I common the ground of the battery and the power source together. If you don’t connect the ground together it will not work. After making the connection you have to press the second button to switch the playback mode from SD card mode to USB mode and then you can use the other buttons to play the music as before.

4. Serial Mode (Conncecting Arduino with DF Player Mini)

This is the last mode. In this mode, you can communicate with the DFPlayer Mini using so-called UART communication. Here I am using Arduino Mega 2560. You can use any microcontroller. 

To communicate with the DF player you have to send some numbers through serial communication. There are different numbers for performing a different task. You can find the numbers in the datasheet of the DF player

For programming the Arduino you have to include a software serial library. You can communicate with the module by sending the number manually by writing in the code or you can just simply use the DFPlayer Mini library provided by DF Robot. I would not recommend using any other library for the DF player.

Next, I make the connection between the DF player mini and the Arduino according to the given circuit diagram. I also connect some pushbuttons with the Arduino to give some functionalities like playing & pausing the music, playing the previous & next music, Increase & decreasing the volume.

Required components to make the circuit

  1. Bread board
  2. 3.7 volt lithium ion battery
  3. 8 ohm 3 watt speaker
  4. Push buttons
  5. Single strand wire
  6. Jumper
  7. Arduino 
  8. SD card
Serial Mode ckt diagram

In the code, I included the software serial library as well as the DF player library. At first, I define the pins to take input from the switches. In the setup part, I declare all the defined pins as input pull-up because I connected the switches between the Arduino pins and ground. Then I have started the serial monitor and begin the communication with the DF player mini. In the loop part, I am checking the inputs coming from the switches and calling the functions like play pause, volume up down, next & previous music accordingly.

  1. By pressing the button connected with pin no. 3 you can play the music if it is paused and pause the music if it is playing.
  2. By pressing the button connected with pin no. 4 you can increase the volume.
  3. By pressing the button connected with pin no. 5 you can increase the volume.
  4. By pressing the button connected with pin no. 6 you can play the next music of the currently playing or played music.
  5. By pressing the button connected with pin no. 7 you can play the previous music of the currently playing or played music.

Code & Circuits

You can find the Code and Circuit in my GitHub repository

To watch the demo of all the modes you can watch my YouTube video.

Hopefully, this article helped you to add a voice to your projects.

Like it !! Share it !!

Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on pinterest

Related Articles