Wiring diagram: NodeMCU v3 talks to a DFPlayer Mini over D6 and D7, with a speaker on the DFPlayer and power from VIN and GND

Build an Arduino MP3 Player with an ESP8266 and DFPlayer Mini

Sometimes all you need is one specific sound: a chime every 15 minutes, a sound effect at the press of a button, or an announcement when someone hits a switch. An off-the-shelf MP3 player can’t do that, and a smartphone is overkill. With a NodeMCU board (ESP8266) and the DFPlayer Mini MP3 module, you can build your own sound machine for a few dollars: an Arduino MP3 player you program in the Arduino IDE, with no soldering required.

In short

With an ESP8266, the DFPlayer Mini MP3 module and the Arduino IDE, you can build an Arduino MP3 player that plays a specific file at the press of a button or on a fixed schedule.

  • You’ll need: NodeMCU ESP8266, DFPlayer Mini, a small speaker, jumper wires and a microSD card
  • Before you start: put your MP3s in a folder called 01 and start each file name with 001, 002 and so on – otherwise the player won’t play the track you expect
  • Effort: about an hour, beginner level, no soldering

Do you even need a microcontroller?

According to the datasheet, the DFPlayer Mini can also work on its own with buttons: a button on IO1 or IO2 skips to the previous or next track, and a resistor ladder on the ADKEY pins lets you wire up several buttons for individual tracks. If all you want is “press a button, music plays”, that’s enough.

The ESP8266 earns its place once you need some logic: a fixed schedule, a specific file per event, volume set in code, or Wi-Fi later on. That’s what this guide covers. An Arduino Uno or Nano works too instead of the ESP8266 – the section “Using an Arduino Uno or Nano” further down explains what changes.

What you’ll need

Links marked with * are affiliate links, which makes them advertising. If you buy through one, I earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. Learn more

Wiring

The DFPlayer takes its 5 V from the ESP8266’s VIN pin, which carries the voltage from the USB port. It’s controlled over a serial connection: the DFPlayer’s TX goes to D6, RX goes to D7. Since the ESP8266 runs at 3.3 V, you don’t need a resistor on the data line. The speaker connects directly to SPK_1 and SPK_2. The schematic shows a NodeMCU V3 board; the pins on the Amica V2 have the same labels.

NodeMCU ESP8266 DFPlayer Mini wiring schematic
Wiring: the DFPlayer Mini is powered from the ESP8266’s VIN and GND, with TX/RX going to D6 and D7.
DFPlayer MiniNodeMCU ESP8266Purpose
VCCVIN5 V from the USB port
GNDGNDGround
TXD6 (GPIO12)Data from the DFPlayer to the ESP8266
RXD7 (GPIO13)Commands from the ESP8266 to the DFPlayer
SPK_1 / SPK_2–Speaker (up to 3 W)
Push button (sketch 2 only)D5 and GNDPlay a track at the press of a button

You can hook up the button without soldering: push a female jumper wire onto each of two diagonally opposite legs. On four-leg buttons, the legs are permanently connected in pairs, so going diagonally always works. You can also seat the button on a breadboard. You won’t need it for the first test.

With an Arduino Uno or Nano, wire it up using the table in the “Using an Arduino Uno or Nano” section further down instead, and skip the “Add the ESP8266 boards” step when you set up the Arduino IDE.

You can download the Fritzing file for the schematic.

AZ-Delivery ESP8266 board with jumper wires attached and a small black speaker next to it
The AZ-Delivery NodeMCU Amica V2 wired up to the DFPlayer, with the speaker on the left.
DFPlayer Mini module with jumper wires plugged in, next to the ESP8266 board
The DFPlayer Mini with six jumper wires attached and the ESP8266 board on the left.

Prepare the microSD card

The DFPlayer plays MP3 and WAV files from cards up to 32 GB formatted as FAT32 (or FAT16). It won’t recognize larger cards or cards formatted as exFAT. Here’s how to prepare the card on Windows:

  1. Insert the card into the reader, then right-click the drive in File Explorer.
  2. Choose Format, set the file system to FAT32 and click Start.
  3. Create a folder called 01 in the root of the card.
  4. Copy your MP3s into that folder and rename them so they start with a three-digit number, for example 001 - Announcement.mp3 and 002 - Chime.mp3.

You can have up to 99 of these folders with up to 255 files each. The sketches below pick a track by folder and file number (playFolder(1, 1) = folder 01, file 001). The simpler play(1) command ignores the file name and goes by the order in which the files were copied to the card – so with several files, it often plays a different track than you’d expect.

Close-up of the DFPlayer Mini MP3 module with its microSD slot and jumper wires
Close-up of the DFPlayer Mini: the microSD card with your MP3s goes into the slot at the front.

Set up the Arduino IDE for the ESP8266

Download and install the Arduino IDE.

Add the ESP8266 boards

Out of the box, the Arduino IDE doesn’t know about the ESP8266. Open File → Preferences.

Arduino IDE preferences
Additional boards are added under File → Preferences.

Paste this URL into Additional boards manager URLs and click OK:

https://arduino.esp8266.com/stable/package_esp8266com_index.json

Then open Tools → Board → Boards Manager, search for esp8266 and install esp8266 by ESP8266 Community.

Arduino IDE boards manager
The Boards Manager lives under Tools → Board.
ESP8266 boards installation
Install the esp8266 package from the Boards Manager.

Next, go to Tools → Board → esp8266 and select NodeMCU 1.0 (ESP-12E Module) – that works for both Amica V2 and V3 boards.

Select NodeMCU board in Arduino IDE
Pick NodeMCU 1.0 (ESP-12E Module) as your board.

Connect the board and select the port

Plug the ESP8266 in via USB and pick the new serial port under Tools → Port. If none shows up, you’re missing the driver for the board’s USB-to-serial chip: Amica V2 boards use a CP2102 (CP210x driver from Silicon Labs), many V3 boards a CH340 (CH340 driver from WCH). The chip name is printed next to the USB port on the board.

Arduino IDE port selection
Choose the ESP8266’s serial port under Tools → Port – COM3 in this case.

Install the DFRobotDFPlayerMini library

Open Tools → Manage Libraries, search for DFRobotDFPlayerMini and install the library by DFRobot. It handles all the commands sent to the DFPlayer. The other library you need, SoftwareSerial, already comes with the ESP8266 package.

Arduino IDE manage libraries
Tools → Manage Libraries opens the Library Manager.
DFRobotDFPlayerMini library in Arduino IDE
The DFRobotDFPlayerMini library handles all communication with the MP3 module.

Sketch 1: Play your first track

The first sketch checks that everything is wired correctly: it starts the DFPlayer, sets the volume and plays file 001 from folder 01 once. Create a new sketch, replace its contents with this code and save it. Both sketches are written for version 3.1.2 of the ESP8266 package and version 1.0.6 of the DFRobotDFPlayerMini library (as of October 2026).

test_tone.ino
// Sketch 1: play /01/001.mp3 once from the DFPlayer Mini (NodeMCU ESP8266)
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// DFPlayer TX -> D6 (GPIO12), DFPlayer RX -> D7 (GPIO13)
SoftwareSerial playerSerial(D6, D7);  // RX, TX
DFRobotDFPlayerMini player;

const uint8_t VOLUME = 15;  // 0 to 30

void setup() {
  Serial.begin(115200);
  playerSerial.begin(9600);
  Serial.println();
  Serial.println(F("Starting DFPlayer Mini ..."));

  // Clone modules: if this fails, try player.begin(playerSerial, false)
  if (!player.begin(playerSerial)) {
    Serial.println(F("DFPlayer not found - check TX/RX wiring and the microSD card"));
    while (true) {
      delay(1000);  // keeps the ESP8266 watchdog happy
    }
  }

  Serial.println(F("DFPlayer ready"));
  player.volume(VOLUME);
  player.playFolder(1, 1);  // folder 01, first file starting with 001
}

void loop() {
  // Print status messages from the DFPlayer (track finished, errors)
  if (player.available()) {
    uint8_t type = player.readType();
    int value = player.read();
    if (type == DFPlayerPlayFinished) {
      Serial.print(F("Finished track "));
      Serial.println(value);
    } else if (type == DFPlayerError) {
      Serial.print(F("DFPlayer error "));
      Serial.println(value);
    }
  }
}

Insert the microSD card into the DFPlayer and click the arrow to upload the sketch. Once the upload finishes, the ESP8266 restarts and plays the track. The serial monitor (magnifying glass in the top right, 115200 baud) shows “DFPlayer ready” and, when the track ends, “Finished track …”. If you open the monitor after the upload, briefly press the RST button on the board – the sketch restarts and you’ll see every message.

Upload button in Arduino IDE
The arrow button uploads the sketch to the board.

Set the volume anywhere from 0 to 30 with VOLUME. If the speaker starts to distort, turn it down.

Sketch 2: Play a track at the press of a button and on a schedule

Now for the actual use case. Connect a push button between D5 and GND – no resistor needed, because the sketch turns on the internal pull-up resistor. Pressing the button plays file 001, and file 002 plays on a fixed schedule – say, an announcement on demand and a chime at regular intervals.

button_interval.ino
// Sketch 2: play a track on a button press and another one at a fixed interval (NodeMCU ESP8266 + DFPlayer Mini)
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// --- Settings -------------------------------------------------------
const uint8_t FOLDER = 1;                                 // folder 01 on the microSD card
const uint8_t BUTTON_TRACK = 1;                           // button plays the file starting with 001
const uint8_t INTERVAL_TRACK = 2;                         // interval plays the file starting with 002
const unsigned long INTERVAL_MS = 15UL * 60UL * 1000UL;  // every 15 minutes, 0 = off
const uint8_t VOLUME = 15;                                // 0 to 30
const uint8_t BUTTON_PIN = D5;                            // button between D5 and GND
// --------------------------------------------------------------------

// DFPlayer TX -> D6 (GPIO12), DFPlayer RX -> D7 (GPIO13)
SoftwareSerial playerSerial(D6, D7);  // RX, TX
DFRobotDFPlayerMini player;

const unsigned long DEBOUNCE_MS = 50;
bool lastButtonState = HIGH;
unsigned long lastButtonChange = 0;
unsigned long lastIntervalPlay = 0;

void playTrack(uint8_t track, const __FlashStringHelper *reason) {
  Serial.print(F("Playing folder "));
  Serial.print(FOLDER);
  Serial.print(F(", track "));
  Serial.print(track);
  Serial.print(F(" ("));
  Serial.print(reason);
  Serial.println(F(")"));
  player.playFolder(FOLDER, track);
}

void setup() {
  Serial.begin(115200);
  playerSerial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);  // pressed = LOW
  Serial.println();
  Serial.println(F("Starting DFPlayer Mini ..."));

  // Clone modules: if this fails, try player.begin(playerSerial, false)
  if (!player.begin(playerSerial)) {
    Serial.println(F("DFPlayer not found - check TX/RX wiring and the microSD card"));
    while (true) {
      delay(1000);  // keeps the ESP8266 watchdog happy
    }
  }

  Serial.println(F("DFPlayer ready"));
  player.volume(VOLUME);
  lastIntervalPlay = millis();
}

void loop() {
  unsigned long now = millis();

  // Button: react once per press, ignore contact bounce
  bool buttonState = digitalRead(BUTTON_PIN);
  if (buttonState != lastButtonState && now - lastButtonChange > DEBOUNCE_MS) {
    lastButtonChange = now;
    lastButtonState = buttonState;
    if (buttonState == LOW) {
      playTrack(BUTTON_TRACK, F("button"));
    }
  }

  // Interval: fixed schedule, a button press does not shift it
  if (INTERVAL_MS > 0 && now - lastIntervalPlay >= INTERVAL_MS) {
    lastIntervalPlay = now;
    playTrack(INTERVAL_TRACK, F("interval"));
  }

  // Print errors reported by the DFPlayer
  if (player.available() && player.readType() == DFPlayerError) {
    Serial.print(F("DFPlayer error "));
    Serial.println(player.read());
  }
}

Everything you might want to change is in the “Settings” block at the top:

  • FOLDER – the folder on the card (1 = folder 01)
  • BUTTON_TRACK and INTERVAL_TRACK – which file the button and the schedule play (1 = file 001); set both to the same number if you want one track for everything
  • INTERVAL_MS – the interval in milliseconds; 15UL * 60UL * 1000UL is 15 minutes, and 0 turns the schedule off so only the button plays the track
  • VOLUME – volume from 0 to 30

Upload the sketch the same way as sketch 1. The serial monitor shows “Playing folder 1, track 1 (button)” every time you press the button and “Playing folder 1, track 2 (interval)” on schedule.

Pressing the button doesn’t shift the schedule, so the chime still arrives on time. To try it out, set INTERVAL_MS to 60UL * 1000UL and the scheduled track plays every minute. The ESP8266 counts the interval from power-on – without Wi-Fi, it has no idea what time it actually is.

DFPlayer Mini, ESP8266 board and speaker connected with jumper wires
The finished build: ESP8266, DFPlayer Mini and speaker, connected with nothing but jumper wires.

Using an Arduino Uno or Nano

Both sketches also run on an Arduino Uno or Nano. What changes are the pins, the power supply and the data line to the DFPlayer: the Uno and Nano send their signals at 5 V, while the DFPlayer’s data pins work at 3.3 V. That’s why DFRobot recommends a 1 kΩ resistor between the Arduino’s TX pin and the DFPlayer’s RX – a breadboard is the easiest place to put it.

DFPlayer MiniArduino Uno / NanoNote
VCC5V
GNDGND
TXPin 10The Arduino’s SoftwareSerial RX
RXPin 11Through a 1 kΩ resistor
SPK_1 / SPK_2–Speaker, same as with the ESP8266
Push button (sketch 2 only)Pin 2 and GND

You only need to change two lines in the sketch – the BUTTON_PIN line only exists in sketch 2:

SoftwareSerial playerSerial(10, 11);  // RX, TX
const uint8_t BUTTON_PIN = 2;         // sketch 2 only

In the Arduino IDE, select Arduino Uno or Arduino Nano under Tools → Board. You don’t need the board manager URL or the ESP8266 package for these boards, and the Arduino IDE already includes SoftwareSerial for them.

Troubleshooting

  • “DFPlayer not found” in the serial monitor: first check whether TX and RX are swapped – the DFPlayer’s TX belongs on D6. Also check that the card is inserted and formatted as FAT32.
  • Still nothing with correct wiring: some DFPlayer clones don’t acknowledge commands the way the library expects. Replacing player.begin(playerSerial) with player.begin(playerSerial, false) has fixed this for several people, as discussed in the library’s GitHub issue. The catch: begin() then always reports success, even with no player connected, so you won’t see “DFPlayer not found” anymore.
  • No sound and no error: the speaker has to be on SPK_1 and SPK_2, not DAC_L/DAC_R. With VOLUME set to 0, it stays silent too.
  • Wrong track plays: make sure the folder and file names start with the number (01, 001) and that the numbers in the sketch match.
  • No port in the Arduino IDE: install the CP2102 or CH340 driver (see above) and try a different USB cable – some cables only charge and don’t carry data.

Frequently asked questions

Does the DFPlayer Mini play WAV files too?

Yes, according to the datasheet it handles both MP3 and WAV. The naming rules are the same as for MP3s: folder 01, with file names starting at 001, 002 and so on.

Can I run the MP3 player on batteries?

Yes, for example with an 18650 battery shield that supplies 5 V over USB. The ESP8266 keeps drawing power between tracks, though, so if it needs to run for days, a power supply is the better choice.

Want to get the ESP8266 onto your Wi-Fi next? Our Wi-Fi temperature sensors with the NodeMCU ESP8266 project shows you how. Have fun building!

Similar Posts