Go Down

Topic: help with LM386 audio amp. (Read 2863 times) previous topic - next topic

uberdanzik

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

Osgeld

Quote

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

Quote
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.


yes, like a Light Emitting Diode, it will be fine without adding extra diodes
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

justjed


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.
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

westfw

Quote
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.)

uberdanzik

Quote
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.

jwatte


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

uberdanzik

#6
Mar 04, 2012, 05:24 am Last Edit: Mar 04, 2012, 05:30 am by uberdanzik Reason: 1
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!

jwatte

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.

uberdanzik

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.

superKittens

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: http://www.youtube.com/watch?v=OMJ9WGrRf6A
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).

Quote

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!
https://www.circuitlab.com/

Good luck!

uberdanzik

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:

http://vimeo.com/38411865

Nick Gammon


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:

http://www.gammon.com.au/forum/?id=11011

And my radio-controlled car:

http://www.gammon.com.au/forum/?id=11506

There's no problem with just connecting it to +5v and Gnd.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

jwatte


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 :-)

DVDdoug

Quote
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 active peak detector.  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 averaging/smoothing 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.

uberdanzik

#14
Mar 14, 2012, 03:26 am Last Edit: Mar 14, 2012, 04:02 am by uberdanzik Reason: 1
Quote
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.

Go Up