Arduino DFPlayer Mini MP3 Player: Wiring, Code and Simulator
To build this Arduino DFPlayer Mini MP3 Player project you need an Arduino Uno and a DFPlayer mini MP3 module, a 1 kΩ resistor and a push button. DFRobotDFPlayerMini starts the player, sets the volume, counts the files and plays track 1; the button skips to the next track. Make the 7 connections in the wiring table, upload the Arduino C++ code, and turn on sound in the Modules tab. Press the button to skip, or change player.volume(20) and run again.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | DFPlayer Mini MP3 module | MP3 player on serial at 9600: VCC 5 V, GND, TX → the board’s RX pin, RX ← its TX pin through 1 kΩ, a speaker on SPK1/SPK2. BUSY is LOW while it plays. Its microSD card has tunes in folders 01, 02 and mp3: you hear them in the browser. |
| 1 | 1 kΩ resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | push button | Connects 1 to 2 while held. Pair with INPUT_PULLUP and wire the other side to GND. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno 5V | DFPlayer Mini MP3 module VCC |
| 2 | Arduino Uno GND | DFPlayer Mini MP3 module GND |
| 3 | Arduino Uno pin 10 | DFPlayer Mini MP3 module TX |
| 4 | Arduino Uno pin 11 | 1 kΩ resistor leg 1 |
| 5 | 1 kΩ resistor leg 2 | DFPlayer Mini MP3 module RX |
| 6 | Arduino Uno pin 2 | push button 2.l |
| 7 | Arduino Uno GND | push button 1.r |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a DFPlayer mini MP3 module, a 1 kΩ resistor and a push button from the parts palette.
- Wire 1. Connect Arduino Uno 5V to DFPlayer Mini MP3 module VCC.
- Wire 2. Connect Arduino Uno GND to DFPlayer Mini MP3 module GND.
- Wire 3. Connect Arduino Uno pin 10 to DFPlayer Mini MP3 module TX.
- Wire 4. Connect Arduino Uno pin 11 to 1 kΩ resistor leg 1.
- Wire 5. Connect 1 kΩ resistor leg 2 to DFPlayer Mini MP3 module RX.
- Wire 6. Connect Arduino Uno pin 2 to push button 2.l.
- Wire 7. Connect Arduino Uno GND to push button 1.r.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Turn on sound in the Modules tab. Press the button to skip, or change player.volume(20) and run again.
Arduino C++ code
// DFPlayer Mini MP3 player with DFRobotDFPlayerMini.
// DFPlayer TX -> pin 10, RX <- pin 11 through 1k, VCC 5V, GND, a speaker on SPK1/SPK2.
// Button on pin 2 (to GND): next track. Turn on sound in the Modules tab to hear it.
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mp3Serial(10, 11); // RX, TX
DFRobotDFPlayerMini player;
const int NEXT = 2;
void setup() {
Serial.begin(115200);
pinMode(NEXT, INPUT_PULLUP);
mp3Serial.begin(9600);
Serial.println(F("Starting the DFPlayer..."));
if (!player.begin(mp3Serial)) {
Serial.println(F("No DFPlayer: check the wiring and the SD card."));
while (true) {}
}
Serial.println(F("DFPlayer online."));
// Ask before sending other commands: right after one, the library is still waiting
// for its acknowledgement and a query comes back as -1 (a well-known quirk).
Serial.print(F("Files on the card: "));
Serial.println(player.readFileCounts());
player.volume(20);
player.play(1);
}
void loop() {
static bool was = HIGH;
bool now = digitalRead(NEXT);
if (was == HIGH && now == LOW) {
Serial.println(F("Next track"));
player.next();
}
was = now;
if (player.available()) {
uint8_t type = player.readType();
int value = player.read();
if (type == DFPlayerPlayFinished) {
Serial.print(F("Track "));
Serial.print(value);
Serial.println(F(" finished, playing the next one"));
player.next();
} else if (type == DFPlayerError) {
Serial.print(F("DFPlayer error "));
Serial.println(value);
}
}
delay(20);
}
What to try
Turn on sound in the Modules tab. Press the button to skip, or change player.volume(20) and run again.
Frequently asked questions
How do I wire the DFPlayer Mini MP3 Player project on an Arduino Uno?
Make 7 connections: Arduino Uno 5V to DFPlayer Mini MP3 module VCC; Arduino Uno GND to DFPlayer Mini MP3 module GND; Arduino Uno pin 10 to DFPlayer Mini MP3 module TX; Arduino Uno pin 11 to 1 kΩ resistor leg 1; 1 kΩ resistor leg 2 to DFPlayer Mini MP3 module RX; Arduino Uno pin 2 to push button 2.l; Arduino Uno GND to push button 1.r.
What parts do I need for this Arduino project?
An Arduino Uno and a DFPlayer mini MP3 module, a 1 kΩ resistor and a push button.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
DFRobotDFPlayerMini starts the player, sets the volume, counts the files and plays track 1; the button skips to the next track.
Why does the DFPlayer Mini not start (begin() fails)?
Check that its TX goes to the Arduino’s RX pin, its RX through a 1 kΩ resistor to TX, that the card is FAT32 with files named 0001.mp3 and so on, and that it is powered from 5 V.
Why does readFileCounts() return -1?
A quirk of DFRobotDFPlayerMini: right after another command, the library is still waiting for that command’s acknowledgement and the query times out. Ask before sending other commands, or wait a moment.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator