Trying to Play WAV File, Speaker Won't Stop Making Noise

I am trying to play a WAV file from an SD card, working from Arduino's Simple Audio Player Tutorial.

I built the amplifier circuit from the tutorial (diagram below) and verified that I'm able to initialize, read from, and write to the SD card. The code uses the AudioZero library. The WAV file is 8-bit mono, 16000 sample rate.

The speaker plays a horrible noise as soon as the Arduino is plugged in! It happens the instant it is plugged in, whether it's plugged into the computer or a wall charger, no matter what code is loaded. It doesn't stop until you unplug the Arduino. Playing with the potentiometer doesn't seem to change the noise either. By touching the speaker cone, the noise is suppressed and I can hear the audio file playing faintly.

Hardware:

  • Arduino MKRZERO
  • 8 ohm speaker found here
  • TI LM386 amplifier

Here is the circuit diagram:


Here is a picture of my circuit (pins used are GND, 5V, and DAC0/A0):

Code:

#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

const int chipSelect = SDCARD_SS_PIN;

void setup() {
  delay(3000);
  Serial.println("Starting Setup");
  // debug output at 115200 baud
  Serial.begin(9600);
  // set up SD-card
  Serial.println("Initializing SD card...");
  //
  if (!SD.begin(chipSelect)) {
    Serial.println("1 failed!");
    while (true);
  }
  Serial.println(" done.");
  AudioZero.begin(16000);
}

void loop() {
  Serial.println("loop starts");
  playFile("imagine.wav");
}

void playFile(char fileName[]) {
  File soundFile = SD.open(fileName);
  if (!soundFile) {
    // if the file didn't open, print an error and stop
    Serial.print("error opening ");
    Serial.println(fileName);
    while (true);
  }

  Serial.print("Playing ");
  Serial.print(fileName);

  AudioZero.play(soundFile);
  Serial.println("End of file. Thank you for listening!");
  Serial.println("Count");
  Serial.println(iCount);
  while (true);
}

That sounds like a grounding issue, possibly leading to pickup of 60 Hz hum from the environment or a feedback problem. Is the noise a low frequency buzz, or a high pitched squeal?

I don't see anything obviously wrong with the wiring in the photo, but triple check every connection. Breadboards are unreliable, so as a last resort try rewiring the setup.

Try removing the capacitor between pin 1 and pin 8. That gives you a gain of 200 (datasheet). You need almost no (voltage) gain (1) and you may end-up turning-down the pot to where you've got overall attenuation rather than gain.

If the pot is wired correctly it should turn-down the signal (and noise) from the Arduino to almost zero. So the noise is coming from the power supply, or the amplifier circuit itself. In any case, lowering the amplifier gain should lower the noise proportionally.

USB power can be noisy, a "charger" or an external power supply can also be noisy, or digital switching noise from the microcontroller can get into the power supply (or into the Arduino's analog output).

Digital noise or noise from a switching power supply is usually "whine". Noise from a linear power supply is usually 50/60Hz power line "hum" or "buzz". Noise generated by the amplifier itself is usually "hiss".

(1) You DO need current & power gain, but with a 5V Arduino and a 5V amplifier you don't need any voltage gain... With a gain of 1, 5V in will give you the full 5V out (with the volume pot turned-up). With a 3.3V Arduino, a gain of 2 is enough to drive the amplifier into distortion.

@jremington @DVDdoug

The noise is an annoying hum. I used my piano and the closest note is D4 which is 294 Hz.

If I remove the connection from the A0/DAC0 pin to the amplifier, the noise continues.

I looked at the LM386 datasheet and it says that with pins 1 and 8 open, the gain is 20. I don't see anywhere that it says you can get below 20, and based on @DVDdoug 's comment, that sounds like way too much gain - could that be a problem?

What happens if you disconnect the amplifier audio input lead from the Arduino?

working on this project with Randance. I wired the speaker directly to the pot -- bypasssing the amplifier. I get very low level sound but distortion free. @DVDDoug's comment suggests that the minimum gain in the amp is too high for either the 5V or 3.3V arduino.

There's no decoupling on 386's pin6 +Vs (100uF electrolytic. in parallel with 0.1uF disc).

Solved the problem by removing connection between the 1 and 8 pins on the LM386.

Please check Post No.3 as 'Solution'

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