Shop OBEX P1 Docs P2 Docs Learn Events
Microphone circuit — Parallax Forums

Microphone circuit

bomberbomber Posts: 297
edited 2011-06-09 07:39 in Accessories
I am curious if anyon has a circuit (and code) that can hook this microphone to a BS2?

Comments

  • LeonLeon Posts: 7,620
    edited 2011-06-07 12:08
    What do you want to do with it?
  • bomberbomber Posts: 297
    edited 2011-06-07 12:11
    I want to (using Stamp Plot Lite) graph the (ambient) sound level in a room. I might also use it to upgrade my light show.
  • LeonLeon Posts: 7,620
    edited 2011-06-07 12:18
    I've interfaced a similar microphone to an ADC input on a dsPIC, using a single BJT amplifier biased at half the supply voltage. You are welcome to that circuit, but I don't think that the BS2 is suitable for your application without an ADC.
  • ZootZoot Posts: 2,227
    edited 2011-06-07 13:56
    Here's a circuit that hooks a two-pin electret mic up to an ADC for sampling by a Stamp or other micro. JonnyMac came up with this some years ago.

    Ignore the part of the schematic up top for the SX portion (power supply, programming interface, sx). The part you want is the bottom half that shows the pre-conditioning of the mic signal, the op amp, and the ADC. You can read the ADC values which will correspond more-or-less to audio volume.
  • ZootZoot Posts: 2,227
    edited 2011-06-07 14:00
    P.S. -- remember that these kind of mics are kind of like open-drain circuits. The mic has a ground pin and an output pin. The output pin must be pulled high with a resistor to Vdd. When the mic reacts to sound, it drives the output pin low.
  • bomberbomber Posts: 297
    edited 2011-06-07 14:40
    Thank you zoot!! As far as reading the ADC, do you think the code from Stampworks will wok?
  • ZootZoot Posts: 2,227
    edited 2011-06-07 15:22
    What code is that? Post it. The ADC doesn't have to be the one in that circuit (which is going end of life anyway, as far as I know). Any ADC will do, pretty much, and most external ADCs either use SPI or I2C so the Stamp would be able to do it.
  • bomberbomber Posts: 297
    edited 2011-06-07 16:01
    The pertictular ADC was the one shipped in the Stampworks kit. As far as code...(see attatchment).
  • ZootZoot Posts: 2,227
    edited 2011-06-07 17:21
    Yes, the basic routines for reading the ADC there should work.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-07 17:42
    Be aware that the ADC will return the instantaneous amplitude of the audio waveform. You will need to take many readings, keep track of the maximum and minimum readings, and then subtract min from max to get the maximum sound level during the period. Still, however, the BS2 will not be able to sample fast enough (i.e. at the Nyquist rate) using this technique, so your results could well be misleading.

    -Phil
  • ZootZoot Posts: 2,227
    edited 2011-06-07 19:52
    Hence the SX in the original circuit for doing the consistent (and fast) sampling. But if bomber wants to get a more or less "ambient" sound level, wouldn't taking a group of successive samplings and then either averaging them (perhaps tossing out the min and max readings as spurious) or doing a simple (slow) Nyquist probably be OK? Practically speaking, anyway, not formally.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-07 19:59
    No, it probably wouldn't work very well. Besides, averaging an AC wave would only yield the zero (quiescent) level. You'd have to average the mean-square deviation from the zero level to obtain anything useful. The best solution might be to introduce an analog integrating peak detector ahead of the ADC.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-07 20:24
    The circuit would be arranged so that the AC would be riding on a positive DC bias. But the average reading would equal that DC bias, since there would be as many excursions below the bias level as above. What you want is the RMS reading, not the average.

    -Phil
  • bomberbomber Posts: 297
    edited 2011-06-08 14:26
    I think that at the moment, the most important matter would be to get the circuit working!!! I built the circuit, loaded the program, and looked at the Debug screen. I saw a voltage of about 2.5VDC. I made a lot of sound, and watched the Debug screen the reading was 2.5VDC (the reading was actually ocilating between 2.5VDC and 2.4VDC, but when I (and the ambient noise) were completely quiet, the reading kept ocilating between 2.5VDC and 2.4VDC). I turned the Potentiometer and nothing happened.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-08 22:22
    Here's a circuit you can use to interface the microphone to your ADC:

    attachment.php?attachmentid=81985&d=1307596772

    The first stage is a x100 amplifier to boost the feeble microphone output to something useable. (The LM358 uses a single +5V supply here.) The second stage is a peak detector to sample and hold the high excursions of the audio waveform long enough that they can be measured.

    Here's a scope trace showing the input to the peak detector (blue) and the output (yellow):

    attachment.php?attachmentid=81986&d=1307597234

    Some things to tinker with:

    1. If you need to measure higher ambient levels than what this circuit accommodates, lower the value of the 1M feedback resistor.

    2. There's no bleeder resistor on the 0.1uF output cap. Leakage seems to provide enough of a bleed route that one was not necessary. By the same token, however, if your ADC has a low input impedance, the cap will bleed too quickly. You can substitute a larger cap or use an additional op-amp unity-gain buffer stage after the cap. In this case, you'd want to use a quad op-amp, like the LM324.

    -Phil
    580 x 234 - 3K
    640 x 480 - 15K
  • bomberbomber Posts: 297
    edited 2011-06-09 07:39
    Thank you Phil (and others) for their ideas. I will report back when I get the chance to test this out.
Sign In or Register to comment.