Author Options:

measuring loudness Answered

I want to experiment measuring sound volume using a A2D converter and a microcontroller, but it is not as simple as i thought because i can't just measure once and use that spike should measure for a period of time and add up all of the amplitudes? or average it all out and use the difference from the average to 0?



11 years ago

Measuring the loudness of what? It would be simple to make a VU dB meter work with a microphone and an amplifier and a diode, It would also be simple to connect a digital AC meter to a speaker, but it will look like random numbers.

i just want a led bar graph move to the sound, since the A2D converter can take several readings very very fast, I can't just measure at one point, a voltmeter actually averages readings over a period of time how about this, i use a diode or a diode bridge and use the signal to charge a capacitor, and measure the voltage? has anybody seen that robot keepon? the little yellow thingy that can dance to beats? i just want a led bargraph to do the same thing, or a 8x8 matrix

You can use an LM3916. I prefer the LM3915 because it has more dynamic range than the LM3914 or LM3916 and always looks good with an amplified microphone. I have circuits for (any of) these chips, although you can search for the datasheet pdf (National Semiconductor made the chips). Typically they drive 10 LEDs from one signal, and can display as one dot or as a bar (more LEDs light up when it gets louder). I will try to find my schematic for the small version for parties. It does use capacitors and diodes to convert the audio to DC and to average it out, the best average is when you can see the single dot move when the dot/bargraph switch is set. The averaging time is set by a "time constant" network - just a resistor and a capacitor. The chips I mention can be connected together to make really long LED sound meters, which I've also done. It's simpler to make it look good as a bar than a dot, just try different capacitors on the input (and a high adjustable resistor) until it's not too fast and not too slow. I don't have a really cool equalizer circuit (many frequency bars) yet but one can be found in an old equalizer I guess. ALWAYS SAVE METERS FROM JUNK STEREOS! Otherwise I think a microcontroller programmed to do an FFT and drive part of a LED sign is needed. If anyone else knows other ways, say so. FFT is the most complex microcontroller DSP function I know of. You can fake the LM3916 with a microcontroller, just remember to put a capacitor between the audio and the ADC input, and put a volume control between the capacitor and the ADC input. Then make a lookup table of ADC volt measurements such as this in hex or binary 0 -> 00h 00000000b 1 -> 01h 00000001b 2 -> 03h 00000011b 3 -> 07h 00000111b 4 -> 0Fh 00001111b ...1F 3F 7F FF up to 8 (or how many bits) and then output to ports, see how higher numbers make more bits turn on more lights. BTW check out "Ruben's Tube"s on Youtube but don't try it at home!

Attempting to put up a schematic...


This functions as a voltage doubler and a time constant filter and a volume control. The bottom is ground, the left is audio-in, the output goes to LM3915 or the PIC ADC. Capacitor on the left is 1uF to 10uF, diode below it points to it, diode to the right points away, to the other capacitor which may be between 0.1 and 1 uF I guess, it depends on what volume control you use which can probably be any, perhaps between 5K and 1Meg (?). This is untested but similar to my typical method. Most important it converts audio to DC voltage per loudness, meaning zero volts when it's quiet, easy to measure. Cheaper than an op amp that may be otherwise used for this purpose. Not shown is whatever amplifier the audio is coming from.

You could use a microcontroller with an on-board ADC. (AVR ATmega48 or even an ATtiny26 have ADCs, and enough pins to drive an LED bargraph.) Just take an average of the incoming readings (say, 8, 16, 24, etc. readings), then set your bargraph accordingly. For a passive source like a mic, you might need an opamp or something to boost the audio signal. Don't average values if you're looking for peak readings.

you know those spy ear thingys that is just an amplified mic? think those will work?

Yeah--anything that can drive an earbud or earphone is amped enough for an ADC...

Just be mindful of the respective voltages. If the spy ear is 6V, and the microcontroller is 3.3v, you'd have too much amplification, and would need something like a voltage divider (just two resistors) to reduce the input. Or just use a POT wired as a voltage divider (and maybe a current limiting resistor on the ADC input pin.)

yea i have a few pic16f877a chips and voltage dividers are no problem for me, i also might have one to adjust the reference voltage. should i have the bars light up exponentially to the bits in the adc byte (as in checking from most to least significant, if the 5th bit is 1 then 3 leds on )? or actually divide the interger into 8 and light up leds evenly?

Ah-cool! I'm not too familiar with PICs, so I don't know about the resolution of their ADCs, etc.

I would start by creating a conversion factor-- for a 10 bit ADC and a 10 LED bargraph: 1024 values/10 LEDs in graph equals a divisor of about 102. So the input value/102 = highest LED to light.

Loudness is subjective, of course, and this is a linear conversion. If you need decibels (logarithmic), you'll need more complex math (or a lookup table.) With PICs, you might be stuck with assembly coding, which will make logs tougher...

Rereading your post, that's pretty much exactly what you said ;-). Using the bits only would be one non-linear approach--try both!

You would want to measure over a period of time. You would also need to take amplitude measurements over the frequency range.
It gets complicated, this is as far as I wanted to look into it: