Get volume of music (not from speaker)

Hello all! :slightly_smiling_face:

Is there a way to detect the volume of music from the line (not a microphone)?
Simply putting the wires on GND and an analog pin wouldn't work.

I don't need an exact measurement in standard units, just one that increases as the volume increases.
I would also like to have my Arduino not be fried when the volume is too high :wink: (use a transistor?)

I know I'm a newbie and probably am missing something obvious.

I really appreciate any help you can provide.
@anon44338819

Do you think it might be important to tell us what your "line" is?

you can measure the amplitude the same way you measure the amplitude with ADC and analogRead. You will need a capacitor and another capacitor a resistor and a diode.

Wiring diagram?

you first

:face_with_raised_eyebrow: :face_with_raised_eyebrow: :face_with_raised_eyebrow:

Loudness is a function of frequency, since it is a hearing function. Also logarithmic.

Really, all the old VU meters were wired into the preamp/driver section which typically is like 1V-PP if I recall. You can easily change the Arduino AD to use the lower bandgap reference and then simply use an RC network with a diode to get a DC varying voltage.

Something like these as starters:

VU Meter for Audio Signal (dBu) using LCD - Arduino Project Hub

or

OLED display audio VU meter - AVR/Arduino project - Electronics-Lab.com

true, what are we talking around 1khz? the middle would appear the loudest I guess. Can find a capacitor value to cut off bass

@anon44338819

Any code and circuit diagrams easy for me (a newbie) to understand?

You still need to define what you want to do. So far, just words with no details.

There are a few solutions...

The Arduino can handle zero to +5V. It can be damaged by negative voltages or voltages over 5V so the main thing is to protect it from the negative half of the AC audio signal. With higher-power speaker signals you have to also protect it from excess positive voltages.

I normally use an op-amp peak detector. I use positive & negative power supplies so it can go all the way down to zero and I normally use + & - 12V so I can go all the way to 5V, and then I add an over-voltage protection circuit. (A resistor and diode.)

A peak detector puts-out a varying DC voltage and it holds the peaks and then decays depending on the RC time constant so it's straightforward to read it and depending on what you're doing you can read it 10 times per second (or so) instead of reading the waveform thousands of times per second. That frees-up the processor to do other things.

But there are simpler alternatives. The "standard solution" is a bias circuit that adds 2.5V to the signal (on the Arduino side) so silence reads about 512 on the ADC, and the audio creates readings above and below that. If you wish, you can subtract-out the bias in software to get the negative & positive values.

Audio Input Schematic

Or you can use a negative voltage protection circuit:
Audio input 2

Note that with either of these the raw readings will "look random" because you are sampling an AC waveform. So, you'll have to find the peaks or the average. With the bias circuit the average is always about 2.5V so you'll have to find the average of the absolute values. Or you can "get fancy" and calculate RMS. With the protection circuit half of the readings (all of the negative readings) will be zero.

The protection circuit has a potential advantage that you can use the optional 1.1V ADC reference to increase sensitivity. That can be helpful, especially if your line-level signal is volume-controlled. You can do the same thing with a peak detector. But with the bias circuit at 2.5V you obviously can't use the 1.1V reference.

...I make sound activated lighting effects and my code switches automatically between the two ADC references depending on the signal level.

My World's Simplest Lighting Effect uses the standard biased input. The bias is subtracted and it finds a peak every 50ms.

Great post. Also there have been almost identical questions in previous threads. So a forum search can produce more details and ideas.

All I need is a number that raises as volume is higher and lowers as volume is lower

The the voltage level will do that. But that is not how "volume" or loudness is measured. That is measured in deciBells or DB. 3DB is twice as loud as before.

How about this

No software except to read the analogue pin the output is connected to.
Note your audio voltage needs to be over 0.7V before it will register anything.

Thanks! I will look into this (and test it)
How do I find the values of the capacitor and the resistor?
And how do I prevent blowing my pin with too much voltage?

@anon44338819

Experiment, the capacitor will control how quickly the numbers respond to a peak, the smaller the sooner. The resistor controls how long the decay is after the peak is reached, the smaller the sooner.

Start off with 10 uF and 10K and go from there.

You would need a 10 volt peak to peak audio signal to exceed the capacity of the analogue input voltage ( assuming a 5V operating Arduino ) you will be hard pressed to get one of those that big.

Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.