I have developed an Arduino program that plays a WAV file from the SD card using a speaker.
This is the circuit schematic
The sketch I'm using is based on TMRpcm library and PWM output
#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h>
int sdpin=10;
TMRpcm tmrpcm;
void setup()
{
Serial.begin(9600);
pinMode(sdpin, OUTPUT);
tmrpcm.speakerPin=9;
tmrpcm.setVolume(3);
SD.begin();
}
void loop()
{
if(Serial.available()>0)
{
String data=Serial.readString();
if(data=="pause")
{
if(tmrpcm.isPlaying()==1)
{
tmrpcm.pause();
}
}
else if(data=="stop")
{
if(tmrpcm.isPlaying()==1)
{
tmrpcm.stopPlayback();
}
}
else
{
String path="/Music/"+data;
if(tmrpcm.isPlaying()==1)
{
tmrpcm.stopPlayback();
}
tmrpcm.play(path.c_str());
}
}
}
At first I could play the music with the speaker but then it stopped working and because I don't have enough skill to make one myself, I would like to know if I can use a buzzer for that.
I know that buzzers can be used to generate melody using the tone() function but I'm not sure if I can use them to play wav files using PWM output.
Any help will be appreciated.
I don't have enough skill to make one myself
... skill to make what? .... the speaker stopped working probably because the output pin on the Arduino blew out