Electret Mic output problem

Quaffable

New Member
Hello all.

I have a pet project I have been working on (mostly off) for a while now.

I have heard that students will self-regulate noise levels if they can see a display of sound levels - a 'noise traffic light'.

I have an electret microphone amplified by a 741 op-amp being read by the adc pin of a picaxe 14m chip. The outputs are three bulbs - red, yellow and green. So far so good. The code for analogue sensor reading from manual 3 works to a point and proves the system works.

As you might imagine, the lights react to sound, but too briefly to be of use in my project. I would like them to remain on - hold at peak level - for a time, but the code must continue to run in the background to check for higher levels.

Using 'pause' is too crude and holds regardless of changes in volume.

Please point me in the right direction, hardware or software, or stop me now if I'm on the wrong track. Thank you.
 

Quaffable

New Member
thank you so much - this is much better, and starting to work as I hoped.:)
I need to play with those timings and adc variables now.
 

BeanieBots

Moderator
You could use a hardware solution. Simply increase the capacitance value in your detector circuit.

I assume you read the adc and then compare to some reference value to determine if/when the LED(s) come on.
Read the adc and store in a temporary variable only if it's greater than the value already there.
Compare the temporary value to reference and switch the LED(s) accordingly.
Then decrease the temporary value by 1 and repeat the loop.
Experiment with small pauses in the loop.
 

inglewoodpete

Senior Member
Or you could use software timers. Something like (untested):
Code:
'Registers
Symbol SoundLevel = b4
Symbol RedTimer = b5
Symbol AmberTimer = b6
'
'I/O assignments
Symbol SoundPin = 1
Symbol RedLamp = 0
Symbol AmberLamp = 2
Symbol GreenLamp = 4
'
'Constants
Symbol OnPeriod = 150         'Number of loops
'
   Do
      ReadADC SoundPin, SoundLevel
      Select Case SoundLevel
      Case < 50                '    Good: green
         'GreenTimer = OnPeriod
         High GreenLamp
         '
      Case < 150               ' Warning: amber
         AmberTimer = OnPeriod
         High AmberLamp
         Low GreenLamp         'Extinguish lower levels
         '
      Else                     'Too loud: red
         RedTimer = OnPeriod
         High RedLamp
         Low AmberLamp         'Extinguish lower levels
         Low GreenLamp         'Extinguish lower levels
      End Select
      '
      If AmberTimer > 0 Then   
         Dec AmberTimer        'count down
      Else
         Low AmberLamp         'Timer has expired
      EndIf
      If RedTimer > 0 Then   
         Dec RedTimer          'count down
      Else
         Low RedLamp           'Timer has expired
      EndIf
      Pause 10                 'May need to change this value
   Loop
 
Top