Why is it not working ? I get a a buzzing sound instead of my sound. I suspect my circuit is wrong but don't know why.
--> Can someone please help ?
Here is the diagram :
The mosfet is the IRF520 Mosfet I got with the starter pack.
Here is the code :
#include <SPI.h>
#include <SD.h>
#include <TMRpcm.h>
TMRpcm tmrpcm;
#define DISABLE_SPEAKER2
#define SD_CS_PIN 4 // Chip Select pin for SD card
void setup() {
Serial.begin(9600);
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.print("SD Card init ...");
if (!SD.begin(SD_CS_PIN)) {
Serial.println("Init failed!");
while (1);
}
Serial.println("Init OK");
if (SD.exists("c6000_16.wav"))
Serial.println("File found !");
else {
Serial.println("File NOT found !");
while (1); // Stop if the file is not found
}
// *** WAV File Header Check ***
File wavFile = SD.open("c6000_16.wav");
if (!wavFile) {
Serial.println("Error opening WAV file!");
while (1);
}
// Read the first 44 bytes (typical WAV header size)
byte header[44];
if (wavFile.read(header, 44) != 44) {
Serial.println("Error reading WAV header!");
wavFile.close();
while (1);
}
// Print some header information (for debugging)
Serial.print("File Size: ");
Serial.println((uint32_t)&header[4]); // File size - 8 bytes
Serial.print("Sample Rate: ");
Serial.println((uint32_t)&header[24]); // Sample rate (Hz)
Serial.print("Bits per Sample: ");
Serial.println((uint16_t)&header[34]); // Bits per sample
wavFile.close();
Serial.println("Playing ...");
tmrpcm.play("c6000_16.wav"); // Try playing with TMRpcm
Serial.println("Stop");
delay(2000);
Serial.println("Loop");
}
void loop() {
// put your main code here, to run repeatedly:
tone(9, 440);
delay(1000);
noTone(9);
delay(1000);
}
And here is the output :
SD Card init ...Init OK
File found !
File Size: 2189
Sample Rate: 2209
Bits per Sample: 2219
Playing ...
Stop
Loop

