Select Page

Player wav files can be easily built using Arduino and may be useful for your models. So I will share instructions how to build it.

What you’ll need :

  • Arduino
  • MicroSD reader ($4 at DX.com )
  • MicroSD card
  • Speaker

Wav files must be in the format of 22 kHz, 8 bit Mono (I tried other combinations, but the resulting quality of play deteriorates rapidly). Save the file to the MicroSD card. Also recommend is called as simple and short names. Some files will not play if you will have longer name of the file.

How to connect the MicroSD reader:

  • 3.3v goes to 3.3v in Arduino
  • GND goes to GND on Arduino
  • D0 goes to pin D12 on Arduino
  • CMD goes to pin D11 on Arduino
  • CLK goes to pin D13 on Arduino
  • D3 goes to pin D10 on Arduino

Now we have prepared a reader and we can read from it. You will still need this library (download it here: http://arduino.cc/en/Main/Software). Library to download: https://github.com/TMRh20/TMRpcm

Now connect the speaker. The default pin on the Arduino pin D9. There are two basic ways to connect the speaker:

  1. tranzistor
    Through transistor (eg 2N2222) – it will boost the sound, but do not expect anything extraordinary. Connect the transistor according to the drawing, when you connect it via a resistor to pin D9 (the transistor terminal B), on the other end (pin C) bring the power from the Arduino using 5V pin and the last end (pin E) is used for output to the speaker.
  2. Through amplifier – that you can buy directly done or as a kit, zesilovačor as me you can build it by yourself directly from components using LM386 chip. There are many guides on Google, certainly a lot of details instructions with diagrams and printed circuit boards. I used the simplest instructions with minimum components, see. picture on the right. Power is however preferable approximately 5V, you will avoid the unwanted noise. So I used the Arduino pin D4 to power this amplifier.

You can use any speaker. I used the speaker from an old cell phone mainly because of the size (I needed the smallest possible) .

If you have everything plugged in and ready to run, here is the software for the Arduino:

#include <SD.h> //you will need this library
#include <TMRpcm.h> // and this one too…
#define SD_ChipSelectPin 10

TMRpcm tmrpcm; // Create an object
char mychar;
int powerPin = 4;

void setup(){

tmrpcm.speakerPin = 9; //11 na Mega, 9 na Uno, Nano…

Serial.begin(9600);
pinMode(powerPin, OUTPUT);
digitalWrite(powerPin, LOW);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

if (!SD.begin(SD_ChipSelectPin)) {
Serial.println(“SD fail”);
return;
}
digitalWrite(powerPin, HIGH);
tmrpcm.play(“sfx03.wav”); //File”sfx03.wav” will play on each Arduino start or reset
}

void loop(){

if(Serial.available()){
mychar = Serial.read();

if(mychar == ‘q’){ //File will play only after pressing “q” key in “Serial Monitor”
tmrpcm.play(“ag_fire.wav”);
}

}

}

Here is the final result: