Introduction: Music Player Using Arduino
Arduino Music Player is a simple and fun Arduino project which can be build in 10–15 minutes. Once we have the hardware. The project is very simple. An Arduino audio player that plays “.wav” files. It consists of a speaker, a amplifier, and a micro-SD card adapter for a micro-SD card that holds the .wav files.
This project is Sponsored by JLCPCB
They provide high quality PCB at very low prices. You can order 2 to 6 layer pcbs from them. Starting at only $2 for 2 layer PCB. You can also add SMD stencil along side with your order only for additional $7
Check them out! - https://jlcpcb.com
Supplies
Parts List:
Arduino Library:
Additionally we need and Arduino library, In Arduino IDE, go to Tools Manage Libraries, and search for “TMRpcm” and click on install.
Step 1: Watch the Video
If you dont wish to read all the steps you can watch my video tutorial!
Step 2: Schematic & Code
#include <SD.h> // need to include the SD library #define SD_ChipSelectPin 4 //connect pin 4 of arduino to cs pin of sd card #include <TMRpcm.h> //Arduino library for asynchronous playback of PCM/WAV files #include <SPI.h> // need to include the SPI library TMRpcm tmrpcm; // create an object for use in this sketch int temp=1; int pp=5; int next=6; int prev=7; void setup() { pinMode(pp,INPUT_PULLUP); pinMode(next,INPUT_PULLUP); pinMode(prev,INPUT_PULLUP); tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc Serial.begin(9600); if (!SD.begin(SD_ChipSelectPin)) // returns 1 if the card is present { Serial.println("SD fail"); return; } tmrpcm.setVolume(5); // tmrpcm.play("song1.wav"); //the sound file "song" will play each time the arduino powers up, or is reset //try to provide the file name with extension } void loop() { while(digitalRead(pp)==0 || digitalRead(next)==0 || digitalRead(prev)==0) { if(digitalRead(pp)==0) { tmrpcm.pause(); while(digitalRead(pp)==0); delay(200); } else if(digitalRead(next)==0) { if(temp<4)//temp should be lesser than no. of songs temp=temp+1; while(digitalRead(next)==0); delay(200); song(); } else if(digitalRead(prev)==0) { if(temp>1) temp=temp-1; while(digitalRead(prev)==0); delay(200); song(); } } } void song (void) { if(temp==1) { tmrpcm.play("Song1.wav"); } else if(temp==2) { tmrpcm.play("Song2.wav"); } else if(temp==3) { tmrpcm.play("Song3.wav"); } else if(temp==4) { tmrpcm.play("Song4.wav"); } }
Step 3: Soldering & Coding!
Firstly, solder all parts as shown about in the circuit diagram. The SD card Module in the circuit shown above loads the .wav files. From the micro-SD card. Which is interfaced with arduino using SPI protocol.
Secondly the arduino processes the information on SD card and generates the signal and outputs it through the speaker connected to digital pin 9 on ARDUINO NANO & UNO. Also Digital pin 5,6,11 or 46 on Arduino Mega, This allows the speaker to create sounds and play Audio.
Once soldering is done upload the code provided in above step.
Step 4: Converting Music Files
Now we need to convert music into desirable format. Accordingly the WAV files used in this circuit have a slight limitation in playing audio. Since a Arduino is used, it cannot read complex .wav files. Therefore, the .wav files should be converted to have these dimensions:
- Samples Per second (Hz): 16000
- Channel: Mono
- Bits Per Sample: 8PCM
- format: PCM unsigned 8-bit
Therefore to convert the Music into desirable formant we will use this website – https://audio.online-convert.com/convert-to-wav
Once, the conversion is done rename the songs as song1, song2, song3 etc. Also don’t forget to, format the microSD Card as FAT using any formatting software like SD Memory Card Formatter and copy all the WAV audio files to the card.
Step 5: That's All!
By default, the first song (i.e. song1.wav) will play automatically once the Arduino is reset. We can use the Play / Pause Button to well, play or pause the current track. Use Next Button to play the next track and Prev Button to play the previous track. with that being done you have your own Arduino Based Music Player.
with that being done you have your own Arduino Based Music Player.