Source: https://mokxi.com/libraries/dfplayer
Updated: 2026-11-02

Libraries / Communication
Arduino library · Communication

# DFRobotDFPlayerMini: play MP3 files from a DFPlayer Mini

The DFPlayer Mini is a small MP3 module with a microSD slot and a 3 W amplifier that drives a speaker directly. It decodes the files itself; the Arduino only sends commands over a 9600-baud serial link, and DFRobot’s DFRobotDFPlayerMini library builds those ten-byte frames and reads the replies.

Open the example in the editor See the calls

Built in on Mokxi: #include <DFRobotDFPlayerMini.h> and it builds, with nothing to install. Free, and no account needed.

## What DFRobotDFPlayerMini does

Most sketches use SoftwareSerial on two spare pins so the USB Serial stays free for messages. Put a 1 kΩ resistor in the Arduino TX to module RX line: the module runs at 3.3 V logic and the resistor stops buzzing and lockups that a direct 5 V line causes.

Files are found by number, not name. play(1) plays the first file the module finds, which follows the order files were copied to the card, not their names. For predictable order use folders 01, 02 and so on with files named 001.mp3, 002.mp3 and call playFolder(), or an mp3 folder with 0001.mp3 and playMp3Folder().

Library Manager name | DFRobotDFPlayerMini

Author | DFRobot

Include | #include <DFRobotDFPlayerMini.h>

Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | DFPlayer Mini MP3 module

## Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32.

In Mokxi it is built in: #include <DFRobotDFPlayerMini.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "DFRobotDFPlayerMini" by DFRobot from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add DFRobotDFPlayerMini to lib_deps in PlatformIO. Mokxi follows the calls of release 1.0.6, so a sketch written here builds there too.

What to know in the simulator: The dfplayer part answers the frames and shows what it plays; there is no sound, since there are no recordings.

Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · Arduino Pro Mini 3.3 V · ESP8266 NodeMCU · ESP32 DevKit · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · ESP32-S3-DevKitC-1 · Seeed XIAO ESP32-S3 · Arduino Nano ESP32

## The calls you will use

In the order a sketch meets them.

### DFRobotDFPlayerMini myDFPlayer

The player object; pair it with a SoftwareSerial mySoftwareSerial(10, 11) started at 9600.

### myDFPlayer.begin(mySoftwareSerial)

Resets the module and waits for its reply. Returns false when it does not answer, with no card or a wiring fault.

### myDFPlayer.volume(20)

Sets the volume from 0 to 30.

### myDFPlayer.play(1)

Plays track 1 in the order the files were copied onto the card.

### myDFPlayer.playFolder(2, 5)

Plays 005.mp3 in folder 02, the reliable way to pick a specific file.

### myDFPlayer.next()

Skips to the next track. previous(), pause() and start() do what they say.

### myDFPlayer.available()

True when the module has sent a message, such as a track finishing; readType() and read() say what it was.

## Example: Jukebox

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run · Jukebox: the project page

## Common errors and how to fix them

### Unable to begin: 1.Please recheck the connection! 2.Please insert the SD card!

The module did not answer. Check TX goes to RX and RX to TX, that the 1 kΩ resistor is in the line to the module’s RX, that the card is FAT32 with MP3 files on it, and that the module has its own 5 V and GND.

### play(1) plays the wrong song

Track numbers follow the order files were copied, not file names. Use numbered folders with playFolder(), or format the card and copy the files one at a time in the order you want.

### The speaker buzzes or the module resets at high volume

The amplifier pulls current peaks the board cannot always supply. Power the module from a separate 5 V supply with a shared ground, add a 100 µF capacitor at its power pins, or lower the volume.

## Projects that use DFRobotDFPlayerMini

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Animated diorama: DFPlayer sound + stepper A button plays a C-3PO line on a DFPlayer Mini while a 28BYJ-48 turns R2-D2’s dome, then R2 beeps back and looks the other way before the dome goes home. Jump-scare box A radar inside a box sees someone walk up: a servo throws the lid open, a DFPlayer screams and two red eyes flicker, then it shuts and rearms. Talking skull A PIR wakes a skull: its eyes light and a servo jaw follows a hand-timed cue list in step with a DFPlayer track, until BUSY says the line is over. Christmas light show A DFPlayer starts the song and three WS2812B strips, roofline, tree and arch, follow a cue list timed in beats from that moment until the song ends. Laser sword A light saber style sword on an Uno: a WS2812 blade that ignites and retracts, swing and clash from an MPU6050, a DFPlayer sound font and a charge gauge.

## Keep going

### Learn

- Arduino DFPlayer Mini MP3 Player: Wiring and Code
- UART Serial Explained: Baud, Frames and the Wire

### Parts

- DFPlayer Mini MP3 module

### More communication libraries

- OneWire
- TinyGPS
- TinyGPSPlus
- MFRC522
- SoftwareSerial
- AltSoftSerial
- i2cdetect
- Keyboard

Every built-in library · Open the editor

## Try DFRobotDFPlayerMini without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
