So I've struggled some time with getting the KY-037 and KY-038 sensors working for ambent sound detection/tracking in ESPHome. These sensors seem to lack sensitivity to be used for anything short of detecting alarms or really loud sounds.

I wanted to build a device to measure the general noise in a room, at a low cost and without actually recording any sound. Finally, I came across the Sparkfun Electret Microphone Breakout BOB-12758. It promised a 60x mic preamp to detect even the lowest ambient noise.

So I connected the mic to an ADC pin on my ESP-WROOM-32 development board, but got disappointed. The sensor output voltage seemed to fluctuate around 1,6V, and randomly spiking upwards and downwards depending on noise around it. Yet another failure, I thought.

Then a brilliant mind on Discord pointed me at the ct_clamp direction. ct_clamp is a sensor type in ESPHome that allows you to sample readings on an ADC pin over time, and convert that to a current measure. The solution turned out brilliantly.

This is how I did it

  - platform: adc
    id: adc_mic_reading
    pin: 32
    name: "Voltage from my BOB-12758"
    update_interval: 60s
    attenuation: auto
  - platform: ct_clamp
    sensor: adc_mic_reading
    name: "Sound level from my BOB-12758"
    sample_duration: 250ms
    update_interval: 500ms

Basically, I'm telling the ct_clamp sensor to use my adc-sensor. Sample the sensor for 250ms before updating with a value twice a second. I've connected my ESPHome to Home Assistant, and now I can monitor the "Sound level" sensor for elevated Ampere values. I can set thresholds in Home Assistant and initiate automations or scenes whenever the sound level reaches certain levels.

Previous Post Next Post