Microphone Sound Sensor · Astro Tech Blog

Microphone Sound Sensor

The microphone sound sensor module (KY-038 / HW-483) detects ambient sound levels using an electret microphone and an LM393 comparator. It provides both an analog output (raw sound waveform envelope) and a digital output (triggered when sound exceeds an adjustable threshold), making it useful for clap switches, voice-activated projects, and sound level monitoring.

Microphone Sound Sensor module

For this interfacing you need the following components:

  • Arduino board (Uno, Nano, Mega, etc.)
  • Microphone sound sensor module (KY-038, HW-483, or similar)
  • Breadboard and jumper wires
  • USB cable to connect Arduino to your computer

Schematic

Connect the sound sensor module to the Arduino as follows:

Sound Sensor          Arduino
------------          -------
VCC           -->     5V (or 3.3V)
GND           -->     GND
DO            -->     Digital Pin 2
AO            -->     Analog Pin A0

No external components are required. The module works at both 3.3V and 5V.

Pin Map

PinNameConnection
VCCPower5V or 3.3V
GNDGroundGND
DODigital OutputAny digital pin (pin 2 used)
AOAnalog OutputAny analog pin (A0 used)

Some modules label AO as A0 and DO as D0. The module has a potentiometer to adjust the sound threshold for the digital output.

Install necessary Library

No external library is required. Sound detection uses standard digitalRead() and analogRead() functions built into Arduino.

Code with complete explanation

This sketch reads both the digital (sound threshold exceeded) and analog (sound intensity) outputs, printing the values to the Serial Monitor.

const int digitalPin = 2; // DO pin
const int analogPin  = A0; // AO pin

void setup()
{
  Serial.begin(9600);
  pinMode(digitalPin, INPUT);
}

void loop()
{
  int digitalValue = digitalRead(digitalPin); // HIGH = sound detected above threshold
  int analogValue  = analogRead(analogPin);   // 0-1023 (higher = louder)

  Serial.print("Digital: ");
  Serial.print(digitalValue);
  Serial.print(" (");

  if (digitalValue == HIGH)
  {
    Serial.print("LOUD");
  }
  else
  {
    Serial.print("Quiet");
  }

  Serial.print(")  Analog: ");
  Serial.print(analogValue);

  // Interpret analog level
  Serial.print(" (");
  if (analogValue < 50)
  {
    Serial.print("Silent");
  }
  else if (analogValue < 200)
  {
    Serial.print("Quiet");
  }
  else if (analogValue < 400)
  {
    Serial.print("Moderate");
  }
  else if (analogValue < 600)
  {
    Serial.print("Loud");
  }
  else
  {
    Serial.print("Very loud");
  }

  Serial.println(")");
  delay(100);
}

Code breakdown

  • digitalRead(digitalPin) — reads the DO pin. The LM393 comparator drives this pin HIGH when the sound level exceeds the threshold set by the module’s potentiometer.
  • analogRead(analogPin) — reads the AO pin (0-1023). Higher values correspond to louder sound. The analog output is the envelope of the sound waveform, not the raw audio signal.
  • The threshold levels in the analog interpretation are approximate and depend on the module’s gain setting and the ambient noise floor. Adjust based on your environment.

Clap switch example

This example toggles an LED when the sound sensor detects two successive claps within 1.5 seconds:

const int digitalPin = 2;
const int ledPin = 13;

int lastState = LOW;
unsigned long lastClapTime = 0;
int clapCount = 0;

void setup()
{
  pinMode(digitalPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
}

void loop()
{
  int currentState = digitalRead(digitalPin);

  // Detect rising edge (sound starts)
  if (currentState == HIGH && lastState == LOW)
  {
    unsigned long now = millis();

    if (now - lastClapTime < 1500)
    {
      clapCount++;
    }
    else
    {
      clapCount = 1;
    }

    lastClapTime = now;

    if (clapCount >= 2)
    {
      digitalWrite(ledPin, !digitalRead(ledPin)); // toggle LED
      clapCount = 0;
    }
  }

  lastState = currentState;
}

Sound level meter (bar graph)

To visualize sound level using the Serial Plotter:

const int analogPin = A0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int value = analogRead(analogPin);
  Serial.println(value);
  delay(50);
}

Open Tools > Serial Plotter to see the sound waveform in real time.

Steps to perform this interfacing

  1. Connect the sound sensor module to the Arduino as shown in the schematic.
  2. Copy the code into the Arduino IDE.
  3. Adjust the potentiometer on the module to set the digital threshold:
    • Turn clockwise to make it less sensitive (louder sound needed to trigger).
    • Turn counter-clockwise to make it more sensitive (quieter sound triggers).
  4. Select the correct board and port (Tools > Board and Tools > Port).
  5. Upload the sketch to the Arduino.
  6. Open the Serial Monitor (Tools > Serial Monitor, set baud rate to 9600).
  7. Make a sound (clap, snap, or speak) and observe the readings change.
  8. Fine-tune the potentiometer until the digital output triggers at your desired sound level.

Caution

  • The analog output is the envelope of the sound signal, not the raw audio waveform. It cannot be used to reproduce or record audio. For audio recording, use a dedicated microphone module with an amplifier (MAX9814, MAX4466).
  • The module can pick up electromagnetic noise from nearby wires and components. Keep the module away from motors, relays, and power cables for cleaner readings.
  • The digital output uses a simple comparator with a fixed threshold set by the potentiometer. It does not perform frequency analysis — loud noises of any pitch will trigger it equally.
  • The analog output responds to sound intensity but the voltage range varies between modules. Calibrate your thresholds for your specific module and environment.
  • Avoid exposing the microphone to wind, dust, or moisture — the electret element can be permanently damaged.
  • For sound-triggered projects, place the sensor on a vibration-dampening surface to reduce false triggers from physical vibration.