Shop OBEX P1 Docs P2 Docs Learn Events
HELP!!! Sound Level Meter — Parallax Forums

HELP!!! Sound Level Meter

picky200picky200 Posts: 2
edited 2007-03-14 21:15 in BASIC Stamp
Hello. I'm attempting to build a project in which a traffic light changes colors based on the sound around it. It is for a classroom environment to help deal with·noise management. When there is a lot of noise the light will turn red, with medium amounts of noise it will turn yellow, and with·ideal noise, it will be green. I have attempted connecting·a kit·microphone circuit, called the·super snooper microphone,to an A-D converter to a basic stamp. The microphone is working, but the results I'm getting from the A-D converter are too broad and fluctuate randomly. The microphone has to be able to capture ambient noise from the room in order to work successfully. Has anyone tried anything like this? I'm open to new suggestions as well!

Here's what my code looks like so far:
' {$STAMP BS2}
' {$PBASIC 2.5}

'
[noparse][[/noparse] I/O Definitions ]
Adc0831········ PIN 15················· ' ADC0831 Chip Select (ADC0831.1)
AdcClock······· PIN 14···················· ' ADC0831 Clock (ADC0831.7)
AdcData········ PIN 13·················· ' ADC0831 Data (ADC0831.6)
'
[noparse][[/noparse] Variables ]
result········· VAR···· Word
'
[noparse][[/noparse] Initialization ]
HIGH Adc0831
'
[noparse][[/noparse] Program Code ]
HIGH 10
PAUSE 1000
LOW 10
Read_GP2D12:
··· LOW Adc0831
··· SHIFTIN AdcData, AdcClock, MSBPOST, [noparse][[/noparse]result\9]
··· HIGH Adc0831
· DEBUG· HOME, CLS, ? result
· SEROUT 1, 84, [noparse][[/noparse]12,129, DEC RESULT]
· IF RESULT >160 AND RESULT<170 THEN HIGH 11
· IF RESULT<160 THEN HIGH 10
· IF RESULT >170 THEN HIGH 12
· PAUSE 100
··· LOW 11
··· LOW 12
··· LOW 10
· GOTO Read_GP2D12

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-03-02 21:36
    I believe this sort of thing is usually done with an op-amp, set up as an 'integrator', so you get the average sum of sound over a period of time.

    Does anyone have an example they can post for this person?
  • rixterrixter Posts: 95
    edited 2007-03-03 00:55
    What do you mean by "too broad"? It looks like you are on the right track getting a value in RESULT that you are using to determine which light should be lit for that particular noise level. I would figure that you are getting peaks, dips or other noise readings that are making your code prematurely select the improper light. You should be able to tweak the code to solve this if in fact the microphone circuit can return usable values in RESULT. For instance, you could jump to a subroutine based on each of your initial RESULT readings that continues checking (obtaining a mic reading) and deciding whether a light change is warranted. In other words, your program would be looking at two issues.... the range level of noise initially and the length of time or frequency that the mic is reading that noise in your subroutines. One student screaming out for a second may not warrant a red light, but singing out loud would presumably. So your subroutine code jumped to for each initial reading could "poll" the mic a certain number of additional times to see if the noise level initially read is persistent. A loop of 10 readings where the readings were in the red light range a count of 5 times or more for instance would be deemed persistent loud noise. Otherwise you drop back to your original code that cycles mic readings again.

    I would think that you might be able to accomplish this via a microphone/transistor circuit tied into a RCTIME circuit.. varying your capacitor to get the response fine tuned.

    Good luck!

    Rick
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-03 02:20
    Here is a circuit diagram of an op amp integrator:
    http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/opampvar4.html

    The charge is integrated onto the capacitor, R1 determines how quickly the charge will build on the capacitor in the presence of a signal. R2 determines how quickly the charge will dissipate when the signal tapers off.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-03 04:25
    You will probably want to precondition your AC audio input before applying it to an integrator. Otherwise, the positive and negative voltage swings will pretty much cancel, and the integrator output will hover near zero. This can be done in three ways:

    1. DC restoration: This can be as simple as a large series cap connected to the integrator's input resistor, followed by a diode with its anode end grounded, as seen here. This circuit will shift your input level upward, keeping the bottoms near ground and the tops near the peak-to-peak level of your input signal.

    2. Clipping: Same as the DC restorer, but replacing the cap with a resistor. The negative swings will get clipped off by the diode, and the integrator will see only positive pulses equal to one-half the input signals' peak-to-peak voltage swing.

    3. Rectification: By swapping the cap and diode in the DC restorer circuit, you form a half-wave rectifier. This will pass only the positive swings and filter them. The DC voltage level on the cap will roughly equal one-half the peak-to-peak voltage of your input signal. You may not even need the integrator after rectification if the cap is big enough.

    -Phil
  • picky200picky200 Posts: 2
    edited 2007-03-14 20:11
    Sorry for the delay, I've been out of town for a while and I really appreciate your comments. To Paul, I don't knwo that much about op amps, but I have a couple common ones. Would a 741 or 386 work?
    To Phil, I'm not familiar with the circuits you mentioned. Is it possible for you to provide a link to a scematic with specific parts?
    Thank you everybody for your help and I'm really looking forward to finishing the project.
  • ZootZoot Posts: 2,227
    edited 2007-03-14 21:15
    Here is a link to a forum member who posted a nice schematic for a sound sensor using an ADC and a 741 op amp. Since you already have your ADC and you mentioned using a 741 this should be right up your alley.

    His circuit is a two-channel sensor (stereo) -- obviously you only need one channel so I'm thinking you may already have your parts on hand.

    I will also echo rixter's suggestion that you also accommodate the "real world" in your code. It may be as simple as a counter -- if the sound level is in "zone 2" for 5 samples or more, declare it "really at zone 2"; etc. This will help throw away any "spikes" you see in your data due to someone coughing, dropping a book, whatever. You could also consider averaging the samples over time in your code, which will help get you closer to "ambient" levels, rather than one-shot levels.

    http://forums.parallax.com/showthread.php?p=572182

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    Post Edited (Zoot) : 3/14/2007 9:39:08 PM GMT
Sign In or Register to comment.