Playing Wave File Using Arduino

311,096

428

217

About: Electrical Engineer

This is a simple circuit to play wav files using arduino Nano V3.0 ,it consist from 4 buttons ,each one play specific wav file loaded to SD card.

Step 1: Parts

1- Arduino Nano V3.0 (I used the chines version called Funduino Nano).
2- SD card Module.
3- SD card.
4- Bread Board.
5- four push Button .
6- four 22K resistors.
7- one 4.7K resistor.
8- BC546B NPN transistor.
9- Speaker.
10- wires.

Step 2: Prepare Your SD Card

1- Format SD card and make sure the setting as attached picture.
2- Convert your music to .WAV files and make sure the below:
-Samples Per second(Hz):16000
-Channel :Mono
- Bits Per Sample: 8
I use Wav Sample rate converter software (picture attached).
3- Wave files samples attached.

Step 3: Circuit Digram

Step 4: Source Code

1-Before writing the code you need to install TMRpcm library from below link:
https://github.com/TMRh20/TMRpcm/wiki
all information how to install and use the library included in the website .

2- Download the attached WavSW_ino.zip file and open it with arduino sketch ,I tried to copy and paste the Source Code from arduino sketch to instructable but for some reason the text convert to rubbish.



Step 5: Troubleshooting Update 29/5/2016

For people whom unable to make this circuit work ,I created the attached folder "for test" for troubleshooting purpose .

The folder includes tested code for Arduino Nano ,UNO and MEGA.

No need to connect the push buttons,the sounds will play automatically.

No need to connect the transistor ,Connect a small speaker or headphone directly to pin 9 for arduino nano or pin 11 for Mega .

Copy the .wav files directly to SD card ,Do not put them inside folder.

Pin Connection:

Arduino Nano ---------> SD Card

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

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

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

4 ---------------------->CS

9 ---------------------->Speaker

GND ------------------>GND

5V ------------------> VCC

Arduino MEGA ---------> SD Card
50-------------------> MISO

51-------------------->MOSI

52 -------------------->SCK

53---------------------->CS

11---------------------->Speaker

GND ------------------>GND

5V ------------------> VCC

if the tested code worked fine do the following for the push buttons code file to make it work:

1-If you faced problem in compiling the original push buttons code file ,please add line #include<SPI.h>

in the 3rd line of the code.

still have no sound add a delay command between the play commands delay(1000);

Good luck

Husham

123D Circuits Contest

Participated in the
123D Circuits Contest

16 People Made This Project!

Recommendations

  • Beauty Tips Contest

    Beauty Tips Contest
  • Classroom Science Contest

    Classroom Science Contest
  • Planter Challenge

    Planter Challenge

217 Discussions

0
None
mhsyaefudin8

27 days ago

may i ask u some problem of my program, it says "error opening text.txt", can anyone else know what happened?

Untitled.png
0
None
AminA81

Question 3 months ago

If I add another 30 buttons do I need to do something about the transistor too or should I just connect it to the same transistor?

0
None
haojuuestc

3 months ago on Step 5

Hi there,

I'm not quite sure what happened: I ran the troubleshooting codes (and added a short piece of music in wav format myself) on my arduino pro mini, but it just doesn't work... All pins were connected in the same way as your demo (except that I changed CS to pin 10 both in the codes and in the actual circuit. I uncommented #define DISABLE_SPEAKER2 in the pcmconfig.h file, too.). I connected the speaker directly to pin 9 without amplifying the signal input.

I am sure that the SD card and the speaker both work --- I can read and write txt files on the SD card, and the speaker works fine with the tone function.

The waveform on the oscilloscope tuned out as such: (see fig 1)

which should have been like this (original file opened in matlab): (see fig 2)

Wonder if you have any suggestions?

Thanks a million!

IMG_7438.JPGIMG_7439.JPG
0
None
markl329

Question 10 months ago

Does the speaker need a amplifier?

0
None
Suyogpatange7

1 year ago

Why you use analog pin as digital pin instead of original digital pins?

0
None
geo-sun

1 year ago

I need help, mine works with sample files but If I try to play music it just makes buzzing sound.

0
None
ParkerO

1 year ago

I need help. Im using the UNO and i uploaded it and no audio. No static. Nothing. Im using a 5W 8Ohm speaker.

0
None
revlied

1 year ago

I'm done i press the buttons, nothing happens. No errors in the script.

0
None
ĐorđeM2

2 years ago

I have connected all as you, but my speaker is too quiet. But if I change volume, then quality goes horrible, I can't hear anything. Help?

0
None
HaqiK

2 years ago

Hey guys I love your tutorial and thanks for great help :) anyway I tried with my own sound and have some problem with the sound, the sound doesn't clear to hear and I tried to volume up the sound with potentio too but no luck, anyone knows to volume up with this library?

Thanks for your help :) :) :)

0
None
Autoraf

2 years ago

Hello everybody! I made this project but there is a noise like motorcycle wirh the sound from sd card. Can you help me? Tks!

0
None
tuang.pingfavilunda

2 years ago

the "For Test.zip" has no UNO file. Can you provide that ? I have been struggle with this project for weeks now. I need some sample with .wav file and yours seems nice. Ps. I tried change pin 4 to 10 already since I have read somewhere that UNO needs pin 10

0
None
YusdiI

2 years ago

Thank, n nice project

0
None
tsnijder

2 years ago

Hello,

Is it possible to play each sound on a different speaker?

0
None
domdomgin

2 years ago

spi was not declared in this scope..please help..

1 reply
0
None
hungrycatzdomdomgin

Reply 2 years ago

try including the spi library - #include <SPI.h>

0
None
Nolan Cash

2 years ago

hey, just a heads up, when pinning the transistor be sure to look up the pinout and double check before soldering. or you can do what i did and just look at the shape and trust the rest. then spend 3 days trouble shooting. the transistor in the diagram is inverted.

aside from that learning experiance, this is an awesome project and im not sure how but i would like to post a video when i get the entire project done.

1 reply
0
None
badedinNolan Cash

Reply 2 years ago

husham seems like not here that often ..

can you possibly help me nolan?