We show you how to make a small amplifier using this versatile component.
We’ve used the LM386 before in DIYODE projects. This time, however, we’re going to look at the IC itself, and some of the things you need to think about if you’re going to design it into your own projects.
WHY AN AMPLIFIER IC?
When many of us think of amplifiers, we think of home theatre systems, music to wake the neighbours, or a concert. However, in many cases for the maker, these are overkill and somewhat impractical. Yet many projects we make require some form of increase in audio power from the small signals generated by the circuits. This is particularly true of Arduino and Raspberry Pi boards. Both will drive a small speaker, but with minimal volume.
An amplifier integrated circuit (IC) is the answer, and the LM386 is one that is commonly available. It runs from a single-rail power supply and contains many of the components and circuits needed to drive a speaker or headphones to a reasonable volume. All that is left is a minimum of external components required for the user to have control over some functions. This avoids the bulk, weight, and power supply considerations of a larger amplifier that would simply be impractical and largely redundant for many projects.
While there are several variants of the LM386, we’re going to describe the LM386N-1, the most commonly retailed version. Most other variants can only be sourced through trade suppliers. The pin-outs and principles remain the same. However, some of the specifications differ for other variants.
The LM386 is designed to work without heatsinking, within its parameters. Several other audio ICs are designed to do this too, but most use additional pins connected to a metal plane inside the IC. The idea is to solder these pins to a large filled plane of copper on the underside of a PCB, which acts as a heatsink. This is altogether impractical for those working with prototyping boards such as veroboard, or solderless breadboards. The LM386 avoids this problem, although some application examples can be found online using the small stick-on heatsinks like those made for Raspberry Pi processors.
FEATURES AND SPECIFICATIONS
The biggest drawcard of the LM386 is that it is virtually all-in-one. There are no separate transistors needed, no matching of pairs, worry about interference or signal path lengths. Provided the device is used as designed, no heatsinking is required. This is because the package has a maximum dissipation of 1.25W. The actual power output can be determined from a series of graphs in the datasheet. The Texas Instruments datasheet has no impedances listed for its graphs, but National Semiconductor’s shows that for a 12V supply, the LM386 can drive 0.4W into 8Ω before exceeding the maximum dissipation, or 0.3W into 4Ω.
The lowest Total Harmonic Distortion of the LM386 is 0.2%, somewhere between 500 and 1000Hz. The curve starts at 20Hz, with 0.5%, which is reached again at 5kHz. After this, THD rises all the way to 1.5% at 20kHz. However, not many people older than 10 years old can hear above 15kHz, and most adults can only hear up to around 13kHz, despite what many think or claim. Hearing the effects of THD even at the levels present in the LM386 also takes some training, and can be considered low enough to be ignored by most makers. As an aside, the graph for THD rises almost vertically, leaving the scale at 10%, when power output increases over the 1.25W maximum. While overdriving amplifiers is sometimes desirable to musicians, and guitarists in particular, it would make for an interesting experiment with the LM386!
Frequency response for the LM386 is fairly flat until after 20kHz. As noted earlier, most of us can’t hear this high anyway. While the graphs themselves in the datasheets are relatively flat, the IC can have its bass frequency response boosted, which we discuss shortly.
|SUPPLY VOLTAGE||4 - 12V|
|MAC VOLTAGE GAIN||200|
|MAX INPUT VOLTAGE||0.4V|
|MINIMUM LOAD IMPEDANCE||4Ω|
|TYPICAL OUTPUT POWER||325mW|
A NOTE ON AUDIO SIGNALS:
Before moving on, it is worth recapping what audio signals are, for those who don’t work with them regularly or have never thought about it before. In general, audio signals are an Alternating Current (AC), in which current takes some sort of wave form, often a sine wave but there are plenty of others. At maximum amplitude, the high points (or positive peaks) of this wave are at the positive supply rail, and the negative peaks are at the negative supply rail. This is why many amplifiers have a dual rail power supply, with a negative rail, a positive rail, and 0V in the middle. The LM386, and other single-rail amplifiers are designed so that the middle of the waveform sits at the half-way point between the positive supply rail, and ground. An AC signal can still be input, and will still have the relevant output. There are some caveats to this, but they’re largely ignorable for a small, low-powered design such as this. However, it is worth noting that some input signals could be considered Direct Current (DC). DC is generally bad for speaker coils, as it turns them into heaters and leads to speaker degradation and failure. Sources of audio which are technically DC can be used with single rail amplifiers like the LM386, provided the duration of DC is not long. For example, a Pulse Width Modulated (PWM) signal, with a frequency in the audio range, would still produce a sound. The wave does not have a gradual rise and fall like a sine wave or even a triangular wave, but it turns on and off. This is exactly what’s happening in this month’s Kids’ Basics project.
The LM386 has two inputs, an inverting input, and a non-inverting input. This is common for operational amplifiers and other small amplifier designs, but not generally seen on power amplifiers. In many amplifier circuits, one of the inputs is unused, but the design retains both for versatility. This allows some designs such as multivibrators that use both inputs such as comparators. In most cases, the non-inverting input is used, and most of the datasheet examples use this too.
Internally, both inputs have a pulldown resistor of 50kΩ. Open inputs sit at around 12mV, because the input transistors have a base current of 250nA. The resistance of the driving source interacts with the inputs, and can have offset effects at the output. To avoid this, you’ll need to know a little about the DC resistance of the source. If it is less than 10kΩ, then the unused input can be shorted to ground (which will also stop it amplifying any noise it picks up). Source resistance above 250kΩ requires no grounding, but a 0.1μF capacitor to ground is recommended for high gains. Any value in between can be compensated for by adding the same value of resistance between the unused input and ground.
For most makers, the 10kΩ or less category is the one we’re after. The 555 used in this month’s Kids’ Basics, for example, has a DC resistance of its output pin of around 100Ω when high, and somewhere around 10Ω when low. Sources actually differ on this point and the 555’s datasheets don’t directly confirm (though it can be calculated from other data given). Many microcontroller outputs are similar. Capacitive coupling, that is, connecting a capacitor in series with the input, eliminates the problem, but may not suit your application.
In terms of feeding a signal to the input, the maker has the option of directly connecting the source, using a voltage divider, or AC coupling. Direct connecting is not necessarily advisable, as signal adjustment isn’t possible. General practice is to use a voltage divider formed by a potentiometer, with one end connected to the source, the other end to ground, and the wiper to the input of the amplifier. AC coupling, where a capacitor is placed in series with the input, can be used on its own but is better combined with the potentiometer option to provide both DC blocking and volume control. As noted above, the LM386 can be used with DC signals such as PWM sources in the audio frequency. Using capacitive coupling ensures that there can never be too long a DC pulse, as current only flows while the capacitor is charging or discharging.
The voltage gain of the LM386 can be set easily by the manipulation of two pins. Internally, the gain is set at 20 by an internal resistor between pins 1 and 8. If a 10μF capacitor is connected between these two pins to bypass the internal resistor, the gain becomes 200. If a resistor is placed in series with this capacitor, gain can be set anywhere between 20 and 200. Although the datasheets do not say so, gain can be reduced below 20 by simply placing a resistor between pins 1 and 8. Because resistors in parallel divide the total resistance, any external resistor will have the effect of reducing the gain. Bob Harper’s Experimenter’s Amplifier from issue 20 uses a 1kΩ resistor to achieve a gain of 10.
While there is an internal 1.35kΩ resistor to set the gain, there are other current paths and factors involved. This means that, while externally setting the gain, the regular maths for resistors in parallel will give a fair indication of the total resistance (remember to include the series resistance of the capacitor if used), it won't be perfect.
The output of the LM386 automatically centres to half the supply voltage. When configured as an amplifier (the LM386 can be used to build oscillators and other circuits besides amplifiers), the load connected to the IC should be capacitively coupled via an electrolytic capacitor, with its positive lead to the output, and its negative to the speaker. The other side of the speaker goes to ground. This ensures only AC signals get to the speaker, and any DC is blocked. Capacitor values are open to variation, but the datasheet examples all use 250μF values, and most designs around utilise values from 100μF to 330μF. Bigger is better, even over 1,000µF.
The output of the LM386 usually bypassed with a Resistor/Capacitor (RC) network. This stops frequencies that are too high from reaching the speaker, and generally consists of a 47nF capacitor and 10Ω resistor connected in series, between the output and ground.
Gain control can also be achieved by using external components in parallel with the internal feedback network. In addition to connecting components between pins 1 and 8, as above, connections can be made between pin 1, and the output at pin 5. By using an RC network, this option can alter the frequency response. This is useful to, for example, boost the bass response of the amplifier to compensate for the poor bass performance of the small speakers often used in these situations. In some cases, this feedback PC network can be used on its on, but the datasheets make it clear that if this is the case, the resistance must not be lower than 10kΩ, and is generally around 15kΩ. If the resistor, capacitor, or RC option is used between pins 1 and 8 to bypass them, then the RC feedback network from the output to pin 1 can have a resistance as low as 2kΩ.
Pin 7 of the LM386 is the bypass pin. A capacitor connected between here and ground (with the positive to the IC if using a polarised capacitor) will help the amplifier maintain the ability to reject power supply noise. A graph in the datasheet tells us that with no bypass capacitor, rejection is around 5dB across the whole frequency range. With a 47μF (the datasheet says 50μF but those are uncommon on retail markets) we can get close to 50dB rejection across most of the audio spectrum, making the circuit far more immune to noise on the power supply rail.
LM386 Amplifier Circuit
We present a simple amplifier that can run from 5V (although 12V would be better) and will handle signals from an Arduino or Raspberry Pi. There isn’t much to this amp, but it’s an integration of the things discussed above; some things just in case, and some necessary. As presented, this circuit will boost the volume of your microcontroller project to a useable level, such as for vocal feedback or playing MP3 alerts. You can alter some of the component values to see what effects you get. For example, bypass capacitors as big as 100μF are to be found online as ac input coupling capacitors. You can try it without the pin 7 bypass cap, alter the bypass network between the output and ground, change the gain components, or the RC network from the output to pin 5.
The circuit is largely from the datasheets, although with some changes and combinations. Rather than step by step instructions, this build should be achievable with just the parts list, schematic, and Fritzing. Try using it with the Tone function of an Arduino or similar, or see what effects you can get with a PWM output. We noticed quite a lot of noise during testing, and found that shielded wire for the input solved the problem.
|Parts Required:||Jaycar||Altronics||Core Electronics|
|1 x Solderless Breadboard||PB8820||P1002||CE05102|
|1 x Pack of Breadboard Wire Links||PB8850||P1014A||CE05631|
|4 x Pin to Pin Jumper Leads*||WC6024||P1022||PRT-12795|
|1 x 5k Logarithmic Potentiometer||RP7604||R2251||003-POT1KA|
|1 x 10Ω Resistor*||RR0524||R7510||COM-05092|
|2 x 15kΩ Resistors*||RR0600||R7586||COM-05092|
|1 x 47nF Capacitor||RM7105||R3021B||FIT0118|
|1 x 100nF Capacitor||RM7125||R3025B||FIT0118|
|1 x 470nF Capacitor||RM7165||R3033B||-|
|1 x 10μF Capacitor||RE6066||R5065||CE05274|
|1 x 47μF Electrolytic Capacitor||RE6100||R5102||CE05271|
|1 x 220μF Electrolytic Capacitor||RE6312||R5143||CE05149|
|1 x LM386 Audio Amplifier IC||ZL3386||Z2556||-|
|1 x Small Speaker||AS3000||C0610||ADA1890|
*Quantity required, may only be sold in packs.
There isn't much to be said as far as instructions for testing go. Check your connections, add a source, and power it up.
After initial power-up, we waited a minute or so to see if any smoke escaped. Even after checking and rechecking connections, mistakes can happen. The only people who don't make mistakes sometimes are in denial. While smoke did not escape this time, noise certainly did. It turns out our over-worked, fifteen year old lab power supply is getting a little noisy these days. What were perfectly smooth power rails when new, now display a scratchy and rapidly-changing line on an oscilloscope. A 1000μF and 100nF capacitor sorted that.
Next, it was time to plug in an audio source. To be honest, laziness was responsible for what happened next. A 3.5mm audio plug with speaker wire attached to tip and ground was already on the workbench. Using a phone as an audio source, this was connected to the amplifier's input. We should have made up an appropriate cable, as the lack of shielding on the input was very audible indeed. Screened cable solved the issue.
Now, we were able to test the circuit with both MP3 audio and tones from an Arduino. Both elicited adequate sound at a very usable volume. It could be heard at the other end of the office, with the single-frequency tones being more noticeable than music. The actual sound quality was really limited by the speaker. Just for the sake of it, we connected one of the monitor speakers we reviewed recently from Loudspeaker Kit. This speaker certainly determined that the amplifier is good, but understandably limited. The volume generated on these large speakers was also lower than the 57mm paper cone unit we used initially. The sound, however, was in line with the audio quality of the average mobile phone.
WHERE TO FROM HERE?
The main extensions of this project involve component value changes, both around the gain control, and the values of the bypass, input coupling, and output coupling areas. See what effects you can get from a 100μF input coupling capacitor.
The other logical extension is a commonly-powered twin unit, for stereo operation. While you won't often use a circuit like this for listening to music, the possibilities from a microcontroller with two outputs are interesting - perhaps a noise-cancelling circuit with an audio signal fed into one amp and a software-inverted microphone signal into the other? This isn't the only way to achieve this, of course.