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:
- DFPlayer Mini module
- Speaker - DFPlayer module support to to 3W
- SD card - 2GB ~ 32GB formatted with FAT or FAT32
- MP3 / WAV - audio files
- Arduino mini Pro
- 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.
***********
***********
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
Programming Code here:
Here is the video:
- /*
- * 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);
- }
Arduino - 測試 DFPlayer Mini MP3 播放模組
最近在大陸拍賣網上找到一個 Arduino MP3 播放模組(DFPlayer Mini),它支援最大32GB SD卡,又可以由 Arduino 下個 Play 的指令就能由SD 卡上播放 MP3 & WAV檔案。加上體積很小一片又只要連接幾支腳位到 Arduino 就能運作了,二話不說就淘了兩片來試試它的功能。DFPlayer Mini 它的功能真的很多, 有興趣的朋友可以到這裡閱讀 DFPlayer Mini 的介紹!
這個測試主要是測試 DFPlayer Mini MP3 播放模組的功能,所以只需要下列的東西即可:
- Arduino mini Pro
- DFPlayer Mini 模組
- Speaker - 最高支援到 3W
- SD card - 2GB ~ 32GB 以 FAT or FAT32 格式化
- 洞洞板 / 跳線
- 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 程式碼請參考上面。
請看下方實際運作影片:
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.
ReplyDeleteHi Stones,
ReplyDelete你的blog寫的非常用心, 非常有幫助. 我也在用FDPlayer mini做project, 但是當我load你的code的時候(或者官方的examples的時候), IDE告訴我"error: 'mp3_set_serial' was not declared in this scope.", 請問你有遇到過這個問題么, 或者有知道這是怎麼回事嗎?
非常感謝,
天宇
補充: 我的IDE的Board中選的是UNO.
Delete全部的error是:
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.
再次感謝
oh never mind, 我在http://www.dfrobot.com/forum/viewtopic.php?f=8&t=975找到解決方法了, 就像他說的"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..."
Delete還是謝謝
Sorry, not check message very often..Yeah, sometimes the location of the library could cause the compiling error. I'm glad you found answers!
Delete//DFMiniMp3 mp3(Serial1);
Delete// 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?
那样问题就解决了。
+heymannstrasse7, if.you.ever.found the solution, please share it with us, thank you!
ReplyDeleteThis comment has been removed by the author.
ReplyDelete+heymannstrasse7 Thanks for this! I will give it a try over the weekend!
ReplyDeleteHi there,
ReplyDeletei 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
Hi Michael, I haven't try this myself yet, but I suggest you look at the "software debounce" from Arduino.cc here: http://playground.arduino.cc/Learning/SoftwareDebounce
DeleteYou should be able to filter out the longer push by debounce.
Let me know, if you were able to pull it off! :)
Hi Stonez,
ReplyDeleteand THX for your reply.
there is no Arduino in the game. i am using the DFPlayer "stand alone". so, no way for "software debouncing"
Hi Michael,
DeleteI 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! :)
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.
DeleteCan i use it with Pic/AVR
ReplyDeleteSorry, I can answer this question as this is beyond my knowledge....
DeleteCan the DFPlayer and the Arduino use the same power supply - as long as I'm not powering the player through the Arduino?
ReplyDeleteSomeone left a message in the blog: Try it out:
DeleteThere 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.
I actually broke an arduino nano by powering the mp3player from it
DeleteNice tutorial and many many thanks for this .
ReplyDeleteI'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 ?
Someone left a message in the blog: Try it out:
DeleteThere 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.
I have an electronic solution.
DeleteI 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).
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.
ReplyDeleteHi, thanks for this solution!
DeleteHi, how do you reduce the DC voltage? Currently powering using PC USB
DeleteI found this for your reference.
DeleteUSB 5V to 3.3V Step down module. BTW, I haven't try this yet myself.
https://www.amazon.com/-/zh_TW/dp/B07RFBD2RX/ref=sr_1_7?dchild=1&keywords=5V+to+3.3V&qid=1613959475&sr=8-7
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...
ReplyDeletecan you suggest what i am doing wrong?
https://www.dropbox.com/s/gbzmzfsmis2dnd6/IMG_2741.MOV?dl=0
Hi!!
ReplyDeleteI'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 :(
joanne
Hi,
DeleteUsually, 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.
Stoenz
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.
ReplyDeletehi 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.
ReplyDeletethis guy found all the commands there are some very interesting ones 2: http://forum.banggood.com/forum-topic-59997.html
Deletei hope the links work for you
Dear Stonez,
ReplyDelete感謝你的用心的文章,對我使用這塊模組有非常大的幫助。
我使用時遇到一個非常困擾的問題,當使用行動電源提供模組5V電壓時,
模組上的指示燈與音樂時有時無,以為是電源問題,但換使用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.
Dear Stonez,
ReplyDelete感謝你的用心的文章,對我使用這塊模組有非常大的幫助。
我使用時遇到一個非常困擾的問題,當使用行動電源提供模組5V電壓時,
模組上的指示燈與音樂時有時無,以為是電源問題,但換使用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.
Yes, I did encountered similar issues with what you've described during the testing.
DeleteSorry, I do not know why, but do you want to solder wires to the Arduino module to prevent the pin contact issues first?
Thank you and sorry for my late reply.
DeleteTo 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.
Thanks for your compliments! By writing these tutorials, I hope Arduino beginners can have something to start with! :-)
ReplyDeletehow to connect dfplayer with amplifier
ReplyDeleteNice 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 branhamsound.com 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.
ReplyDeleteThank you for your information!
Deleteне рабочий скейч или библиотека. Пишет,ошибка компиляции.
ReplyDeletePlease double check and be very careful where you place the library files or this tutorial will not work. Good Luck!
Deletehi guys,
ReplyDeleteI 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.
It's really hard to tell, but I suggest you try the simplest connection to check whether DFPlayer is functioning.
DeleteI did try with the vcc pin and gnd pin to check each of the df player.
ReplyDeleteStonez, thank you for your tutorial. 我跟著上面的步驟做,可發現了一個問題
ReplyDelete即便我供電給arduino 了,可MP3 module的LED也沒亮起來。直到我把IO_2 or IO_1接了一下GND以後才會開始播。然後播完一首又停了,燈也黑了。又要再把IO pin 接一下GND才會播。這到底是甚麼情況QAQ
OK I know this is way out of date but this is how you playback a whole folder:
ReplyDelete1 - 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 :
https://gist.github.com/gtsafos/03d6978b0fc587a339b4af94ab9c2683
Hello.
ReplyDeleteI 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 : https://www.youtube.com/watch?v=Rr_SSpw407Q
Thank you very much
Forgive my beginner question,how do I add the libray to my ide/project?
ReplyDeleteThis guide will tell you how to install libraries:
Deletehttps://www.arduino.cc/en/Guide/Libraries
Hi! Thank you for interesting project! Do you think it is possible to control several players individually from the same Arduino? Best regards Johan
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeletecan you plzz give a link of DFPLAYER library which you are use in this project?
ReplyDeleteThe link is here:
Deletehttps://github.com/DFRobot/DFRobotDFPlayerMini/archive/1.0.3.zip
您好,我想請問一下
ReplyDeletemp3_set_serial (Serial);
這一行的功能是什麼?
因為我想做的是利用語音辨識模組來播放音樂,而不是直接播放。
我在想我的程式會有問題是不是因為set_serial這行是代表當程式燒錄進去後,
DFplayer mini就會直接開始播放音樂
我沒試過, 不過我猜它應該是用來下 Serial Control Cmd,
ReplyDelete如, 上一首, 下一首, 播放, 暫停...等等
看一下使用手冊: Serial Control Cmd:
https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
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.
ReplyDeleteGlad that you figured this out yourself! Thanks!
DeleteWhy 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.
ReplyDelete