Part

Sound sensor, KY-038

A microphone with no amplifier. Claps light it; talking barely moves it. Press clap.

See every part
  • 4 pins
  • 2 settings
  • In 2 projects
  • In 1 lesson
Drawn live by the editor's own code, at the size you see it.
At a glance

The Sound sensor, KY-038 in brief

What it is, and every setting the properties panel gives it.

The KY-038 is the kit sound sensor: an electret capsule on an LM393 comparator board with a blue multiturn trimmer, its pins printed A0, G, + and D0. It runs from 3.3 to 5 volts. On an Uno, + goes to 5 V, A0 to an analog pin and D0 to a digital pin; on an ESP32, power it from 3.3 V so D0 stays at 3.3 V logic, and A0 then rests near 1.65 volts. There is no amplifier, and Mokxi models what that means: A0 rests at half the supply and the capsule gives -44 dBV per pascal, 6.3 mV rms at 94 dB, so talking barely moves analogRead from 512: it is a loud-noise detector. The slider is the room from 30 to 110 dB SPL, the clap button is a 120 dB clap dying away over 25 ms, and the trimmer sits at 0.505 of the supply, 25 mV above rest on 5 V. The classic mistake is reading D0 as a level: one clap is dozens of pulses, so latch the first edge and ignore the rest. Real audio, sound below about 75 dB and the capsule’s frequency response are not modeled.

Family
Sensors
Pins
4
threshold
0.505
sensitivity
-44

A circuit built around it, running and explained: the Sound sensor simulator.

Pins

4 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
Role
What it does
AO
Output
The microphone's signal, resting at half the supply. Printed A0.
GND
Input or output
Ground. Printed G.
VCC
Input or output
Supply, 3.3 V to 5 V. Printed +.
DO
Output
High while the sound is above the trimmer: a burst of pulses, not a level. Printed D0.
How to use it

How to use the KY-038 sound sensor with an Arduino

The pins are printed A0, G, + and D0. In the clap switch, + goes to 5 V, G to GND, D0 to pin 2 and A0 to A0, and a lamp on pin 9 toggles on each clap. Press clap on the sensor to try it.

D0 is the one to use. A clap is not one clean high but a burst of dozens of pulses, so the sketch takes the first rising edge and ignores D0 for 300 ms, the same debounce a button needs. A sketch that toggles on every edge flickers the lamp dozens of times.

A0 sits at about 512 and barely moves: there is no amplifier on the board, so even “very loud” on the slider shifts it by a few counts. That is the real module too, which is a loud-noise detector and not a microphone for speech.

Part pin
Board pin
DO
Pin 2
AO
A0
VCC
5 V
GND
GND

It runs from 3.3 V, so on an ESP32 power it from 3.3 V: D0 then swings to 3.3 V and A0 rests near 1.65 V, half the supply.

Arduino Uno: clap switchlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Toggling a lamp on each clap
const int SOUND_DO = 2;
const int LAMP = 9;
bool lampOn = false;
bool wasHigh = false;
unsigned long lastClap = 0;
void setup() {
  pinMode(SOUND_DO, INPUT);
  pinMode(LAMP, OUTPUT);
}
void loop() {
  bool high = digitalRead(SOUND_DO) == HIGH;
  if (high && !wasHigh && millis() - lastClap > 300) {
    lastClap = millis();
    lampOn = !lampOn;
    digitalWrite(LAMP, lampOn ? HIGH : LOW);
  }
  wasHigh = high;
}
How it is modeled

What is true about the Sound sensor, KY-038, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

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.

Not modeled

The sound itself. By default the part hears only the slider and the clap. The Sound settings button on the toolbar can feed it a test tone, a test beat, an audio file or your computer's microphone instead, but the part takes only a loudness from that: what it makes on AO is still white noise at that level, stopping 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.

From KY-038 sound sensor, in full.

Projects

See the Sound sensor, KY-038 in a project

2 built-in projects use it. Each opens in the editor, already wired.

Lessons

Where it turns up in a lesson

One lesson places it in its own circuit.

Boards

The boards it is shown on

Each of these 2 boards has a built-in project with the Sound sensor, KY-038 in it.

Wire up the Sound sensor, KY-038

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.