My Code Doesnt Work Anymore To Output Music From SD Card Module On Arduino Mega (TMRPCM Library Doesnt Work Properly)

Hi I have a problem with my code because in my previous project my arduino mega could make a sound but after I tried again in the near future it turned out that the sound could not come out. but when I used the default arduino example program the idea for the simple tone turned out to work. does anyone have a solution? Note: "The Code Work Properly On UNO"

#include "SD.h"
#define SD_ChipSelectPin 53
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

 
void setup(void) {
tmrpcm.speakerPin = 8;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(5);
Serial.println("Play Music");
tmrpcm.play("dona.wav");
Serial.println("Loop Music");
}
  // We'll send debugging information via the Serial monitor

 
void loop(void) {

}

What does this code outputs to the Serial Monitor?

PS Putting a two line question in the message title is not a good idea. Try to be short and clear.

the output only

Play Music
Loop Music

the music didnt came out

So your SD card initialized and works. So good!
Try to change the speakerPin to 11, it is default for Mega

i already made it on pin 11. but nothing happens

So why in the code it setup as pin 8?

i change it because i follow the guide from example code from arduino ide to play simple tone. and it works! but after i tried it on this code. nothing happens

What is your actual speaker pin ?

  • in the code
  • on connections

It must be 11 in both cases.

Showing the code that is not consistent with your actual firmware is wasting the time for those who could help you.

Right Now :
Speaker Wiring --> 8
The Code --> 8

Already Do :
Speaker Wiring --> Any PWM and Digital Pin
The Code --> Same as above

try to test

Speaker Wiring --> 11
The Code --> 11

Done

Output still same

Play Music
Loop Music

Thanks bud. The error actually on my cabble. Its broken. Thanks to help

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.