2

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 May 24 '15 at 17:06
  • Are there? I haven't found any yet. Can you point me to one? – bytecode77 May 24 '15 at 17:07
  • 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 May 24 '15 at 18:37
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.

  • Can any of these be triggered with 48 different sounds on button click? – bytecode77 May 27 '15 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 May 27 '15 at 6:47
  • 1
    If 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 May 27 '15 at 6:50
0
#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.

https://github.com/TMRh20/TMRpcm

  • Finding code is easy, but the question is more focused on the right hardware. – bytecode77 May 26 '15 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.