Trying to play WAV file with Arduino - getting buzzing sound instead

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

You need a different MOSFET or a transistor.
Do you have any transistors?
If yes what are the part numbers

Does your speaker look like this?

Thank you for your reply.
Yes my speaker looks exactly like that one.
I just have the Arduino starter pack so that's the only transistor I have.
May I ask why that transistor will not work?

It may or may not work in certain applications because it needs 10V on the gate in order to turn it ON/OFF and the Uno is only 5V
It was a very poor choice to include in a starter kit.

Try this
Make R3 330 ohms.
Remove R1
Make R2 100 ohms

Try a simple sketch using tone() just for testing.

Sample Rate: 2209

Minimum sample rate for TMRpcm is 8000Hz.

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