This is my third MP3 player project. (I have submitted it to Instructables.)
This time I chose the easily available, cheap “DFPlayer Mini” module.
It has a “Random play” mode BUT because it is random, it is possible for tunes to repeat!
My design uses a PIC microcontroller to “Jumble-Up” the music to play randomly without repeats. (while powered on).
It also overcomes the restrictions on file names and folders caused by the DFPlayers’ limited file system.
Now you can put all your music files directly onto an micro SD-card or USB memory stick without having to rename
them or bother about folder names.
- At power-on, the tunes are jumbled-up to prevent repeats.
- Simply controlled by one knob, turn for volume, press for next tune!
- Uses a ready made “DFPlayer” MP3 module to play up to 32Gb of tunes!
- Tunes can be played from a Micro-SD card or USB stick
- RGB LEDs for mood lighting while playing and status indications.
- Uses two 60W Class-D Power Amplifier Modules.
- A sensor pauses playing when no user movement is detected.
- Can also be controlled by an IR remote (NEC protocol)
- Push-button for choosing and saving EQ Modes
- Volume setting is saved even after power-on.
- Amplifier is muted between tracks and at power-on to prevent “pops”.
- For the case I used an old “Boxee Box” streaming TV player that was discontinued by the manufacturer back in 2012.
Step 1: Supplies & Tools
- D-SUN 3 Amp Regulator module (Ebay or Aliexpress)
- DFPLAYER Mini MP3 Module (Ebay or Aliexpress)
- TPA3118 PBTL M O NO 60W AMPLIFIER MODULE (Ebay or Aliexpress) X 2
- PIC18F14K50-I/P PIC Microcontroller (DIP type)
- 100uF Capacitor Radial Electrolytic 25V Working
- 47uF Capacitor Radial Electrolytic 16V Working
- 0.1uF Capacitor 2.5mm Y5V Ceramic 50V working X 5
- 0.47uF Capacitor 2.5mm Y5V Ceramic 50V working
- 100uF Capacitor Radial Electrolytic 16V Working X 2
- BAT85 Schottky barrier diode
- Fuse 3A poly Resettable (30v Working)
- Lengths of 2.54mm Pin Header Strip to cut as required
- “Dupont” type 2.54mm female crimp sockets. 2-way X 3 & 3-way X 3
- 2.1mm DC Socket PCB R/Angle Mount
- USB A Female Through Hole PCB Socket
- BC327 Transistor TO-92L
- 10k 1/8W Carbon Film Resistor (5%)
- 22R 1/8W Carbon Film Resistor (5%) X 2
- 470R 1/8W Carbon Film Resistor (5%)
- 10K 1/8W Carbon Film Resistor (5%) X 9
- 100R 1/8W Carbon Film Resistor (5%)
- 1K 1/8W Carbon Film Resistor (5%)
- 10k Preset Potentiometer 6mm X 2
- Rotary Encoder With Switch type EC11 (Ebay or Aliexpress)
- Addressable LED PL9823 5mm or WS2812B SMD (1 or more)
- TL1838 VS1838B HX1838 Infrared Receiver – OPTIONAL (Ebay or Aliexpress) ( See Step 6 )
- Microwave Radar Sensor RCWL-0516 Module – OPTIONAL (Ebay or Aliexpress)
- 28-Pin DIP / DIL PCB IC Socket (0.3”) (for the PIC)
- Small Push Button (Normally Open)
- IR Infrared Remote Control (NEC Protocol) – OPTIONAL (Ebay) ( See Step 6 )
- Knob for Rotary Encoder
- 4 way Push Spring Load Speaker Terminals (Ebay)
- Double-sided 1.6mm thick copper PCB board
- DC power adaptor (12V 5 Amp or 19.5V 4 Amp PC power brick)
- Speakers X 2 (I used 6 Ohm impedance rated for up to 65W )
- Equipment wire
- “Toner transfer” laser printer paper
- PCB etching tools – Ferric Chloride and plastic container etc.
- PCB plastic standoff screws and nuts X 4
- M3 screws and nuts (for speaker terminals) X 4
- Heat shrink sleeve
- Small, Fine tip Soldering iron.
- Safety goggles for use while soldering, etching etc.
- Laser printer with manual paper feed (for toner transfer PCB method)
- Household iron (for toner transfer PCB method)
- ESD Wrist strap (for handling static sensitive parts)
- PCB drill
- PCB drill bits, 0.8mm, 1mm, and a step drill bit (3-13mm)
- Pliers, Cutters, Fine hacksaw, file
- Microchip PIC programmer (eg. Pickit2)
- Microchip MPLAB or PICkit2 standalone programmer software
- Hot melt glue gun and glue sticks
- Rotary “Dremel” type tool
- Crimp tool (SN-28B) for “Dupont” sockets (Ebay or Aliexpress)
Step 2: Circuit Diagram and How It Works
Microchip PIC Microcontroller
The heart of the circuit is a Microchip PIC18F14K50 microcontroller. This chip was chosen as it has just enough
memory available to jumble-up the music, fairly small (20 pins) and low cost. It is programmed in Assembler
Language to control a DFPlayer Mini MP3 module using a serial data protocol. (9600 Baud).
Dfplayer MP3 module
The DFPlayer module is a very low cost device for playing MP3 files using a built in Mini-SDCard holder or via an external USB stick if fitted. It has a 24-bit DAC output and 2 Watt Amplifier (Not used in this project). This module is easily available from Ebay.
It does have a few issues.
- The module layout causes some audible noise interference (particularly when selecting a tune or when playing very quiet sections.
- Not all sellers supply the modules with the original YX5200-24SS chip. (Some of the alternative chips may not work as expected.)
This design tries to minimise the noise issue by muting the amplifier modules whenever music is not playing.
The PCB has ground planes to help reduce noise. (Don’t use breadboard!).
At power-on, the PIC requests the total number of tunes available on the DFplayer sd-card or USB stick.
It jumbles-up these tunes and then commands the player to start playing.
The complete play sequence is kept in the PIC memory while powered-on. This ensures that while powered on, a tune cannot repeat until every tune on the SD-CARD has been played.
When a tune finishes, the player’s busy line goes high, the PIC selects the next tune and sends the play command to the player.
The player volume is controlled by a rotary encoder. On each turn of the knob, the PIC senses the turn direction and sends commands to the player to set the new volume level. The selected volume level is saved to the PIC eeprom to be retained even after power-off.
The Rotary Encoder Button
A short press instructs the PIC to select a new tune. If the the button is held pressed for a few seconds, the PIC stops the current tune and mutes the amps. The next press of the button selects and plays a new tune.
The EQ Button
Each press of the EQ button makes the PIC cycle through the available EQ modes and sends the command to the player. The chosen mode is saved to eeprom.
The six available EQ modes are indicated by the RGB led colour:
- Off (No EQ)
- Red (Pop)
- Green (Rock)
- Blue (Jazz)
- White (Classical)
- Magenta (Bass)
- These EQ modes don’t seem to match their description very well! (The Blue (Jazz) mode is my favourite).
D-SUN Voltage regulator module
The PIC microcontroller, DFplayer module and RGB LEDs are powered at 5V by a D-Sun 3 Amp high efficiency switching regulator module. (available from Ebay).
The regulator module has a variable resistor which must be adjusted to output exactly 5 Volts before connecting it to any part of the circuit. Alternatively there is a similar version of the D-SUN regulator module available from some Ebay sellers that has a fixed 5V output. It looks identical to the original module except the small variable resistor has been replaced by a 44.2KOhm (63C) SMD resistor.
TPA3118 Amplifier Modules
The two TPA3118 Class D (Digital) 60W power amplifier modules are powered directly from an external DC power supply which can be between 8 to 19.5 Volts rated at least 3 Amps.(A 12V or 19.5V laptop power brick could be used).
The TPA3118 chip is actually a 30W stereo amp that is being used in mono mode (PBTL) to achieve a maximum of 60W power at 10% THD (using a 4 Ohm speaker and 21V power supply).
In reality about 30W maximum per module is possible at less than 1% THD as they don’t have a heat-sink. There is a “Standby” (mute) input on each module. This is switched by PNP transistor Q1. The PIC puts them into standby whenever not playing tunes and also during power-off, the diode D1 and capacitor C11 maintain a voltage to keep Q1 on long enough to prevent speaker “pop”.
Jumper JP1 sets the standby polarity signal to match the Amp Module (this allows for different amplifier module types to be used if you want).
Addressable RGB LED/s
Mood and status lighting is provided by one or more addressable RGB LEDs. Either a 5mm through hole PL9823 or SMD WS2812B type can be used.
Jumper JP2 needs to be set to match the LED type as they have slightly different colour tables. This ensures the correct status colours are always displayed.
If more than one LED is used, it can be connected in parallel with the first. (The Data OUT pin is not used).
A VS1838B IR 38Khz remote sensor can be fitted to J4. This allows the player to optionally be controlled by an NEC protocol IR remote control.
The remote control performs the same functions (Volume, Next Track, Stop and EQ selection) plus Pause/Resume. The remote control was obtained from Ebay.
The player is pre-programmed to work with the NEC key codes for that exact model. Other types that use the NEC protocol may be configured (See the Remote Control setup section below).
This pauses the player if no-one is listening to it. A body movement sensor can be connected to J5. A microwave “radar” type RCWL-0516 module works well as it has good movement sensitivity/range and can easily fitted inside the mp3 player case (not metal).
Any detected movement keeps the tunes playing. If there is no movement within 5 minutes, the player pauses the tune and puts the amps into standby mode. When movement is detected again, the tune resumes.
If the movement sensor is not installed the player does not timeout.
Step 3: Construction
I made the PCB using the “Toner transfer method” on a double-sided board (approx 10.3 x 7.3 cm).
Download the two PDF files (one for each copper layer).
Print them on to toner transfer paper using a laser printer at 100% scale.
The two transfer sheets need to be precisely aligned.
(I got best results using special transfer paper (thin glossy yellow sheets) obtained from Ebay or Aliexpress).
The D-SUN regulator needs to be prepared by soldering pairs of 2.54mm header pins to the component side of the module input and output holes as shown in the photo above. (this allows the module to be fitted upside-down on the pcb later). Connect a DC supply (about 9-12 V) to the IN+ and IN- pins and measure the voltage on the OUT+ and OUT- pins. Adjust the small variable resistor to get the voltage as close to 5.00V as possible. The resistor adjustment is very sensitive, if 5.00V is difficult to achieve, set it slightly below.
The two TPA3118 Amp modules can be fitted with header pins on the underside for fitting to the PCB. A small modification can be made to improve the sound quality. By default, the amplifier gain is preset very high (36dB) for maximum volume. This causes some hiss and instability. It can be optionally reduced to 20dB, resulting in much less hiss and better audio quality (at the expense of maximum volume) by removing one SMD resistor R27 on each module.
Resistor R27 (see photo above) can be removed by carefully heating it up with a fine soldering iron tip and then removing it with tweezers. (It is a very small resistor, a magnifying glass may be needed to do this! ).
Jumper JP1 (Amplifier muting polarity)
When using the default TPA3118 module. Jumper the two left pads of JP1 as shown in the photo below.
Jumper JP2 (RGB LED type)
If using WS2812 LED, Jumper the two left pads of JP2 as shown in the photo below.
For PL9223 type LEDs, jumper the two right pads of JP2 instead.
Step 4: Software
Here is the HEX file firmware for the PIC18F14K50 microcontroller.
Step 5: Preparing Memory Card and MP3 Files
The player can use either a Micro-SD card or USB stick with a capacity up to 32GB.
Before first use, the memory card/stick will need to be formatted using a PC.
If the card capacity is less than 4GB , PCs usually automatically use the FAT or FAT16 file system (which is fine).
If the card is more than 4GB you may need to manually select FAT32 file system when formatting for it to work.
If you have a music collection too large to fit on your memory card, use a music manager program such as MediaMonkey to create a new playlist. Edit the new playlist and sort by “random” to mix-up all of your music collection. Then choose the “Send To” option and then “Folder Copy” and select to copy to the drive letter for your memory card. MediaMonkey will then copy a random selection of your music collection to the memory card until it is full.
Step 6: Initial Checks and Setup
At power-on the RGB LED should glow blue.
The DFPlayer has a red or blue led which should light when it starts playing.
The RGB LED should begin slowly changing colour.
Turn the knob to check it controls the volume correctly. (If it goes lower when turned clockwise then the A and B pin connections on the encoder need to be transposed).
Press the button and the next tune should play.
Adjust the two variable resistors to get the best volume and balance from the speakers.
Remote Control Setup
Only the NEC remote control protocol is supported.
The player is pre-programmed to work with the remote shown in the photo above.
I obtained it from Ebay (described as: HX1838 VS1838 Arduino Infrared IR Wireless Remote Control Sensor Module Kits). It came complete with the IR sensor on a small PCB.
It has the arrow buttons below the keypad as shown in the photo.
(A similar type available marked “KEYES” with the arrow buttons above the keypad has different keycodes requiring you to program it as shown below)
If your remote control is not exactly the same as the photo above, it will need to be setup:
- Hold the Encoder button pressed and turn on the power. (The LED should flash light green)
- Release the button (LED stops flashing and stays light green).
- Press the remote button you want to use for NEXT Tune e.g. ” > “
- The player should then start playing a tune and the LED goes Red.
- Press the remote button to use for VOLUME UP e.g. ” ^ “
- The LED should go Yellow.
- Press the remote button to use for VOLUME DOWN e.g. ” v “
- The LED should go Green
- Press the remote button to use for STOP e.g. “OK”
- The LED should go Sky Blue • Press the remote button to use for PAUSE e.g. “#”
- The LED should go Violet • Press the remote button to use for EQ e.g. “1”
- The LED should go White for 1.5 seconds
- Then the LED flashes Green
- Press the Encoder button until the LED stops flashing – to save the settings.
Step 7: Error Codes
- LED rapidly flashes Blue – Either No sdcard, usb stick or files found.
If this happens at power-on – Check the sdcard or usb stick is correctly formatted and mp3 files are present.
If this happens while playing, it could be a problem reading a file due to a slow or incompatible sdcard/usb stick.
Try using a different sdcard/usb stick.
- LED rapidly flashes Red – timeout waiting for Dfplayer module to initialise.
This can occur at power-on if the dfplayer module fails to initialise within 5 seconds.
It could be caused by a slow or incompatible sdcard/usb stick, a faulty Dfplayer module or a circuit fault.
Try using a different sdcard/usb stick. If still the same, remove the sdcard/usb stick and power-on. The LED should now flash Green if the Dfplayer is working. If it still flashes Red, check all wiring or replace the Dfplayer module.
- LED rapidly flashes Green – No sdcard or usb stick found at power-on.
Insert an sdcard or usb stick.
Step 8: Putting It in a Case
You could probably just put it in a general purpose plastic case or some other redundant equipment case.
I had an old “Boxee Box” TV streaming box lying around since the manufacturer stopped support for it in 2012
I removed the electronic boards then reassembled the two halves of metal chassis that held the main board.
I drilled holes in the top of the chassis and fitted plastic spacers to hold the new board (only three spacers could be fitted because the boxee chassis had a large cut-out where the fourth spacer should go.)
I kept the boxee (power) pushbutton and cable to be re-used as the EQ button.
The boxee had an edge-lit logo on the front panel. I removed the original two leds and replaced them with two WS2812 RGB pixel leds fixed with hot-melt glue.
(I also changed the “BOXEE” logo to show “BOX” using a dab of black paint.)
A hole was drilled in the top for the rotary encoder.
The rear panel had to have several cutouts carefully made with a “Dremel” rotary cutter and file for the power, usb socket, sdcard slot and the two speaker connectors.
The IR remote receiver was fitted to the front panel near the logo by drilling a small hole partially into the black plastic just far enough to reach the transparent front panel plastic sheet (and scraping-off the black back coating).
It was then fixed in place with hot-melt glue.
The “radar” movement sensor was insulated with heat shrink sleeve and glued to the front panel.
The box was then fitted-back together (it is tricky to get everything to go back together!).