Try Embedded

Sound level meter

Read the small and big microphone modules side by side and react to loud sounds.

Sensors · Beginner

In a real product: Noise monitor (Smart home): Detects loud sounds, as a baby monitor does.

Sound sensor modules have a microphone, an amplifier and a comparator. The analog output follows the sound level; the digital output goes HIGH when it is louder than a threshold, handy for clap switches. This project reads both kinds of module.

What you'll learn

  • Reading two sensors of the same kind on different pins
  • Analog level versus digital threshold outputs
  • Making a clap-activated light

How it works

The small module's AOUT and DOUT go to A0 and pin 2; the big module's to A1 and pin 3. AOUT rises with the sound level. DOUT is HIGH while the sound is louder than the module's threshold.

Every 300 ms the loop prints both levels. Whenever either module hears something loud, the built-in LED lights.

Try this

  • Raise the sensors' level sliders while it runs.
  • Toggle the LED on each clap instead of lighting it only while loud.
  • Detect a double clap: two loud sounds less than half a second apart.

sketch.ino

// Two sound sensor modules: small (AOUT A0, DOUT 2) and big (AOUT A1, DOUT 3). DOUT is HIGH when loud.
const int SMALL_ANALOG = A0, SMALL_DIGITAL = 2;
const int BIG_ANALOG = A1, BIG_DIGITAL = 3;

void setup() {
  pinMode(SMALL_DIGITAL, INPUT);
  pinMode(BIG_DIGITAL, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int small = analogRead(SMALL_ANALOG), big = analogRead(BIG_ANALOG);
  bool loud = digitalRead(SMALL_DIGITAL) == HIGH || digitalRead(BIG_DIGITAL) == HIGH;

  Serial.print("Small mic: ");
  Serial.print(small);
  Serial.print("  Big mic: ");
  Serial.print(big);
  Serial.println(loud ? "  LOUD!" : "");
  digitalWrite(LED_BUILTIN, loud);
  delay(300);
}

Lessons behind it