Sound Sensor practical reference
The KY-038 is a small electret-microphone breakout that provides both a digital and an analog output for detecting sound. The digital output flips when volume crosses an adjustable threshold set by an onboard potentiometer, ideal for simple clap-switch or knock-detector projects, while the analog output tracks the raw waveform/envelope for more nuanced sound-reactive builds like level meters or beat-triggered lighting.
Key specifications
- Sensor type: Electret condenser microphone with onboard LM393 comparator
- Operating voltage: 3.3V–5V DC
- Digital output (DO): Goes LOW when detected sound exceeds the threshold set by the onboard potentiometer, HIGH otherwise (some boards invert this)
- Analog output (AO): Continuous analog signal proportional to the microphone's raw audio envelope
- Sensitivity adjustment: Onboard trimmer potentiometer sets the digital-trigger threshold
- Detection range: Best for close-range sounds (claps, knocks, voice) within roughly 0.5-1m
- Interface: 1 digital pin (threshold trigger) + 1 analog pin (raw signal)
Pinout and connection notes
Turn the onboard potentiometer clockwise/counter-clockwise while testing with a clap to tune the digital trigger sensitivity — too sensitive and it fires on background noise, too insensitive and it misses claps. For beat-detection or volume-level projects, use the analog output instead and do the thresholding in software.
- VCC: Power, 3.3–5V DC
- GND: Ground
- DO: Digital output — threshold-triggered HIGH/LOW sound detection
- AO: Analog output — raw microphone signal, read with analogRead()
Integration checklist
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.
Troubleshooting and reproducibility
Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.
Practical signal handling and limitations
The analog output of a KY-038-style board is not a calibrated sound-pressure-level measurement. Depending on the exact board, the microphone preamplifier and bias network may present an AC waveform riding on a DC bias, or a partially detected envelope. Inspect the output with an oscilloscope before choosing an ADC sampling strategy. A single analogRead value is only one sample, not a loudness measurement. For a simple relative level indicator, sample a window of values and calculate a peak-to-peak or RMS-like measure after accounting for the signal's DC offset.
The digital comparator output is useful for threshold events such as a clap, but it cannot identify speech, music, or a particular sound source. Background noise, microphone orientation, enclosure openings, and supply noise all affect triggering. Set the threshold in the intended enclosure and environment, and add software debounce or a minimum re-trigger interval if one clap causes several events.
For an ESP32, check ADC pin restrictions and input range for the exact board. Keep the analog signal within the ADC's permitted voltage range and use a common ground. Do not describe this low-cost module as a calibrated decibel meter or use it as a certified acoustic or safety alarm.
Wiring & code
Board integration
Library
None — built-in analogRead/digitalRead by —
No library needed; uses core Arduino functions only.
Wiring
| Component pin | Arduino Uno pin | Note |
|---|---|---|
| VCC | 5V | |
| GND | GND | |
| AO | A0 | Analog envelope of the mic signal — read continuously. |
| DO | D2 | Digital threshold output, set by the onboard potentiometer. |
#include <Arduino.h>
#define SOUND_AO A0
#define SOUND_DO 2
void setup() {
Serial.begin(9600);
pinMode(SOUND_DO, INPUT);
}
void loop() {
int level = analogRead(SOUND_AO);
bool triggered = digitalRead(SOUND_DO);
Serial.print(F("Level: "));
Serial.print(level);
Serial.print(F(" Triggered: "));
Serial.println(triggered ? F("YES") : F("no"));
delay(100);
}- Turn the onboard potentiometer to set the DO trigger threshold — it does not affect the AO reading.
- AO is noisy and has no fixed units; treat it as a relative loudness level, not a calibrated dB value.
- For actual clap/sound-detection projects, debounce DO in software — a single loud sound can trigger multiple pulses.
