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

 

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

 

 

audio functions

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

 

TMRpcm audio;
audio.play(“filename”);    plays a file
audio.play(“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.

Installation

  1. Download current package: https://github.com/TMRh20/TMRpcm/archive/master.zip
  2. See the Manual Installation section at: http://arduino.cc/en/Guide/Libraries

++++++++++++++++++==

WAV files
the arduino can only play .wav files

we can download free ones here
http://www.thefreesite.com/free_sounds/free_wavs/

or make our own
using ‘sound recorder’

+++++++++

connecting the df robot sd reader to the arduino 

http://www.dfrobot.com/wiki/index.php?title=SD_Module_(SKU:_DFR0071)

500px-DFR0071_Connection_Diagram

++++++++++++++++

You can download the code here

gunbalanya

#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 {

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

tmrpcm.play(“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) {

tmrpcm.play(“moo.wav”);
delay (2500);
}

else {
digitalRead(2) == LOW;
tmrpcm.disable();
}

if (digitalRead(3) == HIGH) {

tmrpcm.play(“6.wav”);
delay (2500);
}

else {
digitalRead(3) == LOW;
tmrpcm.disable();
}

}

Putting in Switches

To turn on the individual sounds we need to add switches
Positive_Negative_Logic_connection_of_Switch_with_Microcontroller_pin