Arduino - DFPlayer Mini MP3 Module

Arduino - Test DFPlayer Mini MP3 Module

I found DFPlayer mini MP3 module on China auction site Taobao when I was looking for a MP3 player module for an Arduino projects.  This module is quite small and it only require few pins connections to Arduino and a speaker to work.  Looks really nice for my little project.

Actually, the module is quite capable and complicated, if you were interested, please visit this page.

This tutorial here is just to show you how to connect DFPlayer module with Arduino and speaker and the Arduino sketch provided here just to play few sample sounds I collected from Internet.

First, I recycled a 2W, 4Omh small speaker from this little music box.

Material Needed:
  1. DFPlayer Mini module 
  2. Speaker - DFPlayer module support to to 3W
  3. SD card - 2GB ~ 32GB formatted with FAT or FAT32
  4. MP3 / WAV - audio files
  5. Arduino mini Pro
  6. Few jump wires
As you can see the illustration below I made in Power Point, hardware connection is quite simple
(Forget about the cross lines...these lines are NOT supposed to be crossed.. :)
* Note: You have to separate DFPlayer Mini Module power from Arduino power or you will hear very loud noises (It took me two days to figure out this!)

UPDATE:  Someone left a message in this blog below, please try it out!

Hello everybody! There is another solution for getting rid of noise. Just put down DC voltage to 4.0 - 4.3 Volts. Arduino is still able to operate and DFplayer recommends to use 4.2V, my experiments prove this.


Here is a photo of my Arduino with DFPlayer Mini connection:

*Important note for audio files. Careful read notes below will save you a lot of precious time!
  • DFPlayer Mini read both MP3 and WAV files.
  • All audio files must be placed under /mp3 folder.
  • Audio file must be named 0001.mp3, 0002.mp3.....0255.mp3 (4 letters not 2 or 3 letters)
  • Audio file names can have any characters after 4 digits, such as 0001_Bruno_Mars_Count_On Me.mp3 
  • Tested few under 1 second WAV files and they did not work
  • If one of the audio file is removed from SD cared, DFPlayer still can find it and play it! Weird! In the end, I formatted the SD card to make DFPlayer to play the music I specified.
  • Delay(seconds); You have to specify number of seconds delay for the audio file to play completely or the next audio file might be started before current audio is over!
  • mp3_play (74); means play audio file 0074.mp3
The code below is from the vendor's website and it worked without much modification.

Programming Code here:

 * Copyright: DFRobot
 * name:  DFPlayer_Mini_Mp3 sample code
 * Author:  lisper 
 * Date:  2014-05-30
 * Description: sample code for DFPlayer Mini, this code is test on Uno
 *   note: mp3 file must put into mp3 folder in your tf card

#include <softwareserial.h>
#include <dfplayer_mini_mp3.h>

void setup () {
 Serial.begin (9600);
 mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module 
 mp3_set_volume (10);

void loop () {        

 mp3_play (1); //play 0001.mp3
 delay (10000); //10 sec, time delay to allow 0001.mp3 to finish playing

 mp3_play (2);
 delay (5000);

 mp3_play (5);
 delay (5000);

 mp3_play (20); //play 0020.mp3
 delay (9000);

 mp3_play (81);
 delay (6000);

 mp3_play (74); //play 0074 mp3
 delay (6000);

Here is the video:

Arduino - 測試 DFPlayer Mini MP3 播放模組

最近在大陸拍賣網上找到一個 Arduino MP3 播放模組(DFPlayer Mini),它支援最大32GB SD卡,又可以由 Arduino 下個  Play 的指令就能由SD 卡上播放 MP3 & WAV檔案。加上體積很小一片又只要連接幾支腳位到 Arduino 就能運作了,二話不說就淘了兩片來試試它的功能。

DFPlayer Mini 它的功能真的很多, 有興趣的朋友可以到這裡閱讀 DFPlayer Mini 的介紹!

這個測試主要是測試 DFPlayer Mini MP3 播放模組的功能,所以只需要下列的東西即可:

  1. Arduino mini Pro
  2. DFPlayer Mini 模組 
  3. Speaker - 最高支援到 3W
  4. SD card - 2GB ~ 32GB 以 FAT or FAT32 格式化
  5. 洞洞板 / 跳線
  6. MP3 / WAV 格式的音效 or 音樂檔案

手上剛好有一個壞掉的音樂播放器,我把喇叭拆下來看了一下,剛好是 2W的,可以拿來用。

下方是我自己在 Power Point 上畫的線路示意圖:
(Forget about the cross lines...these lines are NOT suppose to be crossed.. :)
* 注意: 不要直接把 Arduino 的 5V 給 DFPlayer Mini 使用,一定要分別供給 DFPlayer Mini 電源,不然喇叭會發出很大的雜音,我花了兩天才發現這個問題。


* 以下是使用 DFPlayer Mini Module 的注意事項,請仔細閱讀,可以幫你節省很多時間!

  • DFPlayer Mini 可以讀取 MP3 & WAV 檔案格式,但試過檔案長度1秒以下無法播放。
  • 所有音樂檔案一定要放在 /mp3 資料夾裡
  • 音樂檔案名稱一定要使用 4 個字,如 0001.mp3, 0002.mp3.....0255.mp3 
  • 音樂檔案超過4個字後則無限制,像是 0001_Bruno_Mars_Count_On Me.mp3 是沒問題的。
  • 如果你從 SD 卡上刪掉某個檔案,DFPlayer Mini 還是有辦法把它播出來,好怪!後來我從新格式化 SD 卡才成功播放我要的音樂檔案。
  • Delay(sec); 這個指是是告訴 Arduino 你要播放音樂的長度,如果你給的秒數不足,而下個指令又是要播另一首,則 Arduino 就會把目前播放中斷,而繼續播下一首。
  • mp3_play (74); 這個指令是播放 0074.mp3 這個音樂檔。

Arduino 程式碼請參考上面。



  1. I think that's the limitation of this DFPlayer Mini module. I've written an email to ask DFRobot on what command can I use to tell an audio play length, but no reply yet.

  2. Hi Stones,
    你的blog寫的非常用心, 非常有幫助. 我也在用FDPlayer mini做project, 但是當我load你的code的時候(或者官方的examples的時候), IDE告訴我"error: 'mp3_set_serial' was not declared in this scope.", 請問你有遇到過這個問題么, 或者有知道這是怎麼回事嗎?

    1. 補充: 我的IDE的Board中選的是UNO.

      Build options changed, rebuilding all
      sketch_mar28b.ino: In function 'void setup()':
      sketch_mar28b.ino:66:9: error: 'Serial1' was not declared in this scope
      sketch_mar28b.ino: In function 'void print_info()':
      sketch_mar28b.ino:80:37: error: 'Serial1' was not declared in this scope
      sketch_mar28b.ino: In function 'void loop()':
      sketch_mar28b.ino:90:28: error: 'Serial1' was not declared in this scope
      Error compiling.


    2. oh never mind, 我在找到解決方法了, 就像他說的"I had loaded the DFPlayer library into the Arduino (core) library folder (as I have done with others). But I moved it to the Arduino (user docs) folder and compilation errors on Examples went away. Don't know why, but it works..."


    3. Sorry, not check message very often..Yeah, sometimes the location of the library could cause the compiling error. I'm glad you found answers!

    4. //DFMiniMp3 mp3(Serial1);

      // Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
      // comment out the above definition and uncomment these lines
      SoftwareSerial secondarySerial(10, 11); // RX, TX
      DFMiniMp3 mp3(secondarySerial);

      为什么不尝试把hardware Serial注释掉,用Software Serial?

  3. +heymannstrasse7, the solution, please share it with us, thank you!

  4. This comment has been removed by the author.

  5. +heymannstrasse7 Thanks for this! I will give it a try over the weekend!

  6. Hi there,

    i am using the DFPlayer as a „extension“ of my door bell

    to isolate the power supplys, I am using a optocoupler to trigger the sound on DFPlayer (ADkey1 – “shorting” the segment 1-switch – only one MP3 on TF-Card)

    the problem is: a short push on the door bell button start’s the sound – running once = everything OK 
    but: if the “postman” is pushing the button for a longer time, the DFPlayer is going to looping the sound for ever

    any idea, how to set the DFPlayer in “single play mode” – one shoot only, independent from button time ? – without pressing other buttons, like “K1” or “stop”

    THX for feedback

    1. Hi Michael, I haven't try this myself yet, but I suggest you look at the "software debounce" from here:

      You should be able to filter out the longer push by debounce.
      Let me know, if you were able to pull it off! :)

  7. Hi Stonez,
    and THX for your reply.
    there is no Arduino in the game. i am using the DFPlayer "stand alone". so, no way for "software debouncing"

    1. Hi Michael,
      I am not good at electronic hardware, but you might want to search "hardware debounce" in many online tutorials. Few said, it only required a capacitor and two resistors.

      Let me know if really make it work! :)

    2. Try to connect your button trough capacitor, it will produce small impulse for every click but not for long press. Maybe 1uF will work. Probably you will need to use transistor to amplify impulse from resistor-switch-capacitor, but it is very easy to produce impulse. Otherwise, you can use an 74HCxx to produce impulse instead of long press.

  8. Can i use it with Pic/AVR

    1. Sorry, I can answer this question as this is beyond my knowledge....

  9. Can the DFPlayer and the Arduino use the same power supply - as long as I'm not powering the player through the Arduino?

    1. Someone left a message in the blog: Try it out:

      There is another solution for getting rid of noise. Just put down DC voltage to 4.0 - 4.3 Volts. Arduino is still able to operate and DFplayer recommends to use 4.2V, my experiments prove this.

    2. I actually broke an arduino nano by powering the mp3player from it

  10. Nice tutorial and many many thanks for this .

    I've a problem , you said "You have to separate DFPlayer Mini Module power from Arduino power or you will hear very loud noises " , but I want to operate this mp3 module by arduino with single battery . How to separate ground in this case ?

    1. Someone left a message in the blog: Try it out:

      There is another solution for getting rid of noise. Just put down DC voltage to 4.0 - 4.3 Volts. Arduino is still able to operate and DFplayer recommends to use 4.2V, my experiments prove this.

    2. I have an electronic solution.

      I tried all the 1K resistor suggestions and I'm running it of an ESP8266 3.3V pin. Still lots of ticking.

      I'm only using the built-in 3W speaker connection.

      I snipped one of the speaker wires and soldered in an NPN transistor (like a 3904 or 22222N). Collector and Emitter are soldered to the open ends of the speaker wire

      Then I connected the base to pin 3. In my sketch, I just set the pin high right before I want to play a sound. It energizes the transistor and lets the speaker play the sound. After sound done, pin goes LOW and the speaker is again not connected to the module.

      Problem solved 100%. No ticking during idle time(for my application anyway).

  11. Hello everybody! There is another solution for getting rid of noise. Just put down DC voltage to 4.0 - 4.3 Volts. Arduino is still able to operate and DFplayer recommends to use 4.2V, my experiments prove this.

    1. Hi, thanks for this solution!

    2. Hi, how do you reduce the DC voltage? Currently powering using PC USB

    3. I found this for your reference.
      USB 5V to 3.3V Step down module. BTW, I haven't try this yet myself.

  12. Hi, I am having an issue getting mine to work at all. The weird thing is, when I don't connect the power to the unit and no resistors I get a buzzing sound. When I connect the 1k resistors the sound stops but nothing plays (didn't play during buzzing either). If I connect the power it won't play or buzz...odd...

    can you suggest what i am doing wrong?

  13. Hi!!
    I've tried uploading your codes to my uno board but it says theres an error : mp3codes:23: error: 'mp3_play' was not declared in this scope

    please let me know what I've done wrong here
    I'm very new to arduino
    I'm sorry if my question is stupid :(

    1. Hi,
      Usually, this kind of issues are due to the compiler couldn't find the .h files.

      Please ensure the library "dfplayer_mini_mp3.h" is located in the right directory.


  14. hi i tested this on my uno with an analog pin wich uses analogRead() and i got 1023 when there was nothing played. so every time i saw that and the variable (in your case 'playing') was true i would continue playining the next one also tested it on a pwm pin but didnt get the right results. Hope this helped any one in any way.

  15. hi i have found out that if you use rx and tx for the comands then you dont need to include software serial library. I wil also post any other things i find in here sinds this seems to be the only place for information aside from the main information page.

    1. this guy found all the commands there are some very interesting ones 2:
      i hope the links work for you

  16. Dear Stonez,

    模組上的指示燈與音樂時有時無,以為是電源問題,但換使用Power Supply仍還是這樣。

    偶爾插拔SD card或是等待一段時間,模組指示燈又亮,音樂也開始播放了。


    Thank you for your awesome article.

    I have a problem when I use this module. I use 5V power bank or power supply as DFPlayer external power. The LED on the module and speaker don't work all the times.

    I wire my arduino nano and DFPLAYER like the diagram in your article. And I use a 8 ohm, 0.5W speaker.

    Thank all of you for your help.

    1. Yes, I did encountered similar issues with what you've described during the testing.
      Sorry, I do not know why, but do you want to solder wires to the Arduino module to prevent the pin contact issues first?

    2. Thank you and sorry for my late reply.

      To avoid the serial port disturbing when arduino connect with PC, I used SoftwareSerial.h to modify the demo code to use pin D8, D9 for RX, TX instead of the default RX, TX pin. And I add a 1k ohm resister between arduino's RX, TX and DFPlayer's Tx,Rx.

      It really works for one of my DFPlayers. But I broke the other one in the same way, it comes to smoke LOL

      I'll solder wires in the near future.

  17. Thanks for your compliments! By writing these tutorials, I hope Arduino beginners can have something to start with! :-)

  18. how to connect dfplayer with amplifier

  19. Nice blog. As it is the discussion of speakers I want to say something about klipsch speakers which are of high quality and provide great sound quality. And recently I came to know about which is a great dealer of it. One week ago I contacted with them for one speaker. They not only provide these speakers but also help them to install at an affordable price.

    1. Thank you for your information!

  20. не рабочий скейч или библиотека. Пишет,ошибка компиляции.

    1. Please double check and be very careful where you place the library files or this tutorial will not work. Good Luck!

  21. hi guys,

    I bought 5pcs of DF player from TAOBAO but the led dint light on.
    But my previous DF player i bought from other seller it can work.
    So i would like to ask any other way to test the df player still can work or not ?
    Sorry for my bad english.

    1. It's really hard to tell, but I suggest you try the simplest connection to check whether DFPlayer is functioning.

  22. I did try with the vcc pin and gnd pin to check each of the df player.

  23. Stonez, thank you for your tutorial. 我跟著上面的步驟做,可發現了一個問題
    即便我供電給arduino 了,可MP3 module的LED也沒亮起來。直到我把IO_2 or IO_1接了一下GND以後才會開始播。然後播完一首又停了,燈也黑了。又要再把IO pin 接一下GND才會播。這到底是甚麼情況QAQ

  24. OK I know this is way out of date but this is how you playback a whole folder:

    1 - the module takes into account only directories that actually have files

    2 - other directories should be created in the root of the filesystem

    3 - the datasheet states that the folder structure for other directories except the "sdc:\MP3\" directory should be like :

    sdc:\01\001_xxx.wav or mp3
    sdc:\02\002_xxx.wav or mp3
    sdc:\xx\00x_xxx.wav or mp3 (for the 1-99 directories/1-255 files configuration)

    check my implementation here :

  25. Anonymous5:50 AM

    I follow this good tutorial. But when I play a sound, there is this strange noise. Sometimes I eard my sound but mixed with its strange sound. I tried with an other Arduino, with an other speaker, with a independent power.... Is my DFPlayer board broken ?

    My test :

    Thank you very much

  26. Forgive my beginner question,how do I add the libray to my ide/project?

    1. This guide will tell you how to install libraries:

  27. Hi! Thank you for interesting project! Do you think it is possible to control several players individually from the same Arduino? Best regards Johan

  28. This comment has been removed by a blog administrator.

  29. can you plzz give a link of DFPLAYER library which you are use in this project?

    1. The link is here:

  30. 您好,我想請問一下
    mp3_set_serial (Serial);
    DFplayer mini就會直接開始播放音樂

  31. 我沒試過, 不過我猜它應該是用來下 Serial Control Cmd,
    如, 上一首, 下一首, 播放, 暫停...等等
    看一下使用手冊: Serial Control Cmd:

  32. I have tried to load this and find that there are spelling errors that keep popping up These the result of failure to capitalize the file names to match those in the library folder.

    1. Glad that you figured this out yourself! Thanks!

  33. Why is it when I copy and paste the above sketch "DFPlayer_Mini_Mp3 sample code" into the Arduino IDE and compile the code, I get the error message "Error compiling for board Arduino Nano"? I have the 2 libraries 'SoftwareSerial.h' and 'dfplayer_mini_mp3.h'. When I look through the verbose print out of the error message, the only line I see with the word error is: C:\Program Files (x86)\Arduino\libraries\DFPlayer_Mini_Mp3/dfplayer_mini_mp3.h:45:20: error: redefinition of 'uint8_t send_buf [10]'. I have read the Nano need the Processor: ATmega328P(Old Bootloader), which I used.


Post a Comment

Popular posts from this blog

Android control color RGB LED using HC-05 Bluetooth with Arduino (Part I)

Arduino #27 AsyncWifimanager ElegantOTA ESP32 (WiFi Password Mgnt. + WiFi Firmware Update)