Build your own MP3 player like the Toniebox

FunduinoLast updated on

Eine Audiobox bauen, die per RFID-Karte Hörspiele und Musik startet

Audioboxen für Kinder funktionieren alle nach demselben Prinzip: Eine Figur oder Karte wird aufgelegt, und das passende Hörspiel startet von allein. Gesteuert wird nur über wenige große Tasten, damit schon kleine Kinder das Gerät allein bedienen können.

Genau das baust du in diesem Projekt selbst nach. Ein RFID-Modul erkennt, welche Karte aufgelegt wird, ein MP3-Modul spielt die dazu passende Datei von einer SD-Karte ab, und drei Taster regeln Lautstärke und Pause. Am Ende kannst du die Elektronik in ein selbst gedrucktes Gehäuse einbauen.

Breadboard with Arduino, DFPlayer Mini, RC522 RFID module, and three push buttons
Wiring the MP3 module, RFID module, and buttons to the Arduino

Material

For this project, you’ll need:

  • 1× Arduino microcontroller with a suitable USB cable
  • 1× mini breadboard
  • 1× MP3 module MP3-TF-16P (DFPlayer Mini)
  • 1× microSD card with your MP3 files
  • 1× speaker (8 ohms, 0.5–3 watts)
  • 1× RC522 RFID kit with card and key fob
  • 3× push buttons
  • 4× 1000-ohm resistors (1 kOhm)
  • Various breadboard jumper wires

Optional: a 3D-printed enclosure to turn the circuit into a finished box.

Assembly and wiring

Plug the MP3 module and RFID module into the breadboard and wire everything according to the diagram. The overview shows which Arduino pin connects to which terminal:

  • Pin 3 = Volume up button
  • Pin 4 = Pause button
  • Pin 5 = Volume down button
  • Pin 6 = DFPlayer pin 3 (TX)
  • Pin 7 = DFPlayer pin 2 (RX)
  • Pin 9 = RFID module RST
  • Pin 10 = RFID module SDA (SS)
  • Pin 11 = RFID module MOSI
  • Pin 12 = RFID module MISO
  • Pin 13 = RFID module SCK
  • 5V = DFPlayer pin 1 (VCC) and button power supply
  • 3.3V = RFID module 3.3V
  • GND = DFPlayer pin 7, buttons, and RFID module
  • Speaker = DFPlayer pin 6 (SPK_1) and pin 8 (SPK_2)

Connect the three buttons to 5V and pull them down to GND with a 1-kOhm resistor each. This keeps the input at a clean LOW while the button is not pressed. Place the fourth 1-kOhm resistor in the wire from Arduino pin 7 to the DFPlayer's RX input - it protects the module from the Arduino's 5V signal and reduces noise.

Breadboard with Arduino, DFPlayer Mini, RC522 RFID module, and three push buttons
Wiring the MP3 module, RFID module, and buttons to the Arduino

Prepare SD card

The microSD card must be formatted as FAT16 or FAT32. In Windows, simply right-click the removable drive and select “Format…”; under “File system,” select “FAT32.”

Then copy your MP3 files to the card and name them with sequential numbers: 0001.mp3, 0002.mp3 and so on. The DFPlayer will later refer to the files by these numbers. A maximum of 255 files is possible, so the last one is named 0255.mp3.

Formatting erases all data on the card. Back up anything you want to keep beforehand.

Install libraries

You need two libraries for this project. In the Arduino IDE, open the Library Manager via Sketch → Include Library → Manage Libraries or by clicking the icon in the left sidebar.

  • Search for DFRobotDFPlayerMini and install the library by DFRobot.
  • Search for MFRC522 and install the library for the RFID module.

The SoftwareSerial and SPI libraries are already included in the Arduino IDE and do not need to be installed separately.

Source code

Upload the sketch to the microcontroller, then open the Serial Monitor at a baud rate of 115200. As soon as you hold an RFID tag up to the module, its card number will appear there.

Sketch: MP3 box with RFID control
//Library to work with the DFPlayer.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
//Libraries to work with the RFID module.
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);
SoftwareSerial mySoftwareSerial(6, 7); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

//Assigns a pin to each button.
int TasteVolumeUP = 3;
int TasteVolumeDOWN = 5;
int Pause = 4;

//Stores whether a button is pressed or not.
int STATUSup = 0;
int STATUSdown = 0;
int STATUSpause = 0;

int Volume = 15;  //Stores the set volume
int iPause = 0;   //Indicates whether playback is paused or not.

void setup()
{
  SPI.begin();
  mfrc522.PCD_Init();
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  pinMode(TasteVolumeUP, INPUT);
  pinMode(TasteVolumeDOWN, INPUT);
  pinMode(Pause, INPUT);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //SoftwareSerial for communication with the MP3 module
    Serial.println(F("Error:"));
    Serial.println(F("1.Connect the MP3 module!"));
    Serial.println(F("2.Insert a memory card!"));
    while (true);
  }
  myDFPlayer.volume(Volume);  //Set the volume between 0 and 30. We assigned the variable a value of 15 as the starting value.
}

void loop()
{
  STATUSup = digitalRead(TasteVolumeUP);
  STATUSdown = digitalRead(TasteVolumeDOWN);
  STATUSpause = digitalRead(Pause);

  // Now check what should happen when the pause button is pressed. If the device is playing, it should pause. If it is already paused, playback should resume.
  if (STATUSpause == HIGH)
  {
    if (iPause == 0)
    {
      myDFPlayer.pause();
      delay(500);
      iPause = 1;
    }
    else if (iPause == 1)
    {
      myDFPlayer.start();
      delay(500);
      iPause = 0;
    }
  }

  if (STATUSup == HIGH && Volume < 30) // If Volume+ is pressed and the maximum volume (value 30) has not yet been reached, increase the volume.
  {
    Volume = Volume + 5;
    myDFPlayer.volume(Volume);
    Serial.println(Volume);
    delay(500);
  }

  if (STATUSdown == HIGH && Volume > 0)  // If Volume- is pressed and the minimum volume (value 0) has not yet been reached, decrease the volume.
  {
    Volume = Volume - 5;
    myDFPlayer.volume(Volume);
    Serial.println(Volume);
    delay(500);
  }

  // Read the RFID tag here
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }

  long code = 0;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    code = ((code + mfrc522.uid.uidByte[i]) * 10);
  }

  // Display the card number in the Serial Monitor.
  Serial.print("The card number is: ");
  Serial.println(code);

  // IMPORTANT! In our case, the code of the first RFID tag is 446250. You must first determine the code of your own RFID tag by uploading this sketch and reading the number in the Serial Monitor.
  if (code == 446250) //If the code is 446250, play the MP3 file named 0002.mp3
  {
    iPause = 0;
    myDFPlayer.play(2); //Call the MP3 file "0002.mp3" here
    delay(600);
  }

  if (code == 1427270) //If the code is 1427270, play the MP3 file named 0001.mp3
  {
    iPause = 0;
    myDFPlayer.play(1); //Call the MP3 file "0001.mp3" here
    delay(600);
  }
}

Assign an MP3 file to an RFID tag

Now you decide which RFID tag starts which MP3 file. Hold the tag up to the module and read its number in the Serial Monitor.

Example: A new tag is detected with the number 123456 and should play the file 0012.mp3. Then edit the corresponding block in the sketch so that both the card number and the file number match.

For each additional tag, copy a block like this and enter its number and file number.

The card numbers in the sketch are example values from our setup. Your TAGs have different numbers - nothing will happen when you hold them up unless you adjust these numbers.

Previously in the sketch
if (code == 446250)
{
  iPause = 0;
  myDFPlayer.play(2); // The MP3 file "0002.mp3" is called at this point
  delay(600);
}
Adapted for the new RFID tag
if (code == 123456)
{
  iPause = 0;
  myDFPlayer.play(12); // The mp3 file "0012.mp3" is called at this point
  delay(600);
}

Enclosure

Finally, you can install the electronics in an enclosure. There are no limits to your creativity here. We designed our example enclosure with Tinkercad; it’s a good starting point for your own ideas.

Go to the 3D model on Thingiverse

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.