Sound Detector Module

The majority of microphone modules available for the Arduino have one thing in common - they are sound detectors. They detect when sound is present, but are incapable of measuring the intensity of the sound or of keeping up with whatever frequency they might "hear".

What does it do?

The microphone picks up sound and converts it to an electric signal. The signal is amplified by a transistor and then fed into a comparator. If the sound level is over the comparator's adjustable threshold, the output signal goes high. On the board is an LED for power and one for signal. The signal LED is normally on, but goes off when a sound is detected.

Connection

The sound detector module requires +5V, ground, and one digital input. We use another digital pin as an output so we can see the result on an LED. This duplicates the LED on the sound detector module, but shows that we are actually getting the signal into the Arduino and processing it.

The sound detector module is used like many modules - we read the input and put it on an output:


void setup() {

  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
}

void loop() {

  digitalWrite(3, digitalRead(2));
}
    

The program writes to the LED anything it reads from the sensor. When the sensor detects an object the output goes high. The program puts that high on the anode of the LED, lighting it. If you were using this device for a "clap switch", you would turn on a relay that turns on a light, or similar activity. A time lock prevents multiple firings in rapid succession, which is typically what you get with these modules. The few second wait allows the sound to settle down before it starts listening again.


int lampOn;

void setup() {

  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  lampOn = 0;
}

void loop() {

  if (digitalRead(2))
  {
    if (lampOn)
    {
      // Turn the lamp off.
      digitalWrite(LAMP_PIN, LOW);
      lampOn = 0;
    }
    else
    {
      // Turn the lamp on.
      digitalWrite(LAMP_PIN, LOW);
      lampOn = 1;
    }
    delay(2000);
  }
}
    

In this way we can control the relay without worrying about false triggers during activation. You still have to set the sensitivity of the module to trigger at the correct sound level. You do that by trial and error, adjusting the pot on the module and checking the sensitivity.

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.