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.

If you are interested in how this type of sensor can be integrated into a broader solution that includes notification of detected sound level on a users Android phone see Detect Intrusion with Passive Infrared, Sound, or Vibration

11 comments:

  1. Hello,

    Do you know the sensitivity of your sound level/microphone? I am trying to build an SPL monitor with a sensitivity of at least 1dB.

    Thanks!

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Hi Victoria, I haven't measured. However with this circuit in all applications I have done the highest sensitivity is too sensitive and needs to be reduced. Have fun.

      Delete
  2. I am looking to use something similar to your design in an industrial setting. there will a constant noise level and i am wanting to monitor excessive noise levels e.g a machine takes a knock. Would varying the potentiometer be able to account for the standard noise level?

    ReplyDelete
  3. Possibly. It would depend on the contrast between the ambient noise and the excessive noise levels you expect. In other words, there should be no problem adjusting the potentiometer so it doesn't trigger on regular ambient noise. The question is whether the interesting events you want to alert on are significantly louder to where they would trigger above this threshold. I recommend a quick prototype and test in the target environment.

    ReplyDelete
  4. This is really a wonderful blog for some great information. I have been searching for a long time for this types of content. Keep up posting more and thanks for your great staff.
    Battery Operated Ultrasonic Level Sensor

    ReplyDelete
  5. So many inportant information are available here also have some interesting things. Looking forward to find more topic.
    Level Sensor

    ReplyDelete
  6. Most of the time I don’t make comments on any post, but I'd like to say that this content is really helpful. Please share with us more post like this.
    Ultrasonic Level Sensor

    ReplyDelete
  7. Hi,

    I have a project involving triangulation by tdoa of sound which requires use of 3 equaly calibrated microphones. I have used the sparkfun sound sensor board
    https://www.sparkfun.com/products/12642, but have found that they are firstly overpriced and difficult to calibrate. By replacing R17 with a trimpot, i came quite close to same calibration for 3 boards hooked up to a Teensy 3.5 Digital Inputs 10,11 and 12.

    I require a circuit which firstly has an opamp (LM358), bandpass filter 300hz-3Khz and an adjustable trimpot for gain and calibration. Output Digital High/Low signal to the Teensy 3.5 for use with interrupts.

    I have built the circuit as you have designed and found that it is easy to build and fits the specification above except for the bandpass filter. Would you be so kind as to guide me in the right direction in adding a bandpassfilter?

    ReplyDelete