Introduction: Infrared Controlled MP3 Player
Build an infrared remote controller MP3 player for about $10 (usd). It has the usual features: play, pause, play next or previous, play a single song or all the songs. It also has equalizer variations and volume control. All controllable through a remote.
Remote Key: Function + 01: Volume down + 02: Set to directory #2. + 03: Volume up + 4...9: Select the following equalizer settings: ++ (4)DFPLAYER_EQ_POP (5)DFPLAYER_EQ_CLASSIC (6)DFPLAYER_EQ_NORMAL ++ (7)DFPLAYER_EQ_ROCK (8)DFPLAYER_EQ_JAZZ (9)DFPLAYER_EQ_BASS + OK: Pause + OK: Play + >>: Play next + <<: Play previous + Up: Play next directory songs + Dn: Play previous directory songs + *|Return: Loop single song: on + #|Exit: Loop single song: off
The first step is testing the Arduino and wiring it to the breadboard. The steps following that are designed to work independently. Each step has wiring instructions and testing instructions. When I build projects, I wire and test each component to confirm they are working. This helps integrating components because know that each work and I can focus on the integration requirements.
This Instructable requires that you have the Arduino IDE installed. You are also required to have the basic skills to download an Arduino sketch program from the links in this project, create a directory for the program (directory name same as the program name). The next steps are to load, view and edit the program in the IDE. Then, upload the program through a USB cable to your Arduino board.
- Nano V3 ATmega328P CH340G Micro controller board for Arduino. As an alternative, you can use an Uno.
- Infrared receiver and remote control. I used an IR Wireless Remote Control Module Kits which came with an Infrared receiver and infrared remote control.
- One resister, 1K to 5K. I'm using a 5K resister because I have a bunch of them. The resister removes noise that exists when not using the resister.
- Breadboard Wire cables
- 5 volt wall adapter
I bought the parts on eBay, mostly from Hong Kong or China distributors. US distributors sometime have the same or similar parts for reasonable prices and faster delivery. The China parts take from 3 to 6 weeks to be delivered. The distributors I've used have all been reliable.
Approximate costs: Nano $3, Infrared kit $1, breadboard $2, package of 40 wire cables $1, $1 for a 5 volt wall adapter. Total, about $8. Note, I bought the Nano with the breadboard pins already soldered in place, as I my solder skills are poor.
Step 1: Add the Arduino Nano to the Breadboard
Plug the Arduino Nano into the Breadboard. Or, if you prefer, you can use an Arduino Uno for this project; they both use the same pins for this project. Connect the Nano (or Uno) to your computer via a USB cable.
Connect power and ground from the Arduino to the breadboard's power bar. Connect the Arduino 5+ pin to the breadboard's positive bar. Connect the Arduino GRN (ground) pin to the breadboard's negative (ground) bar. This will be used by other components.
Download and run the basic Arduino test program: arduinoTest.ino. When running the program, the onboard LED light will turn on for 1 second, then turn off for 1 second. Also, messages are posted which can be viewed in the Arduino IDE Tools/Serial Monitor.
+++ Setup. + Initialized the on board LED digital pin for output. LED is off. ++ Go to loop. + Loop counter = 1 + Loop counter = 2 + Loop counter = 3 ...
As an exercise, change the time delay on the blinking light, upload the changed program, and confirm the change.
In the above photo is a 140 piece solderless breadboard jumper wire kit box you can get for 3 to 5 dollars. They make boards neater that using long cables for short connections.
Step 2: Add the Infrared Receiver and Connect It to the Arduino
Plug the female to male cable wires into the infrared receiver(female ends). Connect the ground pin of the clock module, to the breadboard's ground bar strip. Connect the power pin of the clock module, to the breadboard's positive bar strip. Connect the output pin of the infrared receiver, to the Arduino A1 pin.
Connect infrared receiver, pins from top left to right: Left most (next to the X) - Nano pin A1 Center - 5V Right - ground A1 + - - Nano pin connections | | | - Infrared receiver pins --------- |S | | | | --- | | | | | | --- | | | ---------
In the Arduino IDE, install an infrared library. Select Tools/Manage Libraries. Filter your search by typing in ‘IRremote’. Select IRremote by Shirriff (for reference, the library GitHub link). Arduino library information IRremote library link.
Download and run the basic test program: infraredReceiverTest.ino. When running the program, point your remote control at the receiver and press various buttons such as the number from 0 to 9. Serial messages are output (printed) which can be viewed in the Arduino IDE Tools/Serial Monitor.
+++ Setup. + Initialized the infrared receiver. ++ Go to loop. + Key OK - Toggle + Key > - next + Key < - previous + Key up + Key down + Key 1: + Key 2: + Key 3: + Key 4: + Key 6: + Key 7: + Key 8: + Key 9: + Key 0: + Key * (Return) + Key # (Exit)
As an exercise, use a TV remote to see the values printed. You can then modify the program to use the values in the infraredSwitch() function's switch statement. For example, press the "0" key and get the value for your remote, for example, "0xE0E08877". Then, add a case into the switch statement as in the following code snippet.
case 0xFF9867: case 0xE0E08877: Serial.print("+ Key 0:"); Serial.println(""); break;
Step 3: Create a Mico SD Card of MP3 Files
Since the DFPlayer is small inexpensive piece of hardware, it manages files and folders in a simplistic manner. I have had mixed results when playing MP3 files that don't follow the following recommended formats, and therefore, I recommend the following. Also, I haven't tested other options, such as 3 digit filenames (example: 003.mp3), however I have seen 3 digit filenames used in other instructions and samples.
Following are my recommended file name and folder directory name formats:
- The default folder name is MP3, placed under the SD card root directory: SD:/MP3. This folder is optional when using multiple folders.
- The player will also play MP3 files in the root directory.
- When using multiple folders, use the folder names: 01, 02, 03, ..., 99.
- The mp3 file name should be 4 digits with "0001.mp3" as the extension, for example, "0001.mp3".
- Files can be placed in the MP3 folder or in one of the multiple folders.
- File Names: 0001.mp3 to 0255.mp3. Note, the player will play MP3 file of other names as well.
- You can add characters after the digits, for example, "0001hello.mp3".
It's recommended that you format the card before adding files. This insures that the card is clean of system files. Format using FAT32 MS-DOS.
On Mac, use the disk utility to format the disk: Applications > Utilities > open Disk Utility.
Click on the SD card, example: APPLE SD Card Reader Media/MUSICSD.
Click menu item, Erase.
Set name, example: MUSICSD.
Select: MS-DOS (Fat).
The disk is cleaned and formatted.
I wrote a Java program that will copy a directory of MP3 files into a destination directory, using directory and file names that work with a DFPlayer module. To run the program, you will need the Java JRE installed. Following is the program's help output.
$ java -jar mp3player.jar +++ Start, DFPlayer module copy program. Syntax: java -jar mp3player.jar copy [ (IN: MP3 directory) (OUT: MP3 directory) ] ---------------------- This program copies a directory of MP3 files to create another directory of MP3 files using using directory and file names that work with a DFPlayer module. Before running this program, + Create a directory of your MP3 files. + Create a destination directory. + The destination directory is where the MP3 files will be copied to, ++ using digit number directory and file names. + Your destination directory should be empty. + If there are files in it, delete the files and directories. ---------------------- + Run this program. + Syntax: java -jar mp3player.jar copy [ (IN: MP3 directory) (OUT: MP3 directory) ] + Syntax using defaults: java -jar mp3player.jar copy + Default directory names: mp3player1 and mp3player2. + Same as: java -jar mp3player.jar copy mp3player1 mp3player2. ---------------------- + Insert the SD card into your computer. + Delete the directories and files from the SD card. + Empty trash because the files are still on the SD card and the DFPlayer module may play them. + Copy the new directories and files to the SD card. + Eject the card from the computer. ---------------------- + Insert the card into the DFPlayer module. + The card is ready to play</p>
On the Mac, from command line, you can run the following.
List to find the card.
$ diskutil list ... /dev/disk3 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *4.0 GB disk3 1: DOS_FAT_32 MUSICSD 4.0 GB disk3s1 $ ls /Volumes/MUSICSD
Copy files in order onto the SD card. Since the DFPlayer may sort on the timestamp, copy the files in the file name order.
Clean hidden files which can cause issues (reference: https://ss64.com/osx/dot_clean.html)
$ dot_clean /Volumes/MUSICSD
Your SD card is now ready to use. Insert it into your DFPlayer module.
Step 4: Wire in the DFPlayer Module Which Plays MP3 Files
I've separated the connections into 3 parts: serial communications, power, and speaker/sound.
1. Connect the Arduino RX/TX pins to the DFPlayer module. Connect a wire between Arduino pin 10 and DFPlayer pin 3 (TX). Connect a resister, I'm using a 5K resister from DFPlayer pin 2 (RX), to an empty row between the Arduino and the DFPlayer. Connect a wire from Nano pin 11 to the 5K resister. The 5K resister removes noise that exists when not using the resister.
2. Connect the ground pin (GND) of the DFPlayer module, to the breadboard's ground
bar strip. Connect the power pin (VCC) of the DFPlayer module, to the breadboard's positive bar strip.
3. If you have a single small speaker, connect it to pins 6 (SPK-) and 8 (SPK+) as in the above photo with Nano.
DFPlayer Mini pins ---------------- VCC | | | | BUSY, low:playing, high:not playing RX | __ | USB port - (DM, clock) TX | DFPlayer | USB port + (DP, data) DAC_R | | ADKEY_2 Play fifth segment. DAC_L | ------ | ADKEY_1 Play first segment. SPK - | | | | IO_2 short press, play next. Long press, increase volume. GND | | | | GND SPK + | Micro SD | IO_1 short press, play previous. Long press, decrease volume. ----------------
In the Arduino IDE, install the DFPlayer library. Select Tools/Manage Libraries. Filter your search by typing in ‘DFRobotDFPlayerMini’. Select DFRobotDFPlayerMini by DFRobot mini player library (for reference, the library link). For my implementation, I loaded version 1.0.5.
Load MP3 files onto the micro SD card. You can have songs in separate directories. Put the SD card into the DFPlayer.
Download and run the MP3 player program: mp3infrared.ino. When running the program, point your remote control at the receiver and press the okay button to start playing the first song. When it starts playing, the DFPlayer blue light will turn on, and stay on, while a file is playing.
I have built an Altair 8800 emulator computer that uses an Arduino Mega. When I added the DFPlayer there was a lot of noise. To get rid of the noise, I used a separate power supply for the DFPlayer. The Mega has one power supply, and sends serial control signals to the DFPlayer. The DFPlayer has another power supply, and receives and implements the serial control signals from the Mega.
In the above photo, the Altair emulator's white mini USB hub powers the Mega and is connected to the laptop black mini hub. The DFPlayer has a USB cable that connects it directly to the laptop black mini hub. This configuration removed the noise that existed when the DFPlayer was powered through the emulator white mini hub.
Click here, for the code configured for the Mega. That version of the code using Mega RX/TX pins, where as a Nano or Uno uses software serial port pins.
The following is for reference.
Connections used with an Arduino, 1. UART serial, RX for receiving control instructions the DFPlayer. RX: input connects to TX on Mega/Nano/Uno. TX for sending state information. TX: output connects to RX on Mega/Nano/Uno. Connections for Nano or Uno: RX(2) to resister to serial software pin 11(TX). TX(3) to serial software pin 10(RX). Connections for Mega: RX(2) to resister to Serial1 pin 18(TX). TX(3) to Serial1 pin 19(RX). 2. Power options. Connect from the Arduino directly to the DFPlayer: VCC to +5V. Note, also works with +3.3V in the case of an NodeMCU. GND to ground(-). Use a completely different power source: VCC to +5V of the other power source. GND to ground(-) of the other power source. I seen another power option: From the Arduino +5V, use a 7805 with capacitors and diode to the DFPlayer VCC pin. GND to ground(-). 3. Speaker output. For a single speaker, less than 3W: SPK - to the speaker pin. SPK + to the other speaker pin. For output to a stearo amp or ear phones: DAC_R to output right (+) DAC_L to output left (+) GND to output ground.
Following the key library function calls. Link to the DFPlayer wiki page.
DFRobotDFPlayerMini myDFPlayer; myDFPlayer.play(1); // Play the first mp3<br> myDFPlayer.pause(); // pause the mp3 myDFPlayer.start(); // start the mp3 from the pause ------------------------------ myDFPlayer.next(); // Play next mp3 myDFPlayer.previous(); // Play previous mp3 ------------------------------ myDFPlayer.playMp3Folder(4); // play specific mp3 in SD:/MP3/0004.mp3; File Name(0~65535) myDFPlayer.playFolder(15, 4); // play specific mp3 in SD:/15/004.mp3; Folder Name(1~99); File Name(1~255) myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(1~10); File Name(1~1000) ------------------------------ myDFPlayer.loop(1); // Loop the first mp3 myDFPlayer.enableLoop(); // enable loop. myDFPlayer.disableLoop(); // disable loop. myDFPlayer.loopFolder(5); // loop all mp3 files in folder SD:/05. myDFPlayer.enableLoopAll(); // loop all mp3 files. myDFPlayer.disableLoopAll(); // stop loop all mp3 files. ------------------------------ myDFPlayer.volume(10); // Set volume value. From 0 to 30 myDFPlayer.volumeUp(); // Volume Up myDFPlayer.volumeDown(); // Volume Down ------------------------------ myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms myDFPlayer.reset(); //Reset the module ------------------------------ Serial.println(myDFPlayer.readState()); //read mp3 state Serial.println(myDFPlayer.readVolume()); //read current volume Serial.println(myDFPlayer.readEQ()); //read EQ setting Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03 ------------------------------ myDFPlayer.available()
Step 5: External Power Supply
Now that your MP3 player is tested and working, you can unplug it from your computer and use it with an independent power supply. For simplicity, I use a 5 volt wall adapter, which can be bought for about a dollar, and a USB cable, another dollar. The cable connects the Arduino to the +5V wall adapter. Since the Arduino power and ground pins are connected to breadboard, that will power the other components. Because of it's simplicity and low cost, I use this same combination to power other projects.
The photo on the right and video show the player connected to my $40 amp sitting on the right Bose speaker on my desk. It's my desktop music system: Arduino MP3 player, Douk Audio amp, and 2 Bose speakers. Good sound quality.
I hope you are successful and enjoyed building your very own MP3 music player.
Step 6: Eliminate Static Noise
On low volume, there was an irritating background static noise. The noise was okay when the DFPlayer volume was higher and music was playing. But when the music was quiet, the static was there.
I found a StackExchage page that had lots of suggestions. The following worked for me:
- Connect a short wire between the DFPlayer ground pins: pins 7 to 10.
- Use a separate USB wall plug (5V) to power the DFPlayer module.
Connect the wall plug ground to the Arduino ground. This was required to have the serial control work between the Arduino and the player.
The above was tested on my Altair 8800 emulator which I enhanced with a DFPlayer to play music. The player is controlled by flipping the front panel toggles.