DEV Community

Maxime Chéramy
Maxime Chéramy

Posted on

DIY: I've built a music box for the 2nd x-mas of my son

For last Christmas, I wanted to offer my son a music box. But I wanted it to be unique so I decided to build it myself.

In this article, I describe the main components, with links to the source code and schematics. It's not a tutorial but it can be useful if you want to do something similar.

The MP3 music player


The music box is an MP3 player with 6 playlists, volume buttons, previous, stop and next buttons.

Here are the components:

  • ELEGOO nano (4€)
  • DFPlayer Mini (3.5€)
  • CQRobot speaker 3 Watt 8 Ohm (4€)
  • Buttons (11€)
  • PCB boards + wires kit (10€)
  • Battery holders (3€)
  • Wooden box (8€)

The cost of this project is less than 50€, if I don't count my mistakes (2 wooden boxes wasted because the first one was slightly too small, and the second one I drilled a hole on the wrong side).


The player is based on an Arduino nano and a DFPlayer Mini.

Image description

The buttons are not shown on this schematic but they are connected to the following pins:

  • volume down: B2
  • volume up: B3
  • playlists: B4 to B9
  • previous: B12
  • stop: A0

Arduino nano

The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega328. I decided to use an Elegoo model, which is compatible but much cheaper.

The board is powered by 6 AA batteries (~9V), and we use the +5V output to power the DFPlayer Mini.

DFPlayer Mini

The DFPlayer Mini is a small MP3 module that can play mp3 files from an SD card or a USB stick. The documentation is available there:

It is actually challenging to find a legit DFPlayer Mini, the one I received is based on a MH2024K-16SS chip. This means that the firmware is different and the commands are different.


The source code of this project can be found here:

To develop on the Arduino, I use PlatformIO.

DFPlayer support

Probably the most difficult part of this project was getting the DFPlayer to work. I accidentally bought a cheap copy based on a different chipset. I thought it was broken but it just behaved differently (no checksums, different codes for commands).

There are several libraries available to control this chipset with an Arduino. I decided to use the DFMiniMp3 library, and in order to make it work with my module, I contributed to the library:

Main program

The logic is quite simple:

  • Configuration of the Arduino for all the buttons

  • Configuration of the DFPlayer

  • In a loop, we read the state of all the buttons.

    • If a button is pressed (for at least 50ms), we store the button index in a variable named currentButton
    • If no button is pressed (for at least 50ms), we call the buttonUp function with currentButton.
  • The buttonUp function calls the appropriate function to change the volume, playlist, etc.

The volume level and the current playlist are stored in the EEPROM of the Arduino.


I built this box exactly 1 year ago, I now have some feedback about it.

One of my biggest fear was that it would simply not work properly. Especially because of this fake DFPlayer Mini which doesn't seem as good as the original (missing commands, need to add extra delays). It turns out that this module seems to work fine. However, I have some reliability issues with the battery holders that... don't hold the batteries after a drop. Or faulty contacts (I decided not to show pictures of the inside of the box because I'm too ashamed of my soldering).
The autonomy is good enough, but I didn't implement anything to automatically turn off the board after some inactivity. As a result, if the box isn't switched off, I will have to replace the batteries.

Apart from these minor issues, it works great. I really enjoyed working on this project and my son loves his music box.

Top comments (3)

djbobr profile image
Ondrej Ulehla • Edited

Dude, this is beautiful device!
It is great to see that I am not alone having the completely similar idea one year ago. The only difference is that my music box was made for my daughter's 1st b-day.
It was a very quick project as I was struggling with DFPlayer clone (yes, that one - MP3-TF-16P which I could not control correctly using UART and I had no clue about omitting checksums etc.) so I had to order the original DFRobot module and it arrived two days before the b-day. But I finished the music box in last minutes before the celebration party :)
My daughter is still very happy using this box. I added a circuit with CMOS 555, MOSFET and tilt switch so the power consumption is almost zero when idle but the box works few minutes since any movement.

Image description

Image description

Best regards,
Ondrej dj-bobr Ulehla, Czech Republic
dev (at)

ibenstokesy profile image
Ben Stoke

Congratulations on successfully building the unique MP3 music box for your son! Despite minor issues with battery holders, it's heartening to hear that your project turned out well, and your son enjoys the music box you created.

cicirello profile image
Vincent A. Cicirello

Cool project. Thanks for sharing.