Introduction: Audio Player Using Arduino With Micro SD Card

Please SUBSCRIBE my channel for more projects.........................

Many of People want to interface the SD card with arduino or want some audio output via arduino.

So here is easiest and cheapest way to interface SD card with arduino . you can use the audio output from arduino via a switch or sensor .

you can play any type of sound ,music and recording but that audio will be in to .wav file. If it is in .mp3 or any other audio type then we will convert it into .wav file.

Step 1: Components & ​Requirements

Picture of Components  & ​Requirements
  • arduino uno
  • micro SD card Adapter module
  • micro SD
  • Card Reader
  • Speaker or earphone speaker
  • woofer or amplifier

Step 2: Convert Audio to .wav

Picture of Convert Audio to .wav

Go to the Link to convert the audio into .wav .

http://audio.online-convert.com/convert-to-wav

  1. Go to The Link
  2. Upload your audio you want to convert to WAV
  3. Change bit resolution to " 8bit ".

  4. Change sampling rate to " 16000Hz ".

  5. Change audio channels " mono " .

  6. Click on " Show advanced options ".

  7. PCM format " unsigned 8 bit ".

  8. Convert file.

At next page click on "direct download link"

Step 3: Prepare SD Card

Picture of Prepare SD Card

Download the Zip file and Extract it.

Here you will get the " SD formatter "

install the SD formatter in your PC.

Now, Connect your card with PC via USB card reader.

Open SD card formatter.

Select the drive of sd card then click on format .

In Next Step Open your SD card Drive .

Past the Audio file that we have converted in .wav file

Rename the file to "test.wav".

Step 4: Add Library in Arduino

Picture of Add Library in Arduino

Open The arduino Software

Click on then Sketch >> Include Library >> Add zip Library

Select "TMRpcm.zip" that is in zip folder.

Step 5: Upload the Codes

Picture of Upload the Codes

Download the code from link below or i have already mentioned in zip file .

Connect your arduino with pc and upload the Codes.

Step 6: ​Circuit Connections

Picture of ​Circuit Connections

Insert the card in micro sd adapter module.

Connect the circuit as given below.

CS ---------------------->> 10

SCK ---------------------->> 13

MOSI -------------------->> 11

MISO--------------------->> 12

VCC --------------------->> +5v

GND--------------------->> Arduino's Ground

Speaker Connection

one pin is in to 9 pin of Arduino and other is GND of Arduino

Step 7: Play the Audio

Picture of Play the Audio

Now , It's Ready...............................

Click Reset button to play audio every time.

The OUTPUT sound is very Low so you can use woofer or amplifier for batter Output.

Comments

AkinA5 (author)2018-01-12

I think ,The Pins of MicroSD Card was definated automaticaly for Arduino Uno .So are the pins same with Arduino Mega 2560?

vishalsoniindia (author)AkinA52018-01-12

Nope.........not same for arduino mega......
Just search spi pin for arduino mega in Google....

AkinA5 (author)2018-01-12

Hi,I have controled whole connections .Also code is compiled.But it says SD failed.

Please help me.

ankit1079 (author)2018-01-05

Hi I have done everything as mentioned in this but when i am uploading it,its showing me error .i also want to add PIR motion with this can you please help me in achiving

What type of error that you have got...

yenrajan (author)2018-01-03

Sir, Can I play the songs in the sd card one by one at a scheduled time for a fixed duration. If yes , can you please give me the codes for that?

vishalsoniindia (author)yenrajan2018-01-05

Yes, you can......
And if you want to play song over voice commands then here is video
https://youtu.be/Jcg1x1oC-5c

dzimmerm (author)2017-12-24

I have been following Tan's cooments as I am getting the same "deprecated conversion from string constant to 'char*' "error. i copied your exact code, downloaded and included the libraries, and am getting this on the compile. since the cable to the arduino isn't even plugged in, that eliminates wiring problems, sd card issues, file size or wav coversion errors. I am not seeing what a char error has to do with this code.

vishalsoniindia (author)dzimmerm2017-12-24

Remember, do not connect anything to arduino while uploading program.
Did you used my library or download new one...???

dzimmerm (author)vishalsoniindia2017-12-30

I used your library.

I wound up ignoring the warnings since it did upload. The code only worked when I moved the following lines out of the loop area and into the setup:

music.play("A.wav"); //Play song 1 from 10th second

Serial.println("now playing A.wav");

It is pretty tinny, but it is music!

dzimmerm (author)2017-12-24

looking at the exact error message, it looks like the error is coming from the TMRpcm library. Perhaps it has been changed since you got this code to work?

TanvirH13 (author)2017-12-12

deprecated conversion from string constant to 'char*' [-Wwrite-strings]

tmrpcm.play("test.wav");

Did you changed your code.......
Or did you proper converted wav file
?????

no bro i didnt change.. i just copied ur code..then when i compiled it found some errors

Past here that you copied...

#include "SD.h"


#define SD_ChipSelectPin 4

#include "TMRpcm.h"

#include "SPI.h"

TMRpcm tmrpcm;

void setup(){

tmrpcm.speakerPin = 9;

Serial.begin(9600);

if (!SD.begin(SD_ChipSelectPin)) {

Serial.println("SD fail");

return;

}

tmrpcm.setVolume(6);

}

void loop(){

tmrpcm.play("001.wav");

delay(5000) ;

}

I am using arduino mega so.. i will change the pins.. but before that the compiling is shoing error.

Change the name of file.... Rename it in SD card and same as in Code.....
Like a.wav , b.wav
Not put number in sound name

TanvirH13 (author)2017-12-12

this is the error massage i have every time

TanvirH13 (author)2017-12-12

C:\Users\Tanvir\Documents\Arduino\gg\gg.ino: In function 'void setup()':

C:\Users\Tanvir\Documents\Arduino\gg\gg.ino:20:23: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

tmrpcm.play("test.wav");

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function 'byte TMRpcm::metaInfo(boolean, char*, char*, byte)':

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1382:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

char* datStr = "LIST";

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1383:28: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if(infoType == 1){datStr = "ID3 "; datStr[3] = 3;}

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1411:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

char* tagNames[] = {"INAM","IART","IPRD"};

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1411:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1411:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1431:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1431:38: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1431:59: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function 'void TMRpcm::finalizeWavTemplate(char*)':

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1569:65: warning: narrowing conversion of '(fSize >> 16)' from 'long unsigned int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]

seek(4); byte data[4] = {lowByte(fSize),highByte(fSize), fSize >> 16,fSize >> 24};

^

C:\Users\Tanvir\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1569:77: warning: narrowing conversion of '(fSize >> 24)' from 'long unsigned int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]

seek(4); byte data[4] = {lowByte(fSize),highByte(fSize), fSize >> 16,fSize >> 24};

^

Sketch uses 12402 bytes (4%) of program storage space. Maximum is 253952 bytes.

Global variables use 1490 bytes (18%) of dynamic memory, leaving 6702 bytes for local variables. Maximum is 8192 bytes.

TanvirH13 (author)2017-12-12

why is this happening to me??

navajyothin (author)2017-12-11

how to play multiple songs please send me the code.thank u.

1st convert all your audio as I converted...
Rename it by short name of 4-5 characters
Like test.wav, a.wav,b.wav
Any thing that you want

Put it into SD card....
Do this then send me your all audio name and time of song... My suggestion is that you have to choose short ringtones....

TanvirH13 (author)2017-12-12

Bro will u plzz send me the pin numbers for arduino mega..i also have a problem .. when i compile the code it says that invalid conversion from string to *char

then tmrpcm.play("001.wav"); doesnt play

navajyothin (author)2017-12-11

HI, thanks for the code ,i can play a single track, but how to play multiple songs , can u please send me the code.

Thank u.

DennisB146 made it! (author)2017-12-02

i build a rotating platform for christmas with some music...

Good bro....

MR CLN (author)2017-11-22

Sir, I name my audio files "001" .

#define SD_ChipSelectPin 10

#include <TMRpcm.h>

#include <SPI.h>

TMRpcm tmrpcm;

void setup() {

tmrpcm.speakerPin = 9;

}

void loop() {

tmrpcm.play("001");

delay(2000);

}

But the song didn't play at all.

And can I use a 4Ω speaker to emit the sound?

vishalsoniindia (author)MR CLN2017-11-25

Are you converted in wav audio....
If, yes... Then
Replace the line
tmrpcm.play("001.wav");

MR CLN (author)vishalsoniindia2017-11-25

Yes I converted in wav audio.

I replaced it but it still can't work.

The voltage between pin9 and GND is 0.

Do you know what's wrong?

Thank you.

vishalsoniindia (author)MR CLN2017-11-25

you have not begin with serial...... Copy and paste program below




#include "SD.h"

#define SD_ChipSelectPin 4

#include "TMRpcm.h"

#include "SPI.h"

TMRpcm tmrpcm;

void setup(){

tmrpcm.speakerPin = 9;

Serial.begin(9600);

if (!SD.begin(SD_ChipSelectPin)) {

Serial.println("SD fail");

return;

}

tmrpcm.setVolume(6);

}

void loop(){

tmrpcm.play("001.wav");

delay(5000) ;

}

MR CLN (author)vishalsoniindia2017-11-26

Thank you very much!

The music can play now.

But the volume is too small.

What can I do to make it louder?

vishalsoniindia (author)MR CLN2017-11-26

Wellcome please subscribe to my YouTube channel.
Use woofers or audio amplifier to make sound louder

ChandrashekarR (author)2017-11-19

Audio speed very slower than normal, is this effect because of 8 Mhz clock ? , instead of using 16 Mhz clock ? I am using Atmega328 on breadboard internal clock 8 Mhz.

Try to convert sound with 8Mhz

ChandrashekarR (author)2017-11-19

Sir, Audio speed is slower than normal, and the voice is not playing unless I use delay 50000,

.tmrpcm.play("test.wav");

delay(50000) ;

I am using ATmega328 with 8 Mhz internal Clock, What maybe the reason for slower speed of audio .

May be.... Try with tone library

AbdullahH56 (author)2017-11-10

how can i play the whole song automatic repeatedly,

it works but the song only play about 3 sec n silence

What is time of your song.

about 4 minutes and 11 second

can you show me the code and it will repeat automatically

#include "SD.h"

#define SD_ChipSelectPin 4

#include "TMRpcm.h"

#include "SPI.h"

TMRpcm tmrpcm;

void setup(){

tmrpcm.speakerPin = 9;

Serial.begin(9600);

if (!SD.begin(SD_ChipSelectPin)) {

Serial.println("SD fail");

return;

}

tmrpcm.setVolume(6);

}

void loop(){

tmrpcm.play("test.wav");

delay(14415000) ;

}

Copy and past the following program

Remove copy and paste line

maybe the problem is we are using arduino nano instead of uno,

is there any different when im using arduino nano audio as an output,

can you show me the coding to make arduino nano audio output

your help is veru needed,

thank you

No matter which arduino you are using, all can work.......

Program for all type of arduino are same..... So just upload it in proper way.

Select possessor correct.......

10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) also change the spi pins.......

How you connect with the amplifier/woofer/audio jack

Go to step 6 and see the circuit diagram where in right side you will see a pin that looks like audio jack connect 9 pin and ground as shown

Why when im using arduino nano n uno , the song just played about 1 or 2 second
Help me please

Did you uploaded ☝️ that program that I have mentioned in upper reply

Yes already but, same result

Connection is same as 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK).... als.......

Yes make nonsense

About This Instructable

13,750views

61favorites

License:

Bio: i am 20 year old electrical engineer from india.
More by vishalsoniindia:Talkative Automation || audio from arduino || Voice Controlled Automation || HC - 05 Bluetooth Module Wireless Charger for Any Mobile || Easy || Simple || BD135Mobile Controlled Bluetooth Car || Easy || Simple || Hc-05 || Motor Shield
Add instructable to: