KY-038 sound sensor
An electret microphone on an LM393 comparator board with a blue trimmer, pins
printed A0 G + D0. Aliases: sound sensor, microphone module, clap sensor.
It is the most disappointing module in the kit until you know what it is. There is
no amplifier on the board. The capsule's own signal, a few millivolts riding on a
DC level, comes straight out on AO, and the comparator lets DO go high on every
instant the signal pokes above the trimmer.
Pins
| Pin | What it does |
|---|---|
AO |
The microphone's signal, resting at half the supply. Printed A0. |
GND |
Ground. Printed G. |
VCC |
Supply, 3.3 V to 5 V. Printed +. |
DO |
High while the sound is above the trimmer: a burst of pulses, not a level. Printed D0. |
Properties
threshold is the trimmer as a fraction of the supply, 0.505 by default: 25 mV above
the resting level on 5 V. sensitivity is the capsule's sensitivity in dBV per
pascal, -44 by default; -38 is closer to the KY-037's bigger capsule.
While it runs
The slider is how loud the room is, in dB SPL, from a quiet 30 to a very loud 110. The clap button is one sharp clap at the capsule. The DO lamp lights when the comparator trips, and stays lit for 50 ms after each pulse so a flicker can be seen.
What the model gets right
How small the signal is. An electret of this size gives 6.3 mV rms at 94 dB SPL,
someone shouting at arm's length. Talking at 60 dB is a tenth of a millivolt, and a
10-bit ADC on 5 V counts in steps of 4.9 mV. So analogRead(AO) sits at about 512 and
wobbles by a count or two for anything short of shouting. This is the honest answer to
"why does my sound sensor read 512 all the time", and the module is really a loud
noise detector: a clap, a knock, a door.
What DO does. The sound is noise sampled 8000 times a second, and the comparator
works on every sample. A loud sound makes DO a burst of pulses at audio rate, not one
clean high, which is why a clap switch sketch latches the first edge and then ignores
DO for a moment.
What it does not model
There is no real sound: no audio from the computer's microphone, only the level on the
slider and the clap. The noise is white and stops at 4 kHz. Below about 75 dB the
signal is under a quarter of an ADC step and the model does not make it at all, so AO
sits exactly at its resting level where a real one has a little hiss. The resting
level is half the supply; on a real board it depends on the capsule's bias resistor.
The comparator has no hysteresis, as on the real board.
Common mistakes
Reading DO as a level. One clap is dozens of pulses; latch the first and wait.
Expecting speech to register. It will not, on this module or the real one.
See it in action
Clap switch toggles a lamp on each clap with an Uno. Open it at /templates.