DFPlayer Mini MP3 Module with Arduino

FunduinoPublished on

Von der SD-Karte bis zur Türklingel mit eigener Ansage

Mit diesem winzigen Modul – kaum größer als eine microSD-Speicherkarte – setzt du Projekte mit Tonausgabe um. Einen Miniaturlautsprecher schließt du direkt an, ein Verstärker ist nicht nötig. Für die Sprachausgabe eines kleinen Roboters ist das ideal.

DFPlayer Mini MP3 module in size comparison
The DFPlayer Mini MP3 module - barely larger than a microSD card

You need this

5 V buzzer - electromagnetic sounder, 2400 Hz 5 V buzzer - electromagnetic sounder, 2400 Hz 0,90 € *Item no. F23108736About the product — 5 V buzzer - electromagnetic sounder, 2400 Hz
MP3-TF-16P V3.0 MP3 player - microSD up to 32 GB, serial MP3-TF-16P V3.0 MP3 player - microSD up to 32 GB, serial 3,11 € *Item no. FUN-1010563About the product — MP3-TF-16P V3.0 MP3 player - microSD up to 32 GB, serial
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm

All 5 parts together 19,77 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Prepare the SD card

Format the memory card by right-clicking the removable drive, then select FAT32 under File System. Warning: This will delete all data on the card.

So you can start programming right after assembling everything, you’ll need a few sound files in MP3 format. You can record spoken files yourself on a computer. If you don’t like hearing your own voice - especially when it comes from a bush - you can have it generated online: Search for “Text to MP3” or “Text-to-MP3”; several providers offer this for free.

For this guide, save three MP3 files to the microSD card: 0001.MP3, 0002.MP3, and 0003.MP3.

Important: The SD card must be formatted as FAT16 (uncommon) or FAT32. The module will not recognize the card with other file systems.

The circuit diagram

It's best to plug the module into a breadboard to keep your setup organized. If space is limited, you can also connect it directly to the Arduino using individual male/female jumper wires.

Since you can connect a speaker directly to the module, we'll use a typical miniature speaker from the Funduino learning set and wire it to the MP3 module.

Schematic of the DFPlayer Mini connected to an Arduino and speaker
Circuit diagram: DFPlayer Mini with speaker connected to Arduino

Install and test the library

Next, you’ll need a suitable library. Install it through the Library Manager. Here, we’re using the one from DFRobot. Other suitable libraries are available with different advantages, such as using less memory by offering fewer features.

To get started, open the example code under File → Examples → DFRobotDFPlayerMini → GetStarted. Upload the sketch to the board without making any changes, then immediately open the Serial Monitor. If everything worked, you should already be hearing sounds from the speaker.

The Serial Monitor shows whether the module is connected correctly and ready to use. If there are problems, you’ll find hints there, such as a missing SD card or incorrect wiring. If you can’t hear anything after checking everything, increase the volume: in the sketch, find the line myDFPlayer.volume(10); and enter the maximum value, 30.

Practical tip: This sketch transmits at 115200 instead of 9600 baud. Change the value in the serial monitor, otherwise you'll only see garbled characters.

Arduino IDE library manager with DFRobotDFPlayerMini
The DFRobot library in the Library Manager
Menu path to the GetStarted example sketch
The example sketch GetStarted in the File → Examples menu
1 / 2

The program code in its simplest form

The included code is already quite unwieldy for a GetStarted sketch. Here you can see it in its minimal form: it only plays an MP3 file, making it a good starting point for your own applications.

There are plenty of ideas - here are a few combinations:

  • MP3 module + temperature sensor = talking fever thermometer
  • MP3 module + motion detector = burglar deterrent
  • MP3 module + ultrasonic sensor = distance warning
  • MP3 module + push button = doorbell with an announcement
  • MP3 module + RFID kit = audible access confirmation
  • MP3 module + moisture sensor = the grumbling plant

Attention: All three shortened sketches are missing the call myDFPlayer.begin(mySoftwareSerial); which is included in the supplied GetStarted sketch. Without it, the module is not initialized. Please check before publication.

Minimal form: play an MP3 file
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
  mySoftwareSerial.begin(9600);
  myDFPlayer.volume(30);  // Set volume to maximum (30)
}
void loop()
{
  myDFPlayer.play(1);  // Play the first MP3 file
  delay(3000); // The sketch pauses for three seconds after playback.
}

Doorbell with voice announcement

Let's start with the doorbell: When you press the button, the module plays the MP3 file from the SD card. In addition to the existing setup, connect a push button to pin 7.

Doorbell with voice announcement
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int taster = 7; // The word "taster" now stands for the value 7.
int tasterstatus = 0; // This is where it is stored whether the button is pressed or not.
void setup()
{
  mySoftwareSerial.begin(9600);
  myDFPlayer.volume(30);  // Volume at maximum (30)
  pinMode(taster, INPUT); // The pin with the button (pin 7) is now an input.
}
void loop()
{
  tasterstatus = digitalRead(taster); // Read pin 7. The result is HIGH (5 volts) or LOW (0 volts).
  if (tasterstatus == HIGH) // If the button is pressed …
  {
    myDFPlayer.play(1);  // … the module plays the first MP3 file.
  }
}

The scolding houseplant

As a second example, you'll program the grumpy houseplant. Connect a moisture sensor to analog pin A0. Save an MP3 file to the SD card with the following message: “Hey you there, yes, you! I'm thirsty! Bring me something to drink.”

As soon as the moisture level drops below the threshold of 300, the DFPlayer Mini plays the MP3 file.

The scolding houseplant
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int messwert = 0; // The sensor reading will be stored here later.
void setup()
{
  mySoftwareSerial.begin(9600);
  myDFPlayer.volume(30);  // Set volume to maximum (30)
}
void loop()
{
  messwert = analogRead(A0); // The voltage at the sensor is read and stored in "messwert".
  if (messwert <= 300) // If the reading is 300 or less …
  {
    myDFPlayer.play(1);  // … the module plays the first MP3 file.
  }
}

Done!

Weitere Informationen über das Modul findest du beim Hersteller: wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299

Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.