Am I using a LM386N amp wrong?

I'm trying to measure -20 to +20mV signals, mostly around +/- 3mV. So I choose an LM386 amp because it seemed straightforward and had the built-in 20X gain I want even though it is typically used for audio amplification. After bread boarding it, it doesn't seem to work as expected. I thought if the input is say 10mV DC, the output would be 200mV DC, but it's not - it's much higher. In looking at the data sheet again, it says that the output is automatically biased to 1/2 the supply voltage. My electronics aren't superb so I don't understand that. Can I make it work in my application? Currently I simply have a supply voltage of 9V connected to pin 6, pin2/4 are grounded, input signal goes to pin 3 and the output from pin 5 goes to A1 of the Arduino - no other caps or resistors in the circuit.

What does it mean that the output is biased to 1/2 supply and can I remove that bias? If that isn't the correct IC to use in my case, can you suggest one that will fit in the 8 pin configuration this one has?

Thanks for your time.

The ADC on the Arduino can read only positive voltages, so in order to read negative voltages, you have to add an offset to your input values anyway. The LM386, where the offset (after amplification) is 1/2 the supply voltage, might work in this case. Experiment and let us know.

What kind of signals are you measuring? Are they AC or DC signals? If you are measuring AC signals, what frequency range?

If you are measuring AC signals, there's some fairly simple biasing techniques you can do to read the value from the ADC. If they are DC values, it's going to be more complicated since you can't just use blocking capacitors.

"Biasing" is the level the output signal will be at with no input. Being biased at half-supply means that with no input signal, the output voltage will be half of the supply voltage (4.5 V in this case). What values are you getting from your ADC?

Ideally, you want the signals to be biased at half of the ADC's Vref, so 2.5V. The answers to my first three questions will determine what we do.

The LM386 is not suited for anything other than amplification of signals to a speaker.

You should get yourself a LM358 - it's a general purpose opamp, and will do what you want to do.

// Per.

jremington:
The ADC on the Arduino can read only positive voltages

Yes, I understand that so I have a voltage divider (270 and 6.8k resistors) with one end voltage supplied by a 2.5V precision voltage regulator and the other end is my +/-mV signal. So actually, I am trying to amplify a signal between 75 and 123mV. I'm using that same 2.5V to set as an AREF on the analog pins. Mmmmmmm......maybe I don't even have to amplify the signal since the Arduino can read the 75 to 123mV values adequately especially with a reference voltage of 2.5V???? That doesn't give me enough resolution.

Jiggy-Ninja:
What kind of signals are you measuring? Are they AC or DC signals? If you are measuring AC signals, what frequency range?
DC signals

"Biasing" is the level the output signal will be at with no input. Being biased at half-supply means that with no input signal, the output voltage will be half of the supply voltage (4.5 V in this case). What values are you getting from your ADC?
When I input 0mV to my divider, I get 90mV out, That as an input to the amp along with 9.0V supply gives an output of 6.51V. So does that come from 90mV X 20gain = 1.80V plus 1/2 of 9V is equal to 6.3V? Is that it??

Ideally, you want the signals to be biased at half of the ADC's Vref, so 2.5V
I assume you mean when there is an AC signal. My AREF is 2.5V

So, is there a way of getting rid of the 4.5VDC offset or should I use a different amp?

Thanks for your effort!

The LM386 is not suited for anything other than amplification of signals to a speaker.

I disagree. The LM386 can be used for any purpose for which its characteristics are suited. That includes oscillators, DC amplifiers and motor drivers. Here is how to build Herbie the robot, who has an LM386 as the brain and the motor driver: https://solarbotics.com/download.php?file=64

However, since the OP has now changed his/her specifications (from amplifying signals in the range of +/- 20 mV, as per the original post, to 75 to 123 mV in the latest post), some sort of op amp circuit with an adjustable offset would be a better choice.

jremington:

..... some sort of op amp circuit with an adjustable offset would be a better choice.

But I still want to do the same as I outlined , the numbers have just been defined better. I want the 75mV input to come out times 20 or 1.5V.

Is my solution to put 1/2 of the supply voltage on pin 2, the negative input and therefore I would get just the gain rather than the gain plus the offset?

jremington:

The LM386 is not suited for anything other than amplification of signals to a speaker.

I disagree. The LM386 can be used for any purpose for which its characteristics are suited. That includes oscillators, DC amplifiers and motor drivers.

Sorry for to being too specific.

Of course it's usable as a small amp. for motor drive, etc - After all, a speaker is just a motor.

// Per.

I just ran some PSpice simulations on the circuit below, and it will do what you need. However, it will only work if your sensor output is relatively low impedance. Do you have a datasheet for the sensor we can look at to see the specs? if it's relatively high impedance, the circuit might get a little more complicated.

Some specs and requirements on the attached circuit:

  1. Gain is 50. +/- 20 mV input will give +/- 1V output. Gain is set by the ratio of R1/R3 (50k / 1k = 50). If you want a gain of 20, make the R1/R3 ratio equal to 20.
  2. Output is biased to 2.5 V, mid-supply for the default Arduino analog reference.
  3. This amplifier inverts the signal. +20 mV will give an output of 1.5 V -20mV input will give 3.5 V output. This can be easily dealt with in software.
  4. R2 & R3 must be equal.
  5. R4 & R5 set the biasing point of the op amp. They must be chosen to give 2.5 V to the non-inverting (+) input.

This particular op amp configuration is known as a summing amplifier. It amplifies the sum of the voltages applied to R2 & R3 (referenced to the + input of the op amp). In this configuration, the input to R2 is 5 volts (2.5 V relative to + input), the input to R3 is 0 V on your sensor's midscale (-2.5 V relative to + input), and the output is the sum multiplied by 50 (2.5 + -2.5 = 0V), again relative to the + input.

The op amp can be pretty much any op amp, an LM358 is common and will suffice. You can power the op amp off of 5V and GND, no need for a 9V supply.

How are you powering this sensor that it's outputting a negative voltage? Do you have bipolar (positive and negative) power supplies available? That'll make op amp circuits a lot easier if you do.

DBB:

jremington:

..... some sort of op amp circuit with an adjustable offset would be a better choice.

But I still want to do the same as I outlined , the numbers have just been defined better. I want the 75mV input to come out times 20 or 1.5V.

Is my solution to put 1/2 of the supply voltage on pin 2, the negative input and therefore I would get just the gain rather than the gain plus the offset?

No, unfortunately you can't get rid of that bias. What you could do is power the LM386 from the 5V rail, so the output would swing around 2.5V

I want the 75mV input to come out times 20 or 1.5V.

If that is all you want, then a simple noninverting op-amp amplifier will do, and it would have very high input impedance.

I've attached a photo of an LTSpice simulation of a simple 20x amp using the LM358. The input is assumed to have a 100 mV DC offset, with a superimposed 10 Hz sine wave of amplitude 20 mV (so the input goes from 80 mV to 120 mV).

The gain is (R2/R1 + 1) and the resistor values don't have to be as shown. You can always calibrate the circuit after it is built by supplying known input voltages and recording the ADC output (you should do that anyway).

WOW....Thanks for the input and the thought you folks put into this!

I got in trouble on another post for not giving enough info, so I better give you more of the story!

I'm making a monitor for my boat that measures battery voltage, current drain from the battery and water flow from the domestic water tank using IR sensors. The questions here relate to the current measuring part. I have a resistor at the negative side of the 12V battery (actually a section of threaded rod works well). It has a calculated resistance of .001 ohms since measuring the voltage difference across the resistor gives a 1mV drop equaling 1 amp current. I would like to measure a max of 20 amps going out of the battery and 30 amps going into the battery during charging with a resolution of .1A. So that's a range of -20mV when discharging and +30mV when charging (I tried to simplify earlier when I said +/- 20mV). So I have three wires coming from the battery: positive, ground at the battery and Vshunt upstream of the resistor. I am using the positive line to power the monitor and have had to use a voltage regulator to insure I don't deliver a possible 14.5V to the Arduino. I choose a 9V regulator. I then have used a divider to reduce the battery voltage to something I can input to the analog pins. I'm using a voltage divider of 270 and 6.8k ohms in between my Vshunt and 2.5V supplied by a precision voltage regulator. This gives 75mV going into the amp at -20A, 90mV at 0A and 123mV at +30A. My enclosure is fairly small so I'm trying to keep the number of components down - that's why I choose the LM386 with it's built in 20X gain. See schematic below - sorry for my lack of sophistication!

As was suggested, I tried supplying the LM386 with 5V rather than 9V, but the resolution is only +/- .25A and the signal is not steady so when I'm measuring 0mV, I get a swing of +/- 1A just sitting there.

I do not have bipolar supplies available.

Thanks again for your efforts.

Yes, actually the LM386 actually sounds an excellent part for your application as I suggested in this previous thread (with the usual group of naysayers.).

Now I suggest you simplify the arrangement even further. Just connect the inputs - pins 2 and 3 - to each end of the shunt (and preferably with a twisted pair) - if you are measuring such a small voltage you must measure the voltage across the shunt, not the shunt plus your other ground wiring. That is most likely why you were getting the jitter. Now connect pins 1 and 8 of the LM386 with a 680 ohm resistor), increasing its gain to 50 - now 30 mV reads as about 1.5 V.

It is even simpler. You do not need the 2.5V reference, as you are getting enough resolution simply by powering the LM386 from the 5V regulated supply in the Arduino and it is ratiometric - you are reading the amplified shunt voltage with reference to (half of) the Vref of the Arduino (and you are using Vref as the standard for your voltage readings anyway ). The beauty of this is that the LM386 is designed to set (centre) its output voltage to half of its supply, so your "zero" point is approximately 512 count on the ADC - which exact value of course, you calibrate (offset) in software.


Edited: Operating at 5V, the LM386 output can only swing between about 0.6V and 4.4V, so to utilise that swing, you set the gain to 50 so 30 mV (in either direction from the calibrated midpoint of the ADC) converts to 1.5V or 307 counts. With the 680 ohm resistor instead of the calculated 675 ohms between pins 1 and 8, this is probably closer to 300 counts anyway - which is exactly the number you wish to indicate (adding a decimal point after the second digit, for a resolution of 0.1) in Amps, so you need no further calculations.

As a general rule, you use integer maths instead of floating point for such purposes as this, you should be calculating the value of your divider resistors (and using a trimpot to calibrate) for the voltage similarly.

Thanks Paul__B for that - it's exactly what I was looking for. I guess my problem is that I was increasing the Vshunt voltage, amplifying it and then adding the offset which wrecked my resolution. Your way increases the amplification on the signal, which increases the resolution. Great! However, relative to pins 2/3, I currently have 2 tied to 4 which is tied to a general ground. Can I simply reconnect the ground wire from the shunt directly to pin 2 and keep the connection to pin 4 and ground as I have it? I need to connect that battery ground to Arduino ground in order to measure battery voltage. Also, of course, connect Vshunt directly to pin 3. Unfortunately, an 8 wire cable is installed and is not twisted pairs.

Paul__B:
As a general rule, you use integer maths instead of floating point for such purposes as this, you should be calculating the value of your divider resistors (and using a trimpot to calibrate) for the voltage similarly.

I don't understand this. With your solution, I'm not using dividers?

Paul__B:
Thanks for your help. I have revised my circuit as you suggested, but I now have a ground problem. Maybe I had it before too, but I don't know what the issue is. When I hooked up the new circuit, I saw I had -54mV at pin 3 relative to the arduino ground when it should have been 0mV. This happens only when I turn on power to the circuit with my on/off switch. I disconnected the Vshunt wire and again measured -54mV on the wire. So I measured both the Vshunt wire and the battery ground relative to the boat ground and found 54mV on the battery ground wire (I'm confused on the sign - don't know if it was positive or negative) which was still connected to the circuit but no voltage on the Vshunt line which was not connected . Can you help me figure out what is causing that? The lines from the battery (all 8, only three connected) go about 15' to the IR sensors where I joined the grounds of that circuit and continued the cable to the Arduino.
As I'm writing this, it doesn't sound right. The Vshunt line is connected through the shunt to ground so I should be measuring the same voltage on both. If I'm getting voltage feed back from the Arduino, I would think it would show up on the V shunt line as well since they are connected by the shunt. I'll have to verity my numbers tomorrow, but can you make any sense out of it?

I've attached an updated schematic.

Do not connect pin 2 to pin 4. Because the resistance in your circuit is so very low, you should be doing a proper 4-terminal measurement of the shunt resistor. Take pin 2 and snake its cable all the way over to the end of the shunt resistor.

Actually, looking at your schematic, I'm not sure you hooked the shunt up correctly. Nothing except your sense line should be branching off of the node between the shunt and battery, you want the shunt to be completely in series with the battery. That means the GND symbol should be on the other side of the shunt.

I've attached a picture of the proper way to hook up the shunt. Excuse the crudity of the drawing. Again, the + and - terminals of the 386 must be connected directly to each end of the shunt resistor, do not just ground the - input. And hook circuit ground to the end of the shunt, not the end of the battery.

What are you using as a shunt resistor?

Jiggy-Ninja:
Do not connect pin 2 to pin 4. Because the resistance in your circuit is so very low, you should be doing a proper 4-terminal measurement of the shunt resistor. Take pin 2 and snake its cable all the way over to the end of the shunt resistor.

Are you saying I should have 4 wires coming from the battery: positive, the 2 lines coming off the shunt and a ground coming off the far end of the shunt that goes to Arduino ground?

I had previously made a multimeter style monitor using a 200mV full scale digital display and a foot or so of threaded rod. I tuned the length so that I got 1mV=1A. So my display shows mV but reads in amps. It worked great but I wanted to add the water measuring device so I thought I would do it all over again but with an Arduino instead - not as easy for the current measuring part. I'm using the same shunt (read that as the same cheap shunt!).

Thanks for your help.

DBB:
Are you saying I should have 4 wires coming from the battery: positive, the 2 lines coming off the shunt and a ground coming off the far end of the shunt that goes to Arduino ground?

Yes, that's exactly what I said before. :smiley:

Paul__B:
Just connect the inputs - pins 2 and 3 - to each end of the shunt (and preferably with a twisted pair) - if you are measuring such a small voltage you must measure the voltage across the shunt, not the shunt plus your other ground wiring.

That is how you use a shunt - the two "sense" wires to the op amp connect to the ends of the shunt and nothing else, otherwise the other connections will inject currents into your sense wires.

In fact, shunts generally have four connections - two at each end so that the sense wires connect on the shunt material itself, independent of the connections that connect the shunt to the main circuitry.

Thanks for all the help you folks gave me - I really appreciate you taking your time to help. I'm going to have to break from this project for a bit. I'll let you know how it turns out when I get back to it.

Thanks again.

Doug

Good news! All is working well. I am using 3 wires coming from the shunt and one positive wire. The two wires on either side of the shunt go to pin 2 and 3 and the 3rd wire going to Arduino ground comes from the other side of the shunt. I still have a bit of noise that I had to deal with in software. On both the current data and the voltage data, I took an average of the 5 values on either side of the mean over 100 readings. That effectively got rid of the jittery numbers. So all is well. The current numbers compare very favorably to my multimeter.

The next project is to calculate battery capacity over time. If any of you have words of wisdom on how to do that, I would appreciate it. I know Peukert's Law is involved, so I'll start there.

Thanks again for your guidance.

Doug