How to use DFPlayer Pro to play Music
What is a DFPlayer?
DFPlayer Pro is a mini, simple but powerful MP3 Player. It supports four controlling modes: Arduino, AT command, on-board buttons, and ADKEY. You can directly press the on-board button to play or switch music without using a controller. By using a USB cable, you can easily copy your audio files into this module, or use it as a sound card for your PC or Raspberry Pi after connecting them together. Know More
We have a tutorial about how to use DFplayer Mini here.
Upgrade from DFPlayer Mini
Feature | DFPlayer Mini | DFPlayer Pro | Upgrade Benefit |
---|---|---|---|
Audio Output Quality | Mono, lower-quality (distortion at high volume) | Stereo output, higher-quality audio | ✅ Cleaner, richer sound; suitable for higher-end projects |
DAC (Digital-Analog Converter) | Basic DAC | High-quality DAC | ✅ Better audio fidelity |
Storage Support | MicroSD only (up to 32GB FAT32) | MicroSD (up to 32GB FAT32) + 128MB internal flash | ✅ Internal storage removes reliance on SD card |
Flash Memory Support | ❌ None | ✅ Yes, built-in 128MB flash | ✅ More durable, faster access, no SD card needed |
Serial Communication | 9600 baud fixed | 115200 baud default (configurable) | ✅ Faster, more responsive communication |
Command Set | Basic, sometimes buggy | More advanced, stable command set | ✅ More reliable control and feedback |
Speaker Connection | Direct to mono speaker | Stereo line out (needs amp) | ➖ Needs external amp for speakers |
Volume Control | 0–30 steps | 0–100 steps | ✅ Finer volume control |
Power Supply | 3.2V–5V | 3.3V–5.5V | ➕ Slightly more flexible |
Size | Smaller (20mm x 22mm) | Slightly larger (24mm x 24mm) | ➖ Slightly bigger, but compact enough |
Ease of Use | Simple, but unstable at times | More stable firmware | ✅ More professional and dependable |
Audio Channels | Mono | Dual-channel (stereo) | ✅ True stereo separation for improved sound effects |
Advanced Playback Controls | Limited to play/pause/next/prev | Fast-forward, fast-rewind, play from specific time | ✅ More control and interactivity for audio playback |
Wiring
- VCC to 5V (Power)
- GND to GND (Ground)
- RX to D3
- TX to D2
- R+ to Speaker(+) red wire
- R- to Speaker(-) black wire
- Second speaker (L+ & L-) is optional
Library
DFRobot_DF1201S
library will be used for this module. We have a tutorial on how to install a library here.
Get Started
#include <DFRobot_DF1201S.h>
#include <SoftwareSerial.h>
SoftwareSerial DF1201SSerial(2, 3); //RX TX
DFRobot_DF1201S DF1201S;
void setup(void){
Serial.begin(115200);
DF1201SSerial.begin(115200);
while(!DF1201S.begin(DF1201SSerial)){
Serial.println("Init failed, please check the wire connection!");
delay(1000);
}
/*Set volume to 20*/
DF1201S.setVol(/*VOL = */20);
Serial.print("VOL:");
/*Get volume*/
Serial.println(DF1201S.getVol());
/*Enter music mode*/
DF1201S.switchFunction(DF1201S.MUSIC);
/*Wait for the end of the prompt tone */
delay(2000);
/*Set playback mode to "repeat all"*/
DF1201S.setPlayMode(DF1201S.ALLCYCLE);
Serial.print("PlayMode:");
/*Get playback mode*/
Serial.println(DF1201S.getPlayMode());
}
void loop(){
Serial.println("Start playing");
/*Start playing*/
DF1201S.start();
delay(3000);
Serial.println("Pause");
/*Pause*/
DF1201S.pause();
delay(3000);
Serial.println("Next");
/*Play the next song*/
DF1201S.next();
delay(3000);
Serial.println("Previous");
/*Play the previous song*/
DF1201S.last();
delay(3000);
Serial.println("Start playing");
//Fast forward 10S
DF1201S.fastForward(/*FF = */10);
Serial.print("File number:");
//Get file number
Serial.println(DF1201S.getCurFileNumber());
Serial.print("The number of files available to play:");
//The number of files available to play
Serial.println(DF1201S.getTotalFile());
Serial.print("The time length the current song has played:");
//Get the time length the current song has played
Serial.println(DF1201S.getCurTime());
Serial.print("The total length of the currently-playing song: ");
//Get the total length of the currently-playing song
Serial.println(DF1201S.getTotalTime());
Serial.print("The name of the currently-playing file: ");
//Get the name of the playing file
Serial.println(DF1201S.getFileName());
delay(3000);
//Play the file No.1, the numbers are arranged according to the sequence of the files copied into the U-disk
DF1201S.playFileNum(/*File Number = */1);
//Play the test.mp3 file in test folder
DF1201S.playSpecFile("TRACK007.MP3");
while(1);
/*Delete the currently-playing file */
//DF1201S.delCurFile();
}