The Shillehtek KY-037 sound sensor module for Arduino & ESP32 projects is a staple for acoustic triggering, ambient noise monitoring, and clap-switch builds. It features an electret microphone, an LM393 comparator, and breaks out both an analog (AO) and digital (DO) output. However, wiring its 5V analog output directly to an ESP32's 3.3V ADC is the number one cause of bricked microcontroller pins and saturated readings. This guide provides exact wiring topologies, voltage-safe code, and hardware debugging frameworks to get your acoustic projects running reliably.
Spec Sheet & Parts List
Estimated Time: 30 minutes
Target Board Variant: ESP32 DevKit V1 (30-pin) & Arduino Uno R3
Before breadboarding, verify you have the exact components. The Shillehtek branding is common, but the underlying circuit is identical to HiLetgo and SunFounder variants.
| Component | Exact Variant / Spec | Notes |
|---|---|---|
| Sound Sensor | Shillehtek KY-037 (4-pin) | Ensure it has both AO and DO pins. 3-pin variants lack analog out. |
| Microcontroller | ESP32 DevKit V1 (30-pin) OR Arduino Uno R3 | Code provided targets ESP32; Arduino requires minor pin reassignments. |
| Resistors (Voltage Divider) | 10kΩ and 20kΩ (1/4W) | Required only if powering KY-037 at 5V while using ESP32. |
| Jumper Wires | 22 AWG solid core | Keep analog runs under 6 inches to minimize 60Hz hum. |
Pin Mapping & The ESP32 Voltage Trap
The KY-037 operates between 3.3V and 5V. If you are using an Arduino Uno (5V logic), you can power the module from the 5V pin and wire AO/DO directly. If you are using an ESP32 (3.3V logic), you must manage the voltage carefully.
The LM393 comparator on the module has an open-collector output on the DO pin (TI LM393 Datasheet). This means it can only pull the line to ground; it relies on an external pull-up resistor to go HIGH. The module includes an onboard pull-up tied to VCC. If you power the module with 5V, the DO pin will output 5V when HIGH, which will degrade or destroy the ESP32's GPIO pin over time.
The Solution: Power the KY-037 with 3.3V from the ESP32. The LM393 is rated down to 3.0V single-supply operation. This keeps the DO pin safely at 3.3V. The analog (AO) pin, which is driven by an op-amp buffer, will max out around 3.1V, perfectly aligning with the ESP32's ADC 11dB attenuation range.
| KY-037 Pin | Arduino Uno R3 | ESP32 DevKit V1 | Wiring Notes |
|---|---|---|---|
| VCC | 5V | 3V3 | Do not use ESP32 VIN/5V pin unless using logic level shifters. |
| GND | GND | GND | Share a common ground plane to avoid analog noise. |
| DO (Digital) | Pin 2 | GPIO 27 | Open-collector. Safe at 3.3V if VCC is 3.3V. |
| AO (Analog) | A0 | GPIO 34 | GPIO 34 is input-only and ADC1 capable. Avoid ADC2 (WiFi conflicts). |
Compilable Code: ESP32 Dual-Mode Sound Detection
This code targets the ESP32 DevKit V1. It reads both the digital threshold trigger and the raw analog envelope. It includes error handling for ADC saturation, a common issue when the analog signal exceeds the ESP32's maximum readable voltage.
// Target: ESP32 DevKit V1 (30-pin)
// Library: Arduino core for ESP32 (Espressif Systems)
#define DO_PIN 27 // Digital Output from KY-037
#define AO_PIN 34 // Analog Output from KY-037 (ADC1_CH6)
#define ADC_MAX 4095 // 12-bit ADC resolution
#define SATURATION_THRESHOLD 4080 // Buffer for ADC non-linearity at top end
void setup() {
Serial.begin(115200);
delay(1000); // Allow serial monitor to connect
// Configure Digital Pin
// LM393 is open-collector; INPUT_PULLUP provides the 3.3V high state safely
pinMode(DO_PIN, INPUT_PULLUP);
// Configure Analog Pin
// Set attenuation to 11dB for a ~0-3.1V readable range
analogSetPinAttenuation(AO_PIN, ADC_11db);
Serial.println("KY-037 Sound Sensor Initialized.");
Serial.println("Format: [Analog Raw] | [Analog mV] | [Digital State]");
}
void loop() {
int rawADC = analogRead(AO_PIN);
int doState = digitalRead(DO_PIN);
// Error Handling: Check for ADC Saturation
if (rawADC >= SATURATION_THRESHOLD) {
Serial.println("ERROR: ADC saturation detected (Read: 4095). Check voltage divider or lower VCC.");
}
// Convert raw ADC to millivolts using ESP32 calibrated function
int milliVolts = analogReadMilliVolts(AO_PIN);
Serial.print("AO: ");
Serial.print(rawADC);
Serial.print(" | mV: ");
Serial.print(milliVolts);
Serial.print(" | DO: ");
Serial.println(doState == LOW ? "TRIGGERED" : "IDLE");
delay(50); // 20Hz sampling rate is sufficient for envelope detection
}
Debugging: First Three Things to Check When It Fails
When the sensor fails to trigger or outputs garbage data, follow this ranked decision path. These are the first three things to check when it fails on the bench.
- The Trimpot Tuning (Digital Pin Never Triggers): The blue potentiometer sets the threshold for the DO pin. If it is turned fully clockwise, the threshold is set higher than the module's maximum output, meaning the DO pin will never pull LOW. Fix: Turn the trimpot counter-clockwise until the onboard status LED lights up in a quiet room, then back it off slightly until it extinguishes.
- ADC Saturation (Serial Output Stuck at 4095): If your serial monitor prints
ERROR: ADC saturation detected (Read: 4095), your analog input is exceeding the ESP32's ~3.1V ceiling. Fix: Verify you are powering the KY-037 from the ESP32's 3V3 pin, not the 5V/VIN pin. If you must use 5V for microphone sensitivity, build a voltage divider (10kΩ to GND, 20kΩ in series with AO) before hitting GPIO 34. - 60Hz Ground Loop Hum (Analog Plotter Shows Sine Wave): If the Arduino Serial Plotter shows a thick, oscillating band of noise rather than sharp spikes on claps, you have a ground loop or EMI pickup. Fix: Ensure the ESP32 and KY-037 share the exact same ground return path. Keep the microphone capsule away from switching regulators and AC mains transformers.
Extending and Simplifying the Build
Depending on your end goal, you can drastically alter the complexity of this circuit.
How to Simplify: If you only need a clap-switch or a noise-activated relay, abandon the analog (AO) pin entirely. Wire only VCC, GND, and DO. Use the ESP32's hardware interrupt (attachInterrupt) on the DO pin to wake the microcontroller from deep sleep. This eliminates ADC noise, saves power, and reduces code complexity to a single trigger event.
How to Extend: The KY-037 is an envelope detector; it measures sound amplitude, not audio waveforms. If your goal is to record voice, perform FFT frequency analysis, or build a voice-activated assistant, the KY-037 is the wrong tool. Extend your build by replacing it with an I2S MEMS microphone like the INMP441. The INMP441 outputs true digital audio waveforms via the I2S protocol, bypassing the ADC entirely and providing CD-quality audio capture (Espressif I2S Documentation).
Frequently Asked Questions
Why is my Shillehtek KY-037 analog output stuck at 4095 on the ESP32?
This happens because the ESP32's 12-bit ADC maxes out at 4095 when the input voltage exceeds its readable ceiling (roughly 3.1V with 11dB attenuation). The KY-037, when powered by 5V, outputs up to 5V on the AO pin. You are overdriving the ADC. Power the module from the 3.3V rail, or use a resistor voltage divider to step the 5V signal down to 3.3V before it reaches the GPIO pin.
Can I power the KY-037 sound sensor with 3.3V instead of 5V?
Yes. The LM393 comparator is specified for single-supply operation from 3.0V to 30V. Powering it at 3.3V slightly reduces the bias voltage across the electret microphone capsule, which may result in a 10-15% drop in raw sensitivity. However, this is the safest and most reliable method for direct connection to 3.3V microcontrollers like the ESP32, Raspberry Pi Pico, or Arduino Due.
How do I adjust the blue trimpot on the KY-037 module correctly?
The trimpot adjusts the reference voltage fed into the LM393's inverting input. To tune it for a specific environment: monitor the DO pin status LED on the module. Clap your hands near the mic. Turn the trimpot with a small Phillips screwdriver until the LED reliably flashes on your clap but stays off during normal background conversation. Allow the module to run for 10 minutes before final tuning, as the electret capsule's impedance shifts slightly as it warms up.
Is the KY-037 suitable for recording voice or audio files?
No. The KY-037 lacks the bandwidth and sampling architecture for audio recording. The analog output is heavily filtered by onboard capacitors to provide a slow-moving DC 'envelope' of the sound pressure level, stripping away the high-frequency AC waveform required for human speech intelligibility. For voice recording, use an I2S digital microphone (INMP441) or an I2C ADC with a raw electret breakout board.






