SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By reklipz
#17177
A friend of mine challenged me to design something he could put on his car dash that would display the current level of volume in his car via some led meter (leds lined up next to eachother, and the more LED's, the louder the noise)

I have a microphone, and some LED's, and a PIC.

How would I use the microphone to detect the level of volume with the PIC?

Any ideas?
By busonerd
#17178
add an op-amp and a few r's + c's + a diode and I can tell ya how. Just amplify the signal [1 op amp], envelope detect it [diode, resistor and capacitor], Throw it through a low pass filter, and feed that into one of the A/D inputs of your pic.

--David Carne
By reklipz
#17179
hmmm...

can you explain the envelope detect, and how to construct the low pass?

I'm not just trying to bum this off of you, I'm willing to take a lesson if you're willing...
By reklipz
#17181
Ive got a BA546 Audio Power Amp IC

an OP Amp IC (BA10324 (theres 4 of them))

lots of diodes and caps

but this low pass filter, im lost on
Last edited by reklipz on Sun Aug 13, 2006 3:12 pm, edited 1 time in total.
By reklipz
#17186
Image

will that work for the low pass?

and the wiki says it uses this formula:
Image

what frequency should i set it for?
By reklipz
#17187
Code: Select all
     +--------------------------------+
     |                                |
     |            |\                  | |\
     |            |  \   1N4148       | |  \      to A/D
     | [---]------|+ O \--|>|--+      +-|+ O \--+--------
     | [MIC]    +-|- P /       +--/\/\--|- P /  |
     | [---]-+  | |  /    10K  |   1K   |  /    |
     |       |  | |/   +-/\/\--+        |/      |
     |       |  |      |       |   1K           |
     |       |  |      | 100pF +--/\/\----------+
     |       |  |      +--||---+         .01µF  |
 GND |       |  |      |       +-----------||---+
-----+-------+--+------+
Theres what I came up with..

Not sure if that's right or not...

the values for the detect envelope were off some example i saw online

the values for the C and R2 of the low pass were calculated for about 15,900Hz cutoff, and the R1 (which the wiki says gain = -R2/R1), so i just picked another 1K ohm resistor...

sorry for the crappy ASCII art!

let me know if this is right or not!
By riden
#17194
The lowpass filter feeding an ADC input of a PIC which then drives the LEDs will work. However, the LM3915 or LM3916 was designed for this exact purpose. Connect the output of your microphone amplifier to the input of the LM3916 and you're set. And no current limiting resistors for the LEDs are needed. The chip is about $2.
By busonerd
#17199
Hmm... I would also buffer the signal between the env det + the lpf.

The output of the LPF will probably feed back into the env det and mess it up.

But yeah, riden's solution is much simpler, but I was trying to think of one that used a pic and standard bits. If you can source his parts, use them.

Actually, just drop the LPF and replace it with a buffer. An LPF at a low enough frequency to make a difference would be huge anyways.

Cheers,

--David Carne
By reklipz
#17224
So how would I do this with the PIC? (I may try the LM3916 later)

Was that circuit correct?

How would I put the Buffer in there? (wtf is it to begin with)?
By busonerd
#17236
A buffer is just an amplifier with unity gain. [aka, it doesn't amplify].

Basically, drop the low pass filter, and replace it with a buffer.

--David Carne
By reklipz
#17242
So heres my new circuit:
Code: Select all
           |\                    |\
           |  \   1N4148         |  \      to A/D
[---]------|+ O \--|>|--+--------|+ O \--+--------
[MIC]    +-|- P /       |      +-|- P /  |
[---]-+  | |  /    10K  |      | |  /    |
      |  | |/   +-/\/\--+      | |/      |
      |  |      |       |      |         |
      |  |      | 100pF |      +---------+
      |  |      +--||---+
  GND |  |      |
 -----+--+------+
Correct?

how do i know what the voltage levels for this are (how would i setup the A/D converter? never used it before, but I understand how it works / what it does and resolution and that jazz).
By Kuroi Kenjin
#17281
Depending on your PIC... basically just set the ADCONx registers (usually 0 and 1) with it's clock speed (internal RC is simplest), the analog pins, data justification/padding ( XX X0 or 0X XX), and the channel you're using. Then run a reading to initialize the sample/hold circuit and then your next reads will populate the ADRESH/L registers with good data. Once you get the hang of it, it's really easy to use.
By awright
#17632
Bear in mind that virtually all sound level meters or "audio level meters" use RMS (Root Mean Square) signal detection of signal amplitude. The reason is that for complex waveforms with harmonically and non-harmonically related components and random noise, RMS detection indicates the actual energy content of the signal, independent of the "crest factor" (ratio between peak voltage and RMS voltage) and independent of the phase relationship between various harmonics (which affects the crest factor). Crest factor can vary from 1.4 for sine waves to five or ten or even more for music with strong impulsive components like drums.

Peak detection can be wildly off the true energy content of the signal based upon the magnitude of the peaks of the signal. The peak detected voltage is related to the energy content of the signal ONLY for DC or for a sine wave. For any other waveform, the energy content (which is, along with other parameters, directly related to the subjective loudness), cannot be predicted from a peak detected signal unless you know the exact waveform and have calculated or measured the relationship, and this is, of course, impossible in continusouly varying music.

In the olden days, it was difficult to get true RMS detection without elaborate circuits and devices. Bruel & Kjaer for many decades used a biased resistor-capacitor network in their sound level meters, calling it a "quasi-RMS detector," and it worked quite well for the limited range of the analog meter it was driving (perhaps 20 dB).

Fortunately, modern ICs make very accurate, wide dynamic range true RMS detection easy and cheap. See Analog Devices' AD 536 (I think) and its offshoots. Google "true RMS detection," to see the cheap and very good ICs available.

If you don't use RMS detection in an analog meter, your'e just kidding yourself.

awright
Acoustical Consultant