Speaker
Arduino uno
Sd card reader module
Jumper wire
Sd card
Sd card adapter
Positive pin of speaker to digital pin 9
CS pin to digital pin 4
MOSI pin to digital pin 11
SCK pin to digital pin 13
MISO pin to digital pin 12
#include <SD.h> //include SD module library
#include <TMRpcm.h> //include speaker control library
#define SD_ChipSelectPin 4 //define CS pin
TMRpcm tmrpcm; //crete an object for speaker library
void setup(){
tmrpcm.speakerPin = 9; //define speaker pin.
//you must use pin 9 of the Arduino Uno and Nano
//the library is using this pin
if (!SD.begin(SD_ChipSelectPin)) { //see if the card is present and can be initialized
return; //don't do anything more if not
}
tmrpcm.setVolume(6); //0 to 7. Set volume level
tmrpcm.play("test.wav"); //the sound file "test" will play each time the arduino powers up, or is reset
}
void loop(){}