Electronic – LM386 motorboating that goes away with a resistor in parallel with the bypass capacitor on pin 7

amplifierlm386

I'm building a simple amplifier around a LM386. The circuit I'm using is this:

The input is on pin 1 of the connector and is a square wave coming from a digital pin on a NodeMCU devboard.

When I turn the circuit on, I can hear a low frequency oscilation on the speakers (not a constant tone, but as if the speaker was turned on and off a few times a second).

I tried adding a capacitor between the signal and ground as it seemed to work in this related question but I needed a fairly big capacitor (220uF) to get any result at all, and it only decreased the volume of the noise (not to mention it is filtering my input, if I understand it correctly).

What did get rid of the noise completely was adding a 1K resistor between pin 7 and ground (in parallel with the existing capacitor):

I have no idea why this works, but it gets rid of the noise completely.

So my main question is: what is this resistor in parallel with the capacitor doing and why does this remove the noise?

I'm happy to keep this solution if it makes sense, but first I need to understand why it works.

Best Answer

The main problem is that you have the gain of the LM386 set much too high.

By putting a capacitor (C1) between pin 1 and 8 you have set the gain to 200 times. If the input signal is coming straight from a digital pin on the processor with 3.3V output you only need a gain of 2 at most.

With a gain of 200 the LM386 is amplifying small signals coming from the digital pin to an audible level.

Even if you remove C1 the gain will still be 20 times - you will need to attenuate the signal from the processor by about 10-11 times to avoid overloading the amplifier. A 10k resistor in series with the input and a 1k resistor to ground will achieve that. Even better would be a potentiometer to adjust the volume.

Your current solution is drastically altering the biasing of the LM386 such that it is not a linear amplifier, the digital signal is still able to break through the LM386 to drive the speaker but small noise signals do not. Please see page 1 of the data sheet LM386 datasheet

If you only need to drive the speaker with a square wave then you may not even need an amplifier. For low volume just a capacitor and resistor in series driving the speaker will function (for example a 47 ohm resistor and a 10uF capacitor). The resistor is to avoid overloading the digital output with the low resistance of the speaker while the capacitor removes the DC offset since the digital output is always positive (either 0V or 3.3V).