Arduino Controlled MP3 Player Zen Sound Box
by sncarter in Circuits > Arduino
631 Views, 2 Favorites, 0 Comments
Arduino Controlled MP3 Player Zen Sound Box
This is the design and build of an MP3 player controlled by an Arduino Atmega328. My wife wanted a sound box that would play long "Zen" like sounds to fall asleep to such as rain or ocean waves. This project uses the DFPlayer mini MP3 player
Supplies
1 - DFPlayer Mini Aideepen 5PCS DFPlayer Mini Mp3 Player Board YX5200 Module Support TF Micro SD Card U Disk Audio Music for Arduino : Amazon.ca: Electronics or similar
1- DKARDU 18650 lithium battery charger and boost module model JK-US-648 DKARDU 5 pcs 18650 Lithium Li-ion Battery Charger Board 3.7V 4.2V to 5V/9V 1A DC-DC Step Up Boost Module Adjustable Charge and Discharge + 5 pcs 18650 Battery Box : Amazon.ca: Electronics
1 - Daokai 5mm common cathode red/grren/blue tri-color LED DAOKAI 100Pack 5mm LED Light Emitting Diode Common Cathode DC 3V 20mA RGB Tri-Color(Red/Green/Blue) 4Pin Clear Transparent Round LED Buld Lamps Electronics Components for Arduino : Amazon.ca: Tools & Home Impro
1 - I2C 2 x 16 LCD Freenove I2C IIC LCD 1602 Module (2 Pack), New Type TWI Serial 16x2 Display, Compatible with Arduino Raspberry Pi Pico ESP32 ESP8266 : Amazon.ca: Electronics
1 - Loudspeaker full range 4 ohm ACEIRMC 4pcs 4Ohm 5W Full Range Audio Speaker Stereo Woofer Loudspeaker for Arduino Replacement (4pcs) : Amazon.ca: Electronics
1 - Project box 4.7" x 4.7" x 3.5" LeMotech Electrical Box IP65 Waterproof Dustproof Junction Box ABS Plastic Box Electronic Enclosure Black 4.7 x 4.7 x 3.5 inch(120 x 120 x 90 mm)(Pack of 2) : Amazon.ca: Tools & Home Improvement
2 - USB-Micro Power in break out board DAOKAI 10 Pcs Micro USB Female to DIP Adapter 2.54mm 5 Pin USB 2.0 Micro USB Socket to DIP Converter Breakout Board for DIY Power Supply with 50 Pin Header : Amazon.ca: Home
1 - Self Adhesive vinyl Black Permanent Vinyl - 12" x40FT Matte Black Vinyl for Cricut, Self Adhesive Vinyl Roll for for Cricut, Silhouette Cameo - Vinyl for Home Decoration, DIY Mug & Ceramic : Amazon.ca: Home
1 - USB to SD card adapter such as USB C SD Card Reader for iPhone 15/iPad/MacBook/Mac, Type C SD Reader Supports SD and MicroSD Memory Card Adapter, Trail Camera Viewer Plug and Play - 2 Slots : Amazon.ca: Electronics
You can get most of the following on Amazon:
1 - Arduino UNO
1 - Atmega 328P microcontroller
1 - 28 pin IC Socket
1 - 18650 Battery
1 - 18650 single battery holder (DKARDU power modules come with these)
1- prototype board or you can design a PCB and have it made as I did.
4 - 0.1u capacitor thin film or equivalent low voltage
2 - 22pf ceramic capacitor low voltage
1 - 100u electrolytic capacitor 16V
1 - 2N2222A Transistor
5 - 10k Resistors
4 - 330 Ohm Resistor
2 - 1K Resistor
1 - 100 ohm Resistor
1 - 12K Resistor
1 - 10K Potentiometer chassis mount
2 - Pushbutton switch (momentary) chassis mount
1 - Pushbutton switch (latching on/off) chassis mount
1 - 5mm LED red
1 - 16MHZ crystal
2 - knobs for pot and rotary encoder
#18 AWG guage wire - multicolor
solder & flux
Male strip pins
heatshrink tubing
Hot glue
Spray paint - white Matt
#6 nuts and bolts
breadboard
jumper wires
small rubber grommets
Washers as needed
1
Breadboarding - Very Important
This is a bit of a complicated project so it is very important that you breadboard it first. This is mainly because the DFPlayer is difficult to deal with and you should check that you have all the software working and the Arduino talking to the DFPlayer before you actually build it. I'll discuss more on that later.
Use the Arduino Uno board for your microcontroller. Put the DFPlayer and LEDS etc. on the breadboard and connect them to the Arduino UNO with jumper cables. Use the +5V pin on the UNO to power everything.
SCHEMATIC
These are my notes on the circuit diagram:
- USB-Micro connector USB1 is used to power the board directly and bypasses the battery.
- Header H1 and USB-Micro connector USB2 can be used to program the Arduino on board with a programming dongle. On board programming only seems to work when the DFPlayer is not connected. Not sure why. Anyway you can program your ATMEGA 328P on the Arduino UNO and then move it to your project board and you then don't need these connectors if you don't want them.
- IMPORTANT: U6 the battery charger and booster module has a USB-C connector. When plugged in it directly connects 5V to the board regardless of whether the power switch is or on or off. This is because the power switch only controls battery power. VERY IMPORTANT: This module boosts the 3.7V from your battery to anywhere up to 28V! There for it is CRITICALLY IMPORTANT that before you connect it to anything that you adjust it to +5V. You do this with a very small potentiometer on the module. See the picture of the module. The potentiometer is just to the left of the USB-C connector. You will need a DVM (Voltmeter to do this) connect the voltmeter to the +/- out pins on the module, plug the module in to a USB-C power supply or a charged battery, adjust the potentiometer for 5V maximum.
- LED 2, 3 ,4 are all one tri-color LED. This is LED is so bright that I had to add R12 (12K) on the ground lead to reduce the brightness. This LED has 4 leads. You will need to use a DVM to figure out which is which. Or connect it to a +5V supply through a 330ohm resistor to limit the current.
- The LCD display is an I2C display with built in backlight. If you turn this on with the software, then it is quite bright. If you want it dimmer then you need to modify it slightly. Remove R9 on the rear of the display module. See picture. This is a very small surface mount resistor. Use Tweezers to pull it off while you melt the connections on the resistor with a soldering iron. Be careful and be quick doing this so as not to damage the module. Next connect a wire to the Anode of the LED clearly marked as an "A" at one end of the display. This wire connects to R9 which goes to the Arduino pin 9. We place a PWM signal on this pin to control the brightness. Its a bit ridiculous that you can't control the LCD brightness either by software or by a pot on the module, but there you are.
- Transistor Q1 is used to disconnect the speaker during start up as it will make a loud noise on power up - very disturbing and we don't want to hear that every time!
Downloads
DFPlayer Weird and Strange Behaviour and What to Do
This was one of the most frustrating Arduino projects I have ever done mainly due to the DFPlayer. Here are the issues and some solutions:
- I bought 5 modules. I'm glad I did. One didn't work at all, a second one broke somehow when I was putting the circuit board into the box and would not hold the SD Card in. So these modules are physically delicate and possibly unreliable.
- I used a programming dongle to program the Atmega 328P microcontroller on the PCB. This worked until I installed the DFPlayer then refused to work. I have several different dongles. None of them will work with it connected to the Atmega 328P. I don't know why, can't figure that one out. So the programming port and header I provisioned are useless unless you unplug the DFPlayer.
- When you go to save your sound files on the SD Card, first make sure the card is formatted as FAT32.
- You need to number the MP3 Files on your SD Card as 0001, 0002 etc. or 001, 002 etc. Otherwise it won't recognize them.
- Your files need to be MP3 type files.
- For some reason once you place your files on the SD Card, the DFPlayer then does not like it if you change anything such as the file names or order. It seems to remember the configuration you first used and gets confused if you change it. It will often play the wrong files if you do this. So best thing is to decide what sound files you want to play and in what order and copy to your SD Card once only.
- If you do need to change the MP3 files on your SD Card here are things you can try to get around the above issue:
- Completely erase all files on the SD Card and then copy all files you want onto it again.
- Reformat the SD Card and then copy all files you want onto it again.
- Renumber the files. So if you used 0001, 0002 then renumber to 001, 002.
- Copy the files with their original name onto the SD Card, then rename them on the SD Card to 0001, 0002 etc.
- Use a different SD Card.
- In the instructions for the DFPlayer it says you can put any number of files in folders on the SD Card. For a folder called MP3 you use the playMp3Folder() command to play files in that folder for example. This works but you have to place a delay command for the length of the sound/song after the play command otherwise it won't play. For example for a 3 second sound clip delay(3000) is required after the play command. So this works for short sound clips, but not really for anything longer. For long music files place them on the root of the SD Card. Then use the myDFPlayer.play() command. For example to play file 0001 on the root use myDFPlayer.play(1); The issue with this is that you can only place nine files on the root. If you tried to play file 10 the DFPlayer is confused and plays file 1. I don't know a work around for this. Fortunately I don't want to play very many files so it worked for me.
PCB Board or Prototype Board
For this project I designed a PCB board with EasyEDA and had it made by JLCPCB. Shipping time was less than a week. This is easy but it costs a bit to have it done. So this makes it simple to build but not as fast or cheap by far as just using a protoboard. My PCB design was not great, I made quite a few mistakes and also did not account for a few things, so I need to redo it if I want to build anymore of these. I advise you to just use a prototype board as this is not an overly complex circuit.
Arduino Program
The Arduino sketch is fully commented. You should be able to follow/modify it as you wish. Or just load it as is.
Downloads
Construction
Notes on Construction & Other:
- Use rubber grommets or washers under your PCB/Protoboard to position it at the height you want.
- Drill holes and use a file to shape the holes for the USB connectors. Do this once you figure out exactly where your PCB will sit so that the holes for the USB connectors match the connector locations on the PCB.
- Drill holes and use a jigsaw to cut a hole for the LCD screen. Use hot glue to hold it in place.
- Use a drill to drill holes for your speaker grill. I used a paper template to mark out exact hole positions to make it even and nice.
- Drill holes for screws, potentiometer, rotary encoder, buttons etc.
- Use hot glue to hold your battery charger/booster module in place.
- Use self adhesive vinyl to make a bezel (surround) for the LCD to hide the edges of the hole and make it look nice. I did this by carefully measuring the LCD and then cutting the vinyl with a straight edge and Xacto knife.
- For a nicer look spray paint your plastic project box with what ever color you want. White looks nice. Do this only after you have cut and smoothed all the holes. Leave the spray paint to dry for overnight or preferably 24 hours. The can says dries in 5 minutes but actually it is still pretty soft and scratches easily. After a longer period it is much more resistant to scratching.
- Use a black marker and a letter template to write on the box the names of each button and knob etc.
- There are millions of files with music on Youtube for example. Just use a file converter to convert these to MP3 for your project. I like Any Video Converter for this, its free. I also like YTMP3 - YouTube to MP3 Converter for converting Youtube to MP3, also free
MP3 Player Features
This MP3 has the following features built in, mainly due to the software:
- Can exit play and select a new sound or song anytime by pressing the set button.
- Can Pause and Resume play by pressing the Play button at anytime during a song.
- Can select any one of 9 songs/sounds using the rotary encoder.
- Can select the playing time as anywhere from 5 to 600 minutes using the rotary encoder.
- Automatically extinguishes the LED 10 seconds after play starts for low light sleeping conditions.
- Automatically dims the LCD display for low light sleeping conditions.
- Allows adjustment of the LCD brightness with the rotary encoder at anytime except during the setup process.
- Automatically brightens the LCD display for Setup.