Pages: [1] 2   Go Down
Author Topic: help with LM386 audio amp.  (Read 2498 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


CO, USA
Offline Offline
God Member
*****
Karma: 5
Posts: 711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6637
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!


* Screen shot 2012-03-03 at 10.26.38 PM.png (89.7 KB, 833x545 - viewed 55 times.)
* AnalogGuitarInput.fzz (6.82 KB - downloaded 12 times.)
« Last Edit: March 03, 2012, 11:30:32 pm by uberdanzik » Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* Screen shot 2012-03-04 at 1.35.42 PM.png (89.13 KB, 886x530 - viewed 36 times.)
Logged

Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 32
Posts: 1282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* mcp602.png (89.4 KB, 898x543 - viewed 41 times.)
« Last Edit: March 13, 2012, 10:02:43 pm by uberdanzik » Logged

Pages: [1] 2   Go Up
Jump to: