KY-038 Sound Sensor with an Arduino Uno
A microphone module with a raw analog output and a digital output that trips on loud sounds such as claps.

The Arduino Uno has no I2S or digital microphone input, so a module like the KY-038, read through the Uno's analog pin A0, is how it hears. Powered from 5V as Joy-IT wires it for Arduino, AO's swing and DO's level both match the Uno's 0 to 5 V range, with DO on D2.
Wiring the KY-038 Sound Sensor to the Arduino Uno
Pin by pin.
| KY-038 Sound Sensor | Arduino Uno |
|---|---|
| VCC | 5V |
| GND | GND |
| AO | A0 |
| DO | D2 |
What to know on the Arduino Uno
- Each analogRead() on the Uno takes 13 ADC clock cycles at the core's 125 kHz ADC clock, about 104 µs, so the 50 ms window gathers a few hundred samples. That is enough to measure loudness as AO's peak-to-peak swing, not to record or analyse the sound itself.Microchip ATmega328P datasheet DS40002061B, ADC section
- The module has no amplifier, so a clap moves AO by only a few of the Uno's 4.9 mV steps unless the source is close; set the potentiometer so DO fires on the claps you want rather than relying on AO alone.Joy-IT SensorKit, KY-038; Microchip ATmega328P datasheet DS40002061B, p. 2
- While the window runs, loop() does nothing else, which is why the sketch also polls DO inside it. To catch a clap without polling, D2 is INT0: attachInterrupt() on RISING records it even while the Uno is busy, then ignore further edges for 300 ms.Arduino language reference, attachInterrupt()
- AO is inverted and its resting level depends on the trimmer and the 5 V supply, so compare its swing, never one sample against 512.Joy-IT SensorKit, KY-038
KY-038 Sound Sensor code for the Arduino Uno
Compiled for arduino:avr:uno on 2026-10-29.
// KY-038 Sound Sensor on Arduino Uno: wiring and a free simulation at https://www.tinkered.ai/components/sound-sensor-ky-038/arduino-uno
const int AO_PIN = A0; // KY-038 AO: the capsule's signal on a DC level
const int DO_PIN = 2; // KY-038 DO: HIGH while the sound passes the trimmer's threshold
const unsigned long WINDOW_MS = 50; // one loudness reading per 50 ms
const unsigned long CLAP_GAP_MS = 300;
int claps = 0;
unsigned long lastClap = 0;
unsigned long lastPrint = 0;
void setup() {
Serial.begin(9600);
pinMode(DO_PIN, INPUT); // the module has its own pull-up
Serial.println("KY-038 ready");
}
void loop() {
// the swing of AO over a window: its peak-to-peak is the loudness
unsigned long start = millis();
int lo = 1023, hi = 0;
bool loud = false;
while (millis() - start < WINDOW_MS) {
int v = analogRead(AO_PIN);
if (v < lo) lo = v;
if (v > hi) hi = v;
if (digitalRead(DO_PIN) == HIGH) loud = true;
}
int level = hi - lo;
// one clap per CLAP_GAP_MS, however long DO stays HIGH
if (loud && millis() - lastClap > CLAP_GAP_MS) {
lastClap = millis();
claps++;
Serial.print("Clap ");
Serial.print(claps);
Serial.print(" (level ");
Serial.print(level);
Serial.println(")");
}
if (millis() - lastPrint >= 1000) {
lastPrint = millis();
Serial.print("AO ");
Serial.print((lo + hi) / 2);
Serial.print(" level ");
Serial.println(level);
}
}
KY-038 Sound Sensor on the Arduino Uno: questions
Can an Arduino Uno record sound with the KY-038?
No. The Uno samples A0 roughly every 104 µs and has no audio input such as I2S. It can measure loudness and detect claps, which is what the KY-038 is for.
Why does the KY-038 reading barely change on the Uno?
The module has no amplifier, and the Uno's ADC steps are about 4.9 mV. Measure peak-to-peak over a window as the example does, and use DO with the potentiometer for clap detection.
Should the KY-038 use 5V or 3.3V on an Uno?
5V, as Joy-IT wires it for Arduino. AO and DO then span the Uno's full 0 to 5 V input range.
Keep going
This guide as plain Markdown. /components/sound-sensor-ky-038/arduino-uno.md