Audio Player with SD Card

In the Making Music project, you learned how to generate simple sound with the Arduino. In this project, you'll learn how to use the Arduino to play audio (MP3 and WAV) files stored on a microSD card using the DFPlayer Mini audio module.

Parts needed:
  • Arduino
  • DFPlayer Mini audio module
  • Speaker
  • micro SD card
  • A 1K Ω resistor (brown-black-red) or (brown-black-black-brown)
  • Wires
  • Breadboard

  • You also need to download the DFPlayer software library which contains all of the functions for interfacing with the DFPlayer audio module.
Arduino      DFPlayer Audio module      Speaker      Breadboard      Micro SD card      1K Resistor     
1 Prepare SD card.
  • Format the SD card with the FAT or FAT32 file system.
  • Create two special folders using the names mp3 and advert.
  • Additionally you can create 99 more folders using the names 01 to 99. These 99 folder names must be exactly two digits long zero padded.
  • Copy one or more MP3 audio files into the two special folders, mp3 and advert, and to the 01 folder. You need to rename the audio files using the following format:
  • The filenames for the MP3 files that you put inside the two special folders, mp3 and advert, must start with four digits zero padded, and then optionally a long filename after. You can have up to 255 files inside these folders. For example, "0001 Welcome message.mp3"
  • The filenames for the MP3 files that you put inside the 01 to 99 folders must start with three digits zero padded, and then optionally a long filename after. You can have up to 255 files inside these folders. For example, "001 Jack and Jill.mp3"
2 To run the basic example program correctly, you need to have the following mp3 files on your SD card:
  • A mp3 file named 0001.mp3 in the mp3 folder.
  • A mp3 file named 001.mp3 in the 01 folder.
  • A mp3 file named 0001.mp3 in the advert folder.
Then insert the micro SD card into the DFPlayer.
3 (Optional) Testing the DFPlayer without the control of the Arduino. You might want to do this if your Arduino program doesn't work. Connect the power and speaker wires as follows.

DFPlayer Description
7 GND
1 VCC 3.3V
6 SPK_1 Speaker
8 SPK_2 Speaker

  • Quickly connect and disconnect pin 9 (IO_1) of the DFPlayer to GND to play the next song on the SD card.
  • Long connect pin 9 (IO_1) of the DFPlayer to GND to decrease the volume
  • Quickly connect and disconnect pin 11 (IO_2) of the DFPlayer to GND to play the previous song on the SD card. (This sometimes might not work)
  • Long connect pin 11 (IO_2) of the DFPlayer to GND to increase the volume
  • Do not turn up the volume too high or it might not play
DFPlayer pins
4 Using the Arduino to control the DFPlayer This requires seven (7) connections between the DFPlayer and the Arduino.

DFPlayer Arduino Description
2 5, through a 1K resistor Arduino TX - DFPlayer RX
3 4 Arduino RX - DFPlayer TX
7 GND GND
1 3.3V 3.3V
6 Speaker
8 Speaker
16 2 Busy (optional, but needed for the basic sample program)
Audio module connections
5 Download the DFPlayer software library.
6 Install the DFPlayer software library by selecting Sketch from the Arduino IDE menu
  • then select Import Library or Include Library
  • then select Add Library or Add .ZIP Library
  • Locate and select the DFPlayer.zip file that you just downloaded in step 4. It should be in the Download folder.
  • Click the Open button.
(Refer to this document for more information on how to install a library if you run into problems.)
7 Create a new program by selecting File from the menu
  • then select Examples
  • then select DFPlayer
  • then select basic
8 Open up the monitor to see status messages as the program runs.
9 Upload and run the program.
  • The program will first play the audio file 0001.mp3 in the mp3 folder for eight seconds.
  • Then it will play the audio file 001.mp3 in the 01 folder for another eight seconds.
  • It will then interrupt the current song and play the audio file 0001.mp3 in the advert folder.
  • After finish playing the audio file from the advert folder, it will continue with the song that was interrupted.
  • Do not set the volume too high in the code or it might not play