Trying To Make Audio Level Meter

Using LM386D jrc to amplify Audio Signal, and put the output into arduino A0 Pin, when no signal , output is not start from 0 is's measure 1.83 volt and when there is voice signal, output range from 0 to 5, thats mean that the output signal is sin wave ,...

how i make it changes from 0 to 5 volt ??!!

1 Like

Your Arduino input pin is probably "floating".

Since the Arduino can't read the negative half* of the AC audio waveform it's standard practice to bias the input at 2.5V. Your 10-bit ADC should read 512 with silence and that can be subtracted-out. There is a bias circuit attached to [u]this post[/u].

Or... If you're running the LM386 at 5V, it's output should be biased at about 2.5V so you just have to leave-out the output capacitor.

What's your audio source? The LM386 is a power amplifier (designed to take a line-level signal, or lower, and drive a speaker). (The gain may be too high.)

You are "sampling" an audio waveform which means your raw readings will "look random" with "quiet sounds" deviating slightly around the 512 bias (before subtracting the bias) and "louder sounds" deviating more.

You'll need to find the peaks, or take an average of the positive values, or an average of the absolute values, or calculate the RMS, etc., depending on how you want to define "audio level".

thats mean that the output signal is sin wave ,...

You do have a waveform but it's only a sine wave if you have a "pure" sine-wave signal.

how i make it changes from 0 to 5 volt ??!!

You won't get the full range out of the LM386. I don't know what the range is, but it won't go all the way down to zero or all the way to it's positive supply voltage. And of course, within it's operating range the voltage depends on the input signal level and the amplification.

*The Arduino can be damaged by negative voltages and/or the signal can be "damaged' (distorted).

Replace M1 with the Arduino and use a resistor divider to keep the voltage below 5 volts. This I found on eleccircuit web site.

DVDdoug:
There is a bias circuit attached to [u]this post[/u].

Or... If you're running the LM386 at 5V, it's output should be biased at about 2.5V so you just have to leave-out the output capacitor.

What's your audio source? The LM386 is a power amplifier (designed to take a line-level signal, or lower, and drive a speaker). (The gain may be too high.)

sorry for poor English, i found it dificault for understand ENGLISH.

why i have to leave-out output capacitor ??, i know that capacitor output is the pure Audio Signal without (DC vlotage) .

  1. By Using Audio Socket from Mobile without Amplifying and Using the mentioned circuit in Post, the output is Also biasing At 2.5v, after changing resistor connected to Ground to 68 ohm, it seems to be good, but now is the time to test it with my LM386 ,...

gilshultz:
Replace M1 with the Arduino and use a resistor divider to keep the voltage below 5 volts. This I found on eleccircuit web site.

thanks for help, what about using LM385 instead of CA3130 ??

why i have to leave-out output capacitor ??, i know that capacitor output is the pure Audio Signal without (DC vlotage).

Sorry about the confusion.

Right. The capacitor "blocks DC".

If you use the voltage divider (2-resistor) bias circuit it keeps the DC from getting changed when you connect the audio source. (That's not always a problem, since the audio source often already has a series capacitor.)

The "standard" LM386 circuit for driving a speaker already has a capacitor because the output is biased at about half the power supply voltage, and you don't want DC through the speaker.

But... That might be the bias you want so maybe you can leave out the capacitor and leave-out the bias circuit. But, the bias circuit with the capacitor (or with 2 capacitors) would still be OK.

but now is the time to test it with my LM386 ,..

What's feeding the LM386 amplifier? You said your phone is working OK without amplification. It probably has too much gain for your phone unless the volume is turned way-down. (I believe the minimum gain is 20, right?)

thanks for help, what about using LM385 instead of CA3130 ??

Not with that circuit.

That's a "different concept". It's a [u]peak detector[/u] with gain built around a regular op-amp. Almost any op-amp will work, but the LM386 isn't an op-amp.

A peak detector (AKA "envelope follower") puts-out a varying DC voltage that represents the peak input-voltage.

It's EASIER to make an audio meter with a peak detector as long as you want a peak meter. It's putting out a varying positive* DC voltage so you don't have to worry about biasing the audio and you don't have to read & "analyze" the waveform. And since you're not feeding a biased signal into the ADC, silence is actually zero, and you can use the optional 1.1V ADC reference for about 5X the sensitivity without gain/amplification (or you can use an external reference).

I make sound activated lighting effects and I always use a peak detector. And, I switch automatically between the 5V and 1.1V references depending on the signal level (as well as using a software threshold/reverence). ...You do loose the frequency information with a peak detector so you can't do any frequency analysis or make frequency-reactive lighting effects, etc.

I actually made a "VU meter effect" but since it has an automatic sensitivity adjustment it makes a lousy "meter". But, it does give lots of good "meter action" no matter how loud/quiet the music is!

  • The negative half of the waveform is ignored (with this particular simple-version of a peak detector) but the top & bottom halves of an audio signal are almost identical anyway and "close enough" for a meter.

DVDdoug:
But... That might be the bias you want so maybe[/i] you can leave out the capacitor and leave-out the bias circuit. But, the bias circuit with the capacitor (or with 2 capacitors) would still be OK.
[/quote]
very very thanks for help ,... The correct Biasing was Done in software not in hardware (amplifier circuit) ,.. really you are Genius ...
Used circuit is:
https://www3.0zz0.com/2020/02/29/14/243767459.jpg
i use LM386 because it is easier for me to change gain and voltage to be compatible for more than input.
but now there is another problem,.. there is noise come from the .01uF capacitor, how i reduce it to the minimum value ?? help me please.
very thanks in advance.

https://www3.0zz0.com/2020/02/29/14/243767459.jpg

You're not showing the connection to the Arduino so it's not clear what you're doing about the bias.

Do you actually have a speaker connected? What's the power supply voltage to the amplifier? It shows 4-12V and with more than 5V you can potentially damage the Arduino!

but now there is another problem,.. there is noise come from the .01uF capacitor, how i reduce it to the minimum value ?? help me please.

The capacitor won't generate noise. The audio signal and any noise from your audio source have to go through that capacitor before being amplified.

The 10uF capacitor boosts the gain and more gain boosts the signal and the noise.

It's not clear how much gain you need since you won't say what the audio source is...

How bad is the noise? If you have a speaker what does the noise sound like?

A little noise probably won't hurt the meter but if you are listening to the speaker that could be a problem.

If you're getting noise with the volume control all the way down the noise is probably coming from the power supply. You may need a "big" capacitor on the power supply and/or you may need a separately-regulated power supply for the audio.

If the noise is coming through the input (the volume control pot and capacitor) then the noise is coming from the sound source.

DVDdoug:
You're not showing the connection to the Arduino so it's not clear what you're doing about the bias.

first, thanks for help.

My Project:
https://www11.0zz0.com/2020/02/29/16/852441060.jpg

Audio Input comes From Sub:
https://www10.0zz0.com/2020/02/29/16/924015651.jpg
https://www10.0zz0.com/2020/02/29/16/688425131.jpg

Sub: runs on 9v Power Source , But with low Audio Level it is Safe i tested it on one LED by connecting LED directly to it's output and seems to be AC (no polarity).

i replaced the Speaker in the circuit by the (Audio Input)

i Use Power For Project From (5v pin) On Arduino, and also Power LM386 From (5v Pin) on Arduino , Power For Arduino Board Is USB

i use 22uF instead of 10uF for the circuit

i use your code, but after Edit:
https://www12.0zz0.com/2020/02/29/16/969531677.png

because abs() seems to be NOT work, it's result some times is (-ve).

finally when i Power the Project ((Analog)) value Ranges From 0 to about 545 (even there is NO source), but when randomly touch my project board specially the .01uF capacitor the value down to (44), when i restart ATMEGA Ic by software it comes back to 545 .. thats mean that there is noise,.. what is wrong with my Design ??

Some of your links are not working for me...

Audio Input comes From Sub:

...i replaced the Speaker in the circuit by the (Audio Input)

Just so I'm clear - The output from your phone or computer (or something) goes to the input to your powered subwoofer also goes to the input of the LM386, maybe with a Y-splitter? Right?

That should be a [u]line level[/u] (or headphone-level) signal of about 1V depending on the volume setting.

That's "about right" for the Arduino without any amplification, or you can use a little amplification.

Your LM386 has a gain of 200 !!! Of course, you're NOT going to get 200V out of your 5V circuit... You'll get badly distorted audio, clipped to 5V peak-to-peak or less.

i use 22uF instead of 10uF for the circuit

The capacitor value is OK, but a capacitor between pins 1 & 8 gives you a gain of 200!. (See the [u]LM-386 datasheet[/u].) Take-out that capacitor and you still have a gain of 20 which is still too much for a full-volume line-level signal!

Sub: runs on 9v Power Source , But with low Audio Level

That's not an issue as long as you're not connected to the amplifier-output (where the actual 4 or 8-Ohm speaker connects, probably inside the speaker cabinet).

it is Safe i tested it on one LED by connecting LED directly to it's output and seems to be AC (no polarity).

AC is NOT SAFE! The Arduino can be damaged by negative voltages, especially from a power amplifier capable of enough current to drive a speaker. That's the main reason for the bias circuit.

finally when i Power the Project ((Analog)) value Ranges From 0 to about 545 (even there is NO source)

The arduino input is probably "floating" (no DC current path). Something's wrong with your bias circuit. With the bias circuiit and no audio connection you should get a pretty-constant reading of around 512. It might jump around by one or two counts if it's on the "hairy edge' between two counts or it's picking-up a little noise.

DVDdoug:
Some of your links are not working for me...

https://www4.0zz0.com/2020/02/29/20/220415220.jpg

https://www4.0zz0.com/2020/02/29/20/144986809.jpg

DVDdoug:
AC is NOT SAFE!
[/quote]
I'am Suing Diode Between Arduino Pin And Groud (-ve) of diode connected to Ardino A5 Pin

I'am Suing Diode Between Arduino Pin And Groud (-ve) of diode connected to Ardino A5 Pin

Is that something new? A schematic would be helpful.

An over-voltage or reverse voltage protection circuit should have a series resistor so you don't "short out" the audio source. (I'd use a higher-value resistor of maybe 10K).

And you still need a DC current path to keep the input from floating. Add an even-higher value "pull down" resistor (100K - 1M) in parallel with the diode (between the analog input and ground).

With a reverse-voltage protection circuit you should NOT bias the input and you should read zero with no audio.

And with no bias you can use the optional 1.1V ADC reference. That will increase sensitivity without requiring amplification.

DVDdoug:
Is that something new? A schematic would be helpful.

Diode Only
https://d.top4top.io/p_15225cuuz1.jpg

Check Your Previous Response if there is any change you can do ..

Diode Only
https://d.top4top.io/p_15225cuuz1.jpg

OK... That will protect your Arduino from negative voltages but with no current limiting (no series resistor) you might burn-up the LM386.

...With a 4 or 8-Ohm speaker attached, you'll get a voltage drop across the resistor and depending on the resistor value you probably won't get enough signal. If you have a speaker that eliminates the need for the pull-down resistor, but the pull-down should have much-higher value than the series current-limiting resistor.

But like I said, the LM386 has too much gain. Leave it out!

This isn't that hard... You've been given 2 easy solutions - The normal bias circuit (2 equal value resistors and a capacitor) or the protection circuit (a series resistor, a diode*, and a higher-value parallel "pull down" resistor).

Your audio signal into the Arduino doesn't need to go all the way to 5V. You can adjust meter sensitivity in your software. The 10-bit ADC has about 5mV resolution with the default 5V reference (1023 "steps"). Or if you are using negative-protection instead of bias you can use the 1.1V reverence for about 1mV resolution. Or, you can use a different externally supplied reference. Or, you could use a pot for an adjustable reference to adjust the sensitivity or to "calibrate" your meter.

Or, you can make a peak detector with an op-amp (not the 386) which can optionally have some gain. But that's more complicated and for optimal performance it should be powered with positive & negative power supplies, the positive power supply voltage should be greater than +5V so it can go all the way to +5V (slightly over, actually) and it should have an over-voltage protection circuit (this time to protect from higher positive voltages).

I wouldn't recommend a peak detector until you get one of the easier solutions figured-out. :wink:

* Ideally, the diode should be a Schottky type if the series resistor is less than 5 or 10K. There are already "little" protection diodes (standard silicon diodes) inside the Atmel Atmega chip and those tiny internal diodes are only rated for 1mA. With a similar external diode you can't be sure where the current is going and there is a chance of damaging the one inside the chip (and possibly doing other damage).

A regular silicon diode has a forward voltage of about 0.6V and a Schottky diode has a forward voltage of about 0.2V so with a Schottky in parallel the internal diode will never "turn on" and all of the current will flow through the (higher-current rated) external Schottky diode.