Instructables
Picture of Playing Wave file using arduino
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.
 
Remove these adsRemove these ads by Signing Up

Step 1: Parts

Picture of Parts
Funduino Nano V3.JPG
Funduino Nano V3 1.JPG
SD.JPG
SD1.JPG
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

Picture of Prepare your SD card
Format.png
Wav Sample Converter.png
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

Picture of Circuit Digram

Step 4: Source Code

Picture of 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.



WavSW_ino.zip887 bytes
1-40 of 82Next »
A.Ward889 hours ago
Could one use piezoelectric sensors to play the sound file?
ko.ten.71 month ago

i want to use with atmega8.

please help me!!!!!!!!!

err.png

perhaps it is cause atmega328 has 4x flash memory of the atmega8, see how big the hex executable is. you may need a chip with more memory

KUPOV25 days ago

Hi, very nice and useful instructable, but my do not work at all. I use 0,2 W 8 ohm speaker. My code work properly. I thought that it is something with sd card, but when I wrote code for saving data it worked. Do you have any idea what may be cause of problem?

DSC_0036.JPG
LiamB2 KUPOV10 days ago

For me, I ended up getting rid of the buttons to make it simpler, and editing the code given to get rid of the buttons.

Mine also didn't work, until I realized that I was playing the sound every single time in the loop, which will just repeat the first couple miliseconds forever. Make sure you are playing the file only once, not every loop.

kpdavis11 days ago

We got this going without much trouble at all. Now we are trying to run the audio to a set of PC desktop speakers via a 3.5mm audio plug. We get a lot of hum. I see that one suggestion is adding a capacitor, so we will try that. But also saw the suggestion of just taking the transistor out. We can give that a try also. Just not sure what should be coming out of one of those 3.5mm audio plugs. It must be somewhat standard. If there are other suggestions, let me know.

safayeta12 days ago

I am using BC547 transistor and 8 ohm 0.5 watt speaker
The sound is vary low
in your video the sound is quite high
how can i increase the sound.. Thanks

safayeta1 month ago

I have tried this project. But after compiling the code there is an error

"In file included from WavSW_ino.ino:3:0:

C:\Users\Uaer\Documents\Arduino\libraries\TMRpcm/TMRpcm.h:17:19: fatal error: SdFat.h: No such file or directory

#include <SdFat.h>"

Please Help I need to fix this.
Thank You
my email address is safayetahmed.s@gmail.com
please if you can send me your TMRpcm library file it will be helpful.

NoahC2 safayeta20 days ago

just comment out "#include <SdFat.h>" in the begining of TMRpcm.h and TMRpcm.cpp :)

safayeta NoahC212 days ago

Problem Solved.. I used arduino 1.0.3...

Husham Samir (author)  safayeta27 days ago

the library I used SD.h Not SdFat.h and already included in arduino sketch so no need to donload the library.

hi Husham Samir may you explain again what to do to make this solved?

thank's :]

emgeiger1 month ago

I can't run the audio clip editor you suggested because I'm running mac OSX, could you convert a file for me? (link to download file) : https://www.freesound.org/people/CommanderDerp/sounds/167921/

Use Audacity, it does what you want and is compiled for Mac OS X as well. However, you may possibly prefer going to Windows, the Mac doesn't have what you need.

I am facing the same problem. I have downloaded the SdFat.h and included in the TMRpcm library. but it still show errors.

Husham Samir (author)  nasrul.fahmi.3127 days ago

the library I used SD.h Not SdFat.h and already included in arduino sketch so no need to donload the library.

i didnt understand your explanation the error is still there may you explain again what can i do ?

thanks alot :]

monolitico17 days ago

Hello Husham. Thank you for this tutorial.

I also found that the files are missing, and also find that it depends on which language is instructables.com. If you watch this tutorial on english version, the files are there, but for example, in the spanish version I can't find them.

Check the difference:

http://www.instructables.com/id/Playing-Wave-file-...

http://www.instructables.com/id/Playing-Wave-file-...

i have this error can you help me

basic.ino:4:71: fatal error: TMRpcm.h: No such file or directory
compilation terminated.

thanks

Husham Samir (author)  mohammad.habib.12912 months ago

Hi

this error telling you that you didn't install theTMRpcm library in the right location.

Hello

I have the same problem.

basic.ino:4:71: fatal error: TMRpcm.h: No such file or directory
compilation terminated.

I checked and it seems to me that the library is in the right location. How do we fix the problem? What should be the right location? I installed it via ''Import Library'', so should I do it manually somewhere else in sketchbook/libraries?

Thank you.

Husham Samir (author)  SilaSaJulinaHilla1 month ago

Hi,

please check location from the attached picture.

Thanks.

TMRpcm.png
Justin Mai1 month ago

Can you play multiple files at one time? For example, if I press two or more buttons close to each other, or even at the same time, can this controller play both sounds mixed together, or only one at a time?

ofir.dotan1 month ago

Hi, I need some help with a small project of mine. It has to do with sound recognition (not voice, but simple frequencies picked up by a speaker. I am looking to pay (through fiverr.com, paypal, or with bitcoin). Anybody here who would like to help? Please post a comment. Thanks

Really a nice project!

But I have the same problem others had as well: the zip-file is nowhere in sight.

Husham Samir (author)  twilightzone422 months ago

Hi

yes ,for some people they can not find the ZIP file on there browser ,I don't know ,it looks like there is a bug in the website ,so you can send me your email in order to send you the file.

Lndjet2 months ago

sir im using other clone boards and nano v3.0 with 8 ohms 0.5w speaker

i trace the schematics of those two and locate the PWMs and SPI
and try the sd samples to verify my connection and result is okay the program can locate the files in sd

but when i try the codes of yours

in nano the micro controller is not responding and no output on speaker

in the clone result is no output on speaker

thanks sir this work of is a big part of in our project

Husham Samir (author)  Lndjet2 months ago

Hi,

When you verify the code in the sketch ,did you get any error ??

hi sir,
there no error sir. and i try your program with the sd cardinfo example. in same sketch..

when i run the serial monitor the data in sd is found but there's no audio output.

Husham Samir (author)  Lndjet2 months ago

Hi,

try to connect headphone directly to PWM pin and check .

make sure the names of wav files in the SD card is the same in the code and don't put it inside folder

also make sure that the baud rate is 9600 ,if you check the comments below you will find that some people get issue when they change the baud rate.

I hope these things will help you.

nodoubtman2 months ago

Thank you so much! :)

antdickinson2 months ago

Thanks for the great Instructable. I managed to get it working earlier today and am running the output in to a portable speaker... It sounds great when the audio is coming out but when it is waiting to be triggered (as a few other people have mentioned) it is really noisy. I have tried a capacitor (like you suggested) between pin 9 and the input for the speaker but it doesn't seem to do anything. :-/ Do you or does anyone else on here have any suggestions?

Husham Samir (author)  antdickinson2 months ago

Sorry for that but I have no idea how to solve this issue .

Ok, no problem. I am going to keep on experimenting with caps and possibly slightly different wiring to the switches. Thanks again for a good instructable. :)

Good day sir.. Does it work with other boards of arduino? 'coz we dont have arduino nano v3.0 :)

Husham Samir (author)  cris.olayvar302 months ago

yes ,it work with other arduino board but the pins connection will not be the same.

DoctorWoo3 months ago
Sorry if this was already addressed, but could you just replace the speaker in here with a headphone jack and use a set of headphones or a speaker with the correct jack size?
peterj23 months ago

Been trying for hours now to get the stereo output to work on an Arduino Mega, is there a diagram somewhere where all the pins and connections are described for the Mega

rogeliotorlao3 months ago

hi nice work sir ,,,, how cn you make this polyphonic :DD im currently working on my electronic drum but i couldnt play two to three drums at a time ,, is there a way that i could make it polyphonic .

i really need your help :D please pm me on facebook www.facebook.com/polylights

thank you

n1cod3mus4 months ago

Hi, thanks for the instructable really good works great however, I have an issue with volume, its not very loud, I am using an amplifier module and a 4W speaker, its a tiny speaker 30mm x 40mm. it has to be small to fit in the device I want to put it in.

any ideas how I can get a reasonable amount of volume out of a small speak or one that would fit in a 35mm high space?

1-40 of 82Next »