arduino sound

OK, we’re heading into sound land

we have some exciting new projects

1. home intruder alarm

2. an interactive media project for the indigenous community of gunbalanya


First let’s get some sound going



audio functions


TMRpcm audio;“filename”);    plays a file“filename”,30); plays a file starting at 30 seconds into the track
audio.speakerPin = 11;     set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc.
audio.disable();           disables the timer on output pin and stops the music
audio.stopPlayback();      stops the music, but leaves the timer running
audio.isPlaying();         returns 1 if music playing, 0 if not
audio.pause();             pauses/unpauses playback
audio.quality(1);          Set 1 for 2x oversampling
audio.volume(0);           1(up) or 0(down) to control volume
audio.setVolume(0);        0 to 7. Set volume level
audio.loop(1);             0 or 1. Can be changed during playback for full control of looping.


  1. Download current package:
  2. See the Manual Installation section at:


WAV files
the arduino can only play .wav files

we can download free ones here

or make our own
using ‘sound recorder’


connecting the df robot sd reader to the arduino



You can download the code here


#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h>
#define SD_ChipSelectPin 10 //using digital pin 4 on arduino nano 328

TMRpcm tmrpcm; // create an object for use in this sketch

int i = 0;
void setup(){

tmrpcm.speakerPin = 9; //Pin 9 on Uno

pinMode(2, INPUT); // initialize the sensor pin as an input:
pinMode(2, INPUT);
pinMode(3, INPUT);

digitalRead(2) == LOW;
digitalRead(3) == LOW;
if (!SD.begin(SD_ChipSelectPin)) { // Initialize SD Card.

else {

}“1.wav”); //this sound file tone will play each time the arduino powers up, or is reset to check function
delay (1000);“2.wav”); //this sound file tone will play each time the arduino powers up, or is reset to check function
delay (1000);

void loop(){

if (digitalRead(2) == HIGH) {“moo.wav”);
delay (2500);

else {
digitalRead(2) == LOW;

if (digitalRead(3) == HIGH) {“6.wav”);
delay (2500);

else {
digitalRead(3) == LOW;


Putting in Switches

To turn on the individual sounds we need to add switches