help with LM386 audio amp.

Hi, I'm trying to find the appropriate component values and wiring for a LM386 audio amplifier. I've found other examples on the internet but nothing is working. I've gotten it to work halfway, but every example I find uses different power sources or inputs, and I think they're just not calibrated for a guitar signal and arduino. I have no experience with how to determine component ratings or values. I'm at my wits end and need somebody to build me a simple schematic with the correct value components.

I'm essentially creating an LED light that pulses based on the guitar input's strum patterns.

  1. The guitar signal is AC at around 1.5 volts max, and it will be running into the LM386.

  2. The output of the LM386 should be amplified up to a max of 5v and it will still be A/C (I assume) so I need to use a rectifying diode setup to convert it to DC.

  3. Then once it's in DC I'm pretty sure I need to put a small capacitor and resistor to help me find the peak voltages. Otherwise I'm still going to get zero values in between each wave of the signal. I could probably figure these compnent values out with trial and error, but guidance would be nice.

Also, I've heard there is an electrical engineering software program out there that will simulate electronics so you can build your circuit on the computer without having to buy parts and try them out. This would be immensely helpful. Anybody know what the program is called so maybe I could help myself?

Thanks for any help.
Dan

  1. The guitar signal is AC at around 1.5 volts max, and it will be running into the LM386.

I am no where near anywhere an expert with amps, but I know the 386 is garbage with big inputs ... you need to increase the values of the voltage divider going into the input

  1. The output of the LM386 should be amplified up to a max of 5v and it will still be A/C (I assume) so I need to use a rectifying diode setup to convert it to DC.

yes, like a Light Emitting Diode, it will be fine without adding extra diodes

uberdanzik:
Also, I've heard there is an electrical engineering software program out there that will simulate electronics so you can build your circuit on the computer without having to buy parts and try them out. This would be immensely helpful. Anybody know what the program is called so maybe I could help myself?

You might be thinking of Spice. There are some free clones out there, or sorta-clones. One is Gnucap. Here's a list of others.

I'm essentially creating an LED light that pulses based on the guitar input's strum patterns.

Is there some reason that you've decided to use the lm386? It is essentially a "speaker amp", designed to convert typical audio "line" levels to the power levels needed by small speakers. For general voltage-level conversion, you'd probably be better off with a general purpose "op amp" (or two) that is designed to be highly configurable in its behavior (gain, offset, etc.)

Is there some reason that you've decided to use the lm386?

I just saw other people using the LM386 it and though I'd give it a try out of frustration.

I'd love to try an opamp, but finding one that ran on the arduino's 5v power proved difficult. Every example I found wanted me to use a power supply that had negative voltage or ran on 9-18 volts.

If you can recommend an appropriate opamp that will run on the arduino's 5v and will handle the guitar's input, I'm more than willing to order it.

uberdanzik:
If you can recommend an appropriate opamp that will run on the arduino's 5v and will handle the guitar's input, I'm more than willing to order it.

Try an MCP602: http://search.digikey.com/us/en/products/MCP602-I%2FP/MCP602-I%2FP-ND/305932

Ok, thanks for the op-amp recommendation. I'm going to order it.

In the meantime, I've attached a fritzing screenshot of my circuit. Please take a look.

  1. Do I have the op-amp wired correctly, are there any other components I need to have connected to it?

  2. I'm trying to figure out what kind of values I need for the resistor and cap "peak finder". I know I can use trial and error, but I don't want to use values bigger than I need.

Thanks!

AnalogGuitarInput.fzz (6.82 KB)

I have not checked the wiring diagram against the data sheet for the opamp.

The opamp will already do the "DC" part, because it won't output anything lower than GND. You will need to bias the input to 2.5V if you want to capture a full wave. For a "level meter," that won't be necessary. Thus, you can lose the diode. If you still want to use a diode, use a Schottky for less loss and faster response, but really, don't use any at all.

The cap and resistor will form an RC filter. I can't see the value of the capacitor, so I can't calculate the "corner" frequency of that filter, but you probably want it to be on the order of 100 Hz or less for an envelope follower. With 1 kOhm resistor and 10 uF capacitor, you get a T (tau) of 0.01, which is probably in the ballpark.

Ok awesome, thanks for the advice. I'm just going to post the updated breadboard layout now, and once the MCP602 comes in the mail I'll hook it up and post about how it goes. Thanks again.

Hmm...from what I understand, you want to build a circuit that lights up an LED for each strum am I right?

According to Pete (Sparkfun) has a great tutorial on opamps: SparkFun According to Pete 9-6-11: OpAmps - YouTube
One of the first circuits he shows is a comparator. You could potentially use this and put in a rectifier before the opamp to convert your AC guitar signal into DC before it heads off to the comparator. Your comparator can spit out 5 V to drive your LED (you might want to put a LED driver at the end).

Also, I've heard there is an electrical engineering software program out there that will simulate electronics so you can build your circuit on the computer without having to buy parts and try them out. This would be immensely helpful. Anybody know what the program is called so maybe I could help myself?

Check out CircuitLab! It's a browser-based simulator. I just heard about this today on hackaday and haven't had the chance to try it out yet but it looks promising!

Good luck!

Alright a fresh new tube of MCP602's came in the mail on Friday!

I hooked everything up and discovered my circuit had the power mains to the opamp backwards, but I fixed that and boom, it started working.

My ADC reading now is at about 400 max, which is much better than what I was getting before. I'm hoping to make this larger because the ADC bottoms out at zero before the note actually dies out. I'm not sure how I can do this.

I've posted a video so you can see what I mean:

uberdanzik:
I'd love to try an opamp, but finding one that ran on the arduino's 5v power proved difficult. Every example I found wanted me to use a power supply that had negative voltage or ran on 9-18 volts.

I've been using the LM358 in various applications on the Arduino, such as this one:

And my radio-controlled car:

There's no problem with just connecting it to +5v and Gnd.

uberdanzik:
My ADC reading now is at about 400 max, which is much better than what I was getting before. I'm hoping to make this larger because the ADC bottoms out at zero before the note actually dies out. I'm not sure how I can do this.

You need a reistor ladder between the output and the negative input and ground to set the amplification factor.

Additionally, you need a capacitor between ADC input and ground -- try another 10 uF there to start with. The reason for this capacitor is to low-pass-filter the signal so that the ADC gets less of a "moving target" to try to capture.

A schematic is generally a lot more useful for figuring out what you're trying to do than a hookup picture.

And, finally, if you want some more theory around this, I think what you're trying to build is an "envelope follower" which is a word you can google for lots of information :slight_smile:

My ADC reading now is at about 400 max, which is much better than what I was getting before. I'm hoping to make this larger because the ADC bottoms out at zero before the note actually dies out.

The problem is the rectifier. A diode doesn't turn-on until it has about 0.5 to 0.7V across it. Anything "quieter" than that is going to get killed*.

The solution is to add an op-amp to make an [u]active peak detector[/u]. You can replace the switch with a resistor, and you may beed a buffer amplifier (an op-amp circuit with a gain of one) depending on your capacitor & resistor values. I just made a buffered peak detector with a dual op-amp. In my circuit (also used for audio) the resistor is 1M, and I'm experimenting with capacitor values between 0.1uF (1/10th of a second time-constant) and 0.33 uF (1/3rd of a second).

Slightly off topic... Something else I'm working on is automatic level adjustment/calibration. I'm adjusting the analog thresholds, depending on the input levels. I'm updating an array (every second or so) and keeping the latest 10-20 results in the array. I can use [u]averaging/smoothing[/u] to get a running-average, or I can pick-out the peak value from the array, etc. So far it's working great! I can change the volume and after 10 or 20 seconds it re-adjusts to the new volume level.

  • Do you know what a noisegate is? The diode is acting something like a noisegate. Some guitar players use a noisegate to kill the hum & buzz between songs when they are not playing.

The problem is the rectifier. A diode doesn't turn-on until it has about 0.5 to 0.7V across it. Anything "quieter" than that is going to get killed*.

Is the rectifier in the MCP602? or the Arduino? I used to have a diode in my old design I posted, but I took it out because jwatte said the opamp will essentially do the same thing. For the video I took, that version was without the diode. I wasn't aware there was a rectifier in the circuit?

I've attached my most recent schematic for clarification, which matches the video.

very good

've attached my most recent schematic for clarification, which matches the video.

That's not a schematic. A schematic will have a triangle for the op amp, with a "+" and a "-" line going into the flat side, and the amplified output going out the pointy side. It will have resistors as either zig-zags or skinny boxes. It will have capacitors as double crossbars. It will have wire as solid black lines. That's the kind of schematic you need to post to get more help on why the envelope follower you're trying to build doesn't do what you want it to do. The reason for this is that trying to trace the circuit through the connections in that picture is pretty hard, especially if you haven't memorized the pinout of your particular IC.

Additionally, it seems you haven't yet tied a second capacitor between the ADC input and ground for the Arduino, to act as a low-pass filter.

Ok I've finally found how to create a real schematic! I used a program called Fritzing, and I've taken a screenshot of the schematic view (attached photo).

So in order to eliminate this 0.5 - 1.0v loss on the ADC, is it going to need another op-amp or can I use the 'B' input of the MCP602?

@jwatte: I'm a little confused on the second capacitor you recommended. I thought I already had one 10uf capacitor in between the ADC and Ground, are you saying to add another identical one?

Thank you,

Yes, it looks as if the capacitor is proper for filtering, although there is no series resistor to create an RC (there's a parallel resistor only.)
There is also no resistor going into the inverting input. This may not be much of a problem, I don't know off-hand. Try putting a 1 kOhm resistor in series from the output to the capacitor. You may want to lose the parallel resistor.
You're tying the signal to inverting input, and ground to the positive input -- this seems like it would always generate zero out to me.
There's no gain control in the opamp, either. Typically, a 100 kOhm resistor from out to negative in, a 10 kOhm from negative in to ground, and running the signal into positive input, will set up 10x gain, if I recall correctly. As it is, you will either get nothing, or a full-clip signal.

Now, I'm not an EE -- I just go by what I've learned over a life of on-again, off-again hobbyism, so I may very well be missing something obvious. Doesn't that give you the warm fuzzies? :slight_smile:
What I do know is that an oscilloscope can save days of debugging. If you don't have one, you may want to look for either a cheap pocket oscilloscope, or a used one somewhere. These days, they are all digital storage oscilloscopes (DSOs) that capture the waveform once and let you look at it for as long as you want, which is great in a case like this.

What I do know is that an oscilloscope can save days of debugging.

Ok so I downloaded a scope program that uses your soundcard input, and that has really helped. I just realized however that my opamp output is peaking out at 2.5volts.

If I send a really gentle note through the amp, the output seems to be hugging the zero on the low size, and on the high side it looks like the top half of a waveform. (GREAT!) But when I play a really loud strum, the low size pushes out to -2.5 volts, and the top peaks out at 2.5 volts. It's like the more voltage the signal has, the more the signal tries to push to -2.5 volts and even out over zero, but in a skewed manner.

This is probably why my ADC on the arduino is only hitting 500 range now, instead of the full 1023.

Any ideas of why it would be doing this?