What is the best / simplest way to play audio files from an SD card?
I'm currently working on a sound board, where each button plays a different sound. But I have yet to find the right combination of shields / hardware to do this efficiently.
Is there a shield that supports this directly (SD card -> speaker)? Note that I also need additional pinheads for my buttons to connect to. I think I will be using the Arduino Mega for that purpose.
-
If all you need is button → sound then you don't need an Arduino at all. There are modules that do exactly that natively.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams05/24/2015 17:06:41Commented May 24, 2015 at 17:06
-
Are there? I haven't found any yet. Can you point me to one?bytecode77– bytecode7705/24/2015 17:07:40Commented May 24, 2015 at 17:07
-
sparkfun.com/search/products?term=triggerIgnacio Vazquez-Abrams– Ignacio Vazquez-Abrams05/24/2015 17:08:37Commented May 24, 2015 at 17:08
-
I don't think this will work, because I have 48 sounds and I don't have one button for each sound, but rather one row and one column of buttons that need to be pressed one & then the other...bytecode77– bytecode7705/24/2015 18:37:23Commented May 24, 2015 at 18:37
2 Answers 2
There are several audio products/shields. Because you mention "speakers", the first one listed can come with an on-board amplifier to drive speakers directly. Most shields just give line-out to drive a pre-amp.
- Adafruit Music maker shield plays MP3/WAV/OGG from microSD http://www.adafruit.com/products/1788
- Adafruit Wave shield plays WAV files on SD card http://www.adafruit.com/products/94
- SparkFun MP3 trigger board supports 256 tracks and a serial protocol for running individual tracks. https://www.sparkfun.com/products/11029
- SparkFun MP3 shield board plays MP3/WAV/OGG https://www.sparkfun.com/products/10628
-
Can any of these be triggered with 48 different sounds on button click?bytecode77– bytecode7705/27/2015 06:42:03Commented May 27, 2015 at 6:42
-
The shields and devices mentioned are for audio playback. They don't in general handle buttons or inputs (although the SparkFun trigger above handles a smaller number). Instead, you'd want to handle the inputs with some other method on the arduino (poll your row/column inputs) and then calculate what audio file to play. Communicate that to the device and it plays.BowlOfRed– BowlOfRed05/27/2015 06:47:51Commented May 27, 2015 at 6:47
-
1If you can rig your device to print one of the numbers "1" through "48" based on inputs, getting it to instead play audio with one of the above would be pretty easy.BowlOfRed– BowlOfRed05/27/2015 06:50:03Commented May 27, 2015 at 6:50
#include <SD.h> // need to include the SD library
//#define SD_ChipSelectPin 53 //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 10 //using digital pin 4 on arduino nano 328
#include <TMRpcm.h> // also need to include this library...
TMRpcm tmrpcm; // create an object for use in this sketch
char mychar;
void setup(){
tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
tmrpcm.play("beware.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}
void loop(){
if(Serial.available()){
mychar = Serial.read();
if(mychar == 'o'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("helpyou.wav");
} else if(mychar == 'r'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("chortle.wav");
} else if(mychar == 'q'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("helpyou.wav");
} else if(mychar == 'p'){
tmrpcm.play("beware.wav");
}
else if(mychar == 'w'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("impresiv.wav");
}
else if(mychar == 't'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("seekyoda.wav");
}
else if(mychar == 'y'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("sensefear.wav");
}
else if(mychar == 'u'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("strongami.wav");
}
else if(mychar == 'i'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("whyhere.wav");
}
}
}
This code should be helpful. Make sure you have a SD card reader. You must also hookup the card reader:
3.3v goes to 3.3v on the Arduino UNO (for power)
GND goes to Ground on Arduino UNO
D0 goes to pin 12 on Arduino UNO
D1 goes to pin 11 on Arduino UNO
CLK goes to pin 13 on Arduino UNO
D3 goes to pin 10 on Arduino UNO
Lastly, download an arduino library so it can play audio files.
-
Finding code is easy, but the question is more focused on the right hardware.bytecode77– bytecode7705/26/2015 13:14:20Commented May 26, 2015 at 13:14