In this instructable I'm going to show you how to make a simple music player using an Arduino and a SD card reader. It is quite simple to use and is fun to make. Note: This is just for fun and not for serious use. I tried this mainly to learn how to use SD card on Arduino.
Step 1: Components Required
- 1* Arduino (I used Uno)
- 1* SD card
- 1* SD card reader for Arduino (I use LC Studio)
- 8* Jumper cables Male - Female
- A couple of Male - Male jumper cables
- 3* Push Buttons (tactile switches) (as the controls for the music player)
- 3* 10 k ohm resistors
- 1* Breadboard
- 1* Speaker (low wattage speaker that doesn't need separate power - see the attached picture)
Step 2: Making the Player
Create the circuit as shown in the fritzing image above. Make sure you wire the SD card reader correctly as you don't want to risk damaging your SD card. Here are all the SD card connections. (You don't need to worry about these if you are using a SD shield, but if you are using a module you need to wire it up.)
| SD module | Arduino (UNO) | +-----------+---------------------------------+ | Gnd | Gnd | | 3.3v | 3.3v | | 5v | 5v | | CS | pin 4 (Pin 53 on Arduino Mega) | | MOSI | pin 11 (Pin 51 on Arduino Mega) | | SCK | pin 13 (Pin 52 on Arduino Mega) | | MISO | pin 12 (Pin 50 on Arduino Mega) | | Gnd | Gnd | +-----------+---------------------------------+
Additionally, the speaker connection should be as follows:
- Speaker - Pin 9 (Pin 11 on Arduino Mega) (This is required for TMRpcm library that is used with this code)
The switches should be connected to pin 5, 6, 7 (Respectively - Rewind to first file, Play, Next File).
The code which I have written requires TMRpcm library (you need to download it from https://github.com/TMRh20/TMRpcm/archive/master.zip)
Go to the Arduino IDE. Include the downloaded library by going to Sketch > Include Library > Add Zip file.
Now upload the code given below onto your Arduino board.
Note : If you are using Arduino Mega, you need to make 2 changes in the code.
1. Use pin 11 as speaker pin instead of pin 9. 2. Use pin 53 as CS pin instead of pin 4.
Step 3: Prepare the SD Card
Now you need to format the SD card. Format it according to the instructions given in the link below:
Once you have formatted the SD card, you need to put in a few music files. The libraries I have used only support .WAV files.
If you don't have WAV files, you can use the link below to convert your mp3 to WAV. The library supports files with 8-32 khz Sample Rate (I used 16 kHz), 8 bit per sample, mono channel.
Since I had used FAT system, I had to rename the WAV file to 8.3 format (you may need to do the same). Then copy the files into the SD card.
Step 4: Use It!!
Plug in your SD card into the reader and connect your Arduino to your PC/Comp. Click on Serial Monitor and after a few seconds the first music file's name on your SD card will appear. To move to the next file press the push button connected to pin 7. To go to the first file press the button connected pin 5. To play a file press the button connected to pin 6. And that's it, enjoy!!!
Please note that I used only 3 controls (Go to first file, Next file, Play), but you can obviously use more controls as you wish. Of course, you would need to modify the program accordingly.
PS- Thanks a lot for looking at my write up. If you have any suggestions please do tell me.
If you liked this instructable, have a look at my other instructables.