Monday, February 17, 2014

High Sensitivity Arduino Sound Level Detector

Generally we want to sense the environment when something interesting is occurring. Sometimes the presence of sound is indicative of an interesting activity. If we can detect sound level we can trigger a sensing activity to capture information about the activity of interest. I have posted a short video of this simple high sensitivity Arduino sound level detector working.

In this project we use an Arduino Uno, an electret microphone and an LM358 dual operational amplifier to create a simple sound level detector. The signal from the mic is amplified by the one side of the LM358 with a gain of approximately 221 (see op-amp wiki) as defined by the 220k feedback resistor and the 1k pull down resistor connected to the negative input of the LM258 amplifier. The output of the first stage amplifier provides input to the other side of the LM358 used as a comparator. The triggering threshold of the comparator is controlled using the potentiometer. When the audio signal from the first amp exceeds the triggering threshold the comparator sends a digital '1' to the Arduino Uno on pin 8. When the Uno detects the sound level high input it turns an LED on. You can see a schematic diagram of the sound detection part of the circuit below.

Prototyping this on a breadboard looks something like this:

The actual breadboard prototype appears below:

... and the simple sketch I used to drive the Arduino Uno appears below:

I include the sketch code below if you'd like to try it out yourself:

#define SOUND_DETECTED_DIGITAL_IN_PIN 8
#define LED_DIGITAL_OUT_PIN 7

void setup(){
  pinMode(SOUND_DETECTED_DIGITAL_IN_PIN, INPUT);
  pinMode(LED_DIGITAL_OUT_PIN, OUTPUT);
}

void loop(){
  if(digitalRead(SOUND_DETECTED_DIGITAL_IN_PIN) == HIGH){
    digitalWrite(LED_DIGITAL_OUT_PIN, HIGH);
    delay(50); // delay long enough for you to see the LED on
  }
  else {
    digitalWrite(LED_DIGITAL_OUT_PIN, LOW);
  }
}

Stay tuned for projects that receive the sound detection as input and use it to drive other interesting activities. Have fun. Feel free to share below if you built something cool with this, or have some ideas for enhancements.

You may also be interested in a high sensitivity vibration sensor using the Arduino Uno.

Note: if you notice your output locking in on state try lowering the feedback resistor of the op-amp from 220k to something lower, for example 160k.

No comments:

Post a Comment