
Updated August 6, 2026 · Code and limitations checked against current ESPHome documentation.
A KY-037 with ESPHome is useful for detecting a clap, knock, alarm or sudden rise in noise and sending that event to Home Assistant. Its digital output reports whether an adjustable threshold has been crossed, while its analog output can compare relative levels. The crucial limitation is simple: the KY-037 is not a sound level meter and does not measure calibrated decibels.
What you need to know first
- DO: binary threshold detection; the physical potentiometer sets the switching point.
- AO: analog signal for comparing relative sound activity, not dB SPL.
- ESP8266: the chip ADC accepts 0–1 V; many NodeMCU/D1 mini boards include a divider on A0 for roughly 3.2–3.3 V. Verify your board.
- Power: module clones vary. When powered from 5 V, their outputs may exceed an ESP input limit; use 3.3 V if your unit operates correctly or add level adaptation.
What the KY-037 is and what each pin provides
The module combines an electret microphone, an LM393 comparator, a potentiometer and two LEDs. The microphone responds to acoustic-pressure variations, but the board is not a calibrated measurement chain. Orientation, distance, supply voltage, microphone tolerances and clone circuitry all change the result.
| KY-037 pin | Function | Recommended use |
|---|---|---|
| + | Module supply | 3.3 V when your module works reliably; if it requires 5 V, level-shift AO and DO. |
| G / GND | Common ground | Connect to board GND. |
| DO | Comparator output | ON/OFF detector for sound crossing the threshold. |
| AO | Analog output | Relative index or diagnostic only; never label it dB without real acoustic calibration. |
Why an ADC formula cannot produce real dB
An ADC count only represents voltage. Converting it into sound-pressure level requires, at minimum, known microphone sensitivity, analog gain, frequency response, RMS processing, an acoustic reference, weighting such as dBA and calibration against a trustworthy source or meter. The old expression sensitivity × log10(ADC) + constant had none of that information: it produced a decibel-looking number, not a measurement.
Home Assistant provides sound_pressure for sensors that genuinely report dB or dBA. signal_strength is for signal power such as RSSI and is not appropriate either. This guide publishes the relative value as a percentage with state_class: measurement and no device_class.
That does not make the module useless. A relative reading is often enough to tell whether an alarm has started, a door was knocked or a machine has become louder than its baseline.
Parts required
- KY-037 and Dupont wires.
- NodeMCU ESP8266 or Wemos D1 mini. An ESP32 also works with the changes below.
- ESPHome Device Builder and the Home Assistant integration.
- A multimeter is recommended to check maximum AO/DO voltage if the module is powered at 5 V.
For a secure starting configuration, see our ESPHome WiFi guide. Related tested projects include the HC-SR04 with ESP8266 and DS18B20 with ESP8266.
KY-037 wiring for an ESP8266
| KY-037 | NodeMCU / D1 mini | Note |
|---|---|---|
| + | 3V3 | The cautious option for protecting the ESP when the module operates reliably at 3.3 V. |
| G | GND | Ground must be common. |
| DO | D1 / GPIO5 | Most modules pull low above the threshold; the YAML inverts the state. |
| AO | A0 | Verify your board’s external input range. The bare ESP8266 ADC accepts only 0–1 V. |
Never connect a 5 V output directly to an ESP8266 GPIO or ADC. If your KY-037 version needs a 5 V supply, measure AO and DO and use a suitable resistor divider or level shifter.
Recommended option: digital threshold detector
For claps, knocks or a siren, DO is the simplest option. Turn the potentiometer until the trigger LED changes at the target sound. This block makes Home Assistant turn ON immediately and holds the event for 250 ms so a short pulse remains visible.
binary_sensor:
- platform: gpio
id: ky037_sound_trigger
name: "KY-037 loud sound detected"
icon: "mdi:volume-high"
pin:
number: D1 # GPIO5 on NodeMCU / D1 mini
inverted: true # Remove if your module behaves the other way
filters:
- delayed_off: 250ms
The potentiometer adjusts the physical comparator used by DO. A Home Assistant slider cannot move it or alter that threshold. The old “Sensitivity SoundEsp” control merely changed the fake-dB formula.
Analog option: relative sound level as a percentage
AO can compare sound activity from the same physical setup. Because every board differs, first watch the logs and replace 250 with your normal quiet reading and 750 with a repeatable high reading. The result is a relative 0–100% index, not dB.
substitutions:
ky037_quiet_raw: "250" # Replace with your observed quiet value
ky037_loud_raw: "750" # Replace with a repeatable high level
sensor:
- platform: adc
pin: A0
id: ky037_adc_raw
internal: true
raw: true
update_interval: 100ms
samples: 32
sampling_mode: max
- platform: copy
source_id: ky037_adc_raw
name: "KY-037 relative sound level"
icon: "mdi:waveform"
unit_of_measurement: "%"
device_class: ""
accuracy_decimals: 0
state_class: measurement
filters:
- calibrate_linear:
method: exact
datapoints:
- ${ky037_quiet_raw} -> 0
- ${ky037_loud_raw} -> 100
- clamp:
min_value: 0
max_value: 100
- exponential_moving_average:
alpha: 0.2
send_every: 1
- throttle: 1s
sampling_mode: max retains the maximum from each group of readings, which helps catch transients. Smoothing reduces jumps and throttle protects the Home Assistant database from excessive updates. If your values decrease as sound rises, swap the two calibration points.
Complete current ESPHome configuration
This example combines secret-based WiFi, encrypted API, current OTA syntax, DO and AO. Use a 32-byte Base64 API key generated by ESPHome and keep every sensitive value in secrets.yaml.
substitutions:
device_name: "ky037-sound-detector"
friendly_name: "KY-037 Sound Detector"
ky037_quiet_raw: "250"
ky037_loud_raw: "750"
esphome:
name: ${device_name}
friendly_name: ${friendly_name}
esp8266:
board: d1_mini
logger:
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "KY037 Fallback"
password: !secret fallback_password
captive_portal:
binary_sensor:
- platform: gpio
id: ky037_sound_trigger
name: "Loud sound detected"
icon: "mdi:volume-high"
pin:
number: D1
inverted: true
filters:
- delayed_off: 250ms
sensor:
- platform: adc
pin: A0
id: ky037_adc_raw
internal: true
raw: true
update_interval: 100ms
samples: 32
sampling_mode: max
- platform: copy
source_id: ky037_adc_raw
name: "Relative sound level"
icon: "mdi:waveform"
unit_of_measurement: "%"
device_class: ""
accuracy_decimals: 0
state_class: measurement
filters:
- calibrate_linear:
method: exact
datapoints:
- ${ky037_quiet_raw} -> 0
- ${ky037_loud_raw} -> 100
- clamp:
min_value: 0
max_value: 100
- exponential_moving_average:
alpha: 0.2
send_every: 1
- throttle: 1s
Example secrets.yaml:
wifi_ssid: "YOUR_NETWORK_NAME"
wifi_password: "YOUR_LONG_WIFI_PASSWORD"
api_encryption_key: "BASE64_KEY_GENERATED_BY_ESPHOME"
ota_password: "A_DIFFERENT_UNIQUE_PASSWORD"
fallback_password: "A_SECURE_FALLBACK_PASSWORD"
For larger files, see ESPHome substitutions and packages. Our Home Assistant secrets guide explains why credentials should not be embedded in public YAML.
ESP32 adaptation
On a classic ESP32, AO can use an ADC1 input-only pin such as GPIO34 with automatic attenuation. Pins vary by chip variant, so verify your board. Power or level-shift the KY-037 so neither output can exceed 3.3 V.
sensor:
- platform: adc
pin: GPIO34 # Classic ESP32; check other variants
id: ky037_voltage
attenuation: auto
update_interval: 100ms
samples: 32
sampling_mode: max
name: "KY-037 analog level"
unit_of_measurement: "V"
accuracy_decimals: 3
state_class: measurement
Observe the voltage in quiet conditions and at your reference sound, then apply calibrate_linear if you want a relative percentage. Do not copy somebody else’s calibration points; they are not transferable between modules.
How to adjust the threshold
- Power the final assembly in its intended location.
- In quiet conditions, slowly turn the potentiometer until the DO LED changes state.
- Move slightly away from that point to prevent continuous triggering.
- Play the target sound at a realistic distance and readjust.
- Repeat the test in Home Assistant instead of relying only on the LED.
Home Assistant automation example
An automation should react to a defined event, not treat the percentage as a sound meter. This example notifies when DO detects a loud sound and uses single mode to avoid overlapping runs:
alias: KY-037 loud sound alert
triggers:
- trigger: state
entity_id: binary_sensor.loud_sound_detected
to: "on"
actions:
- action: notify.mobile_app_your_phone
data:
title: "KY-037 detector"
message: "Sound above the configured threshold was detected."
mode: single
Troubleshooting
| Symptom | What to check |
|---|---|
| Always ON | Adjust the potentiometer; if the LED logic is reversed, remove inverted: true. |
| Claps are not detected | Move closer, adjust the threshold, check DO with a meter and verify power/ground. |
| AO barely changes | This is common on low-gain clones. Use DO or choose a microphone board with a suitable amplifier. |
| Reading is saturated | The input may exceed the ADC range. Fix the supply/divider before continuing. |
| Percentage is very noisy | Keep wires away from switching supplies, shorten connections and tune smoothing; this is not instrumentation. |
| Too much history | Keep throttle: 1s or increase it; storing ten readings per second is unnecessary. |
When to choose another microphone
Choose an I2S microphone such as an INMP441/SPH0645 or a specified sound-level board if you need audio analysis, frequency information, RMS or a calibrated estimate. Legal or occupational limits require a certified sound level meter and the applicable procedure; a KY-037 cannot replace one.
Sources and checked documentation
- ESPHome ADC sensor and ESP8266 limits.
- ESPHome GPIO Binary Sensor.
- ESPHome sensor filters, calibration and base properties.
- Home Assistant sensor device classes.
Frequently asked questions
Does the KY-037 measure decibels?
No. It provides an uncalibrated analog signal and a digital threshold. It can create a relative index, but labeling it dB without a calibrated chain is incorrect.
Does the potentiometer change the analog output?
On most modules it sets the comparator threshold for DO. It does not calibrate AO or turn the board into a sound level meter.
Can I power a KY-037 from 5 V?
Some modules specify it, but AO or DO may then exceed an ESP8266/ESP32 limit. Measure and level-shift the outputs. Never assume two clones are identical.
Which output is better for clap detection?
DO is usually simpler: set the physical threshold and use the binary sensor. AO is useful when you want a software-defined relative threshold or a trend.
With the right expectations, the KY-037 is a cheap and useful event detector. The meaningful improvement is not inventing decibels; it is choosing DO or AO for the task, protecting the ESP inputs and calibrating a relative percentage against your own physical setup.
Continue reading
Next related guide · 9 min read
Smart Refrigerator with ESPHome and Home Assistant
Updated August 6, 2026 · Migrated to one_wire and dallas_temp, with wiring, alerts and security checked against current documentation. A smart refrigerator does not…
Continue with this article

