Introduction: 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.

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

Comments

author
%C4%90or%C4%91eM2 made it!(author)2017-06-10

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?

author
HaqiK made it!(author)2017-04-28

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 :) :) :)

author
%C3%BCmit+emreo made it!(author)2017-04-27

Thanks for help.

author
Autoraf made it!(author)2017-03-27

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

author
tuang.pingfavilunda made it!(author)2017-03-15

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

author
YusdiI made it!(author)2017-01-28

Thank, n nice project

author
sgarbo made it!(author)2017-01-10

This is a great project. I would enjoy adding an LED To blink to the sound as it plays but I am having no luck . I would love suggestions I have tried many things with no luck

IMG_1698.JPG
author
ahmadA273 made it!(author)2016-11-27

thanks,,,

author
tsnijder made it!(author)2016-11-21

Hello,

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

author
domdomgin made it!(author)2016-10-19

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

author
hungrycatz made it!(author)2016-11-12

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

author
Nolan+Cash made it!(author)2016-09-17

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.

author
badedin made it!(author)2016-09-29

husham seems like not here that often ..

can you possibly help me nolan?

author
Nolan+Cash made it!(author)2016-10-13

sorry for the late reply, and ill try and help as best i can. is your question about the one button making random wav files play?

author
SyedS80 made it!(author)2016-08-28

nice work !! sir can u please tell if i connect an audio amplifier instead of directly connecting the speaker to get more sound ??

author
AndreM45 made it!(author)2016-07-14

Hello, thank you for your guide, it make my project finished. But i have one question, can we pause the wav when that wav was playing?
Thank you

1468493536793281415323.jpg
author
yehan made it!(author)2016-08-16

audio.pause(); pauses and unpauses the playback

author
EpeTuk made it!(author)2016-08-07

Hello, thank you for the article, it is very helpful. I do tank on the bluetooth control, and I need the engine sounds. Please tell me: where you took them.

author
Cl%C3%A9mentT2 made it!(author)2016-08-04

Hep! Thanks for this tuto its working, Ive a question, i would like to know if it possible that the sample play when you press the button, because at the moment le sample play when you release the button (LOW position) and there is a noise when you press (If you keep the HIGH position), do you have an idea ?

Second point, Ive a keypad (3x4 with 7 pins) do I need to use de keypad librairy to use de 12 buttons or is it possible just with the TRMpcm library ?

author
Cl%C3%A9mentT2 made it!(author)2016-08-04

Point 3: Is it possible to play the sample together ?

author
revlied made it!(author)2016-07-20

What type of 22k resistor do you need? how many wats? 1/4? 1/2?

author
Ishutaru made it!(author)2016-07-04

Hello there. Thank you for your guide, I made it using Uno R3 and SD module and it worked. Now I face a little problem with Mega 2560 + LCD screen with SD card reader. I am using library UTFT SdFat and UTFT_SdRaw to display images from SD card on LCD screen. TMRpcm library needs SD library to work but when I include it I get lots of errors that point to SD and SdFat. When I upload your code Mega 2560 plays from SD card without any problems. Is there any way to make TMRpcm work on SdFat only?

author
Husham+Samir made it!(author)2016-07-07

Hi,

I didn't try this before so I have no idea.

Sorry.

author
Ishutaru made it!(author)2016-07-09

I am now making a workaround. I connected Nano+SD module to Mega 5V so that Mega is now powering on my Nano.. Well it's a strange idea, but all I need is background music with no control over it. Nano plays music by itself using SD library and Mega works with LCD using UTFT_SdRaw. Too bad I have to connect 2 SD cards now :D. My power bank is 5V/1A.

author
yanesi made it!(author)2016-07-08

Hello Husham where download library UTFT_sdRaw, where the codec download and .raw file in Windows 10.

author
AashayC1 made it!(author)2016-07-01

can i use arduino uno 3 as i have to make a voice comand blind helmet

author
Husham+Samir made it!(author)2016-07-07

yes you can.

please put in your mind that the quality of voice is bad ,so if you want a good quality ,try to connect arduino to MP3 serial module.

author
licheong made it!(author)2016-06-25

Hi, I've tried to make one. The SD card reads and writes without problem, but the sound from the speaker is very noisy and distorted. I'm using a BC547 transistor and a 0.2W/16ohm speaker. I'm not sure if the resistance of the speaker is too high? Thanks very much!

IMG_1081.JPG
author
licheong made it!(author)2016-06-25

I tried once again, this time simply connect a 220ohm resistor in series with the speaker and it works. I've tried with your 'nano' sketch. The first few files sound okay, but the last file 88.wav still sounds very distorted. What do you think could be the problem? Thanks!

author
Husham+Samir made it!(author)2016-06-26

Well, Music quality looks better than voice ,you can download "Wav Sample rate converter" software and try to change the samples per sec to 8000 and check.

author
licheong made it!(author)2016-06-27

Thanks! I've been using Reaper, and the sound quality worsened after down sampling. Let me try the software you suggest.

author
badedin made it!(author)2016-06-26

i wonder how to make one button which plays a random wav each time.

author
Husham+Samir made it!(author)2016-06-26

to get random number you need to use arduino random(min,max) command with switch/case statements .

author
JonathanG118 made it!(author)2016-06-26

Hi, i have an atmega8 with the arduino bootloader, this will work on it?thanks

author
Husham+Samir made it!(author)2016-06-26

I'm not sure if the library support atmega8.

check below link for library feature :

https://github.com/TMRh20/TMRpcm/wiki

Supported devices: Arduino Uno, Nano, Mega, etc.

author
%D0%91.%D0%919 made it!(author)2016-05-27

its working

13285770_1039922319433813_846828460_n.jpg
author
Husham+Samir made it!(author)2016-05-28

Great Work,Congrats.

author
%D0%91.%D0%919 made it!(author)2016-05-28

tnx

author
mursidsuyana made it!(author)2016-05-20

Hai Husham, How do you do?

recently i tried this for my final project. but this was not working at all. i used wav files u provide. was theere something wrong on my wiring? thanks

sdcardwav.jpg
author
Husham+Samir made it!(author)2016-05-23

try to remove the transistor and connect a head phone ,if you hear something that's mean that you connect the transistor wrongly ,if not check the connection again ,and have a look on below comments ,you may find the solution.

author
ksai3072001 made it!(author)2016-05-21

sir,is the circuit in the above was connected to pc????

author
Husham+Samir made it!(author)2016-05-23

You will need the PC to upload the code only ,after that you can power it up with out source 5 volt .

author
giannisjome made it!(author)2016-05-21

Very good, but how can I improve the quality of sound?

author
Husham+Samir made it!(author)2016-05-23

Well ,I suggest to buy MP3 module with serial support and connect it to arduino ,in this way you can send command from arduino to play MP3 file with good quality.

author
ksai3072001 made it!(author)2016-05-23

sir is this the above one BC546B NPN transistor.???????

author
Husham+Samir made it!(author)2016-05-23

BC546B NPN transistor.

author
ksai3072001 made it!(author)2016-05-23

sir,

4.7 k ohm resistor of 1/4 watt or something other??

author
Husham+Samir made it!(author)2016-05-23

yes 4.7

author
ksai3072001 made it!(author)2016-05-21

sir,is the circuit in the above was connected to pc????

author
wiki1995 made it!(author)2016-05-16

hi Husham, i hope you are doing good.

i m making a project in which i m using ultrasonic sensors to detect obstacle and then arduino play an audio(that we recorded and converted into .wav of 128kbps bitrate: which is compulsory)

THE ISSUE IS, the output(our recorded sound) comes out with lots of noise, we put another random audio it went out fine.

About This Instructable

256,646views

405favorites

License:

Bio: Electrical Engineer
More by Husham Samir:Using MikroTik Router Board 433 & Arduino To Control Two LEDsArduino Keypad Door LockTemperature Data Logger
Add instructable to: