| Listening route | What the Pi receives | Typical parts | Planning use |
|---|---|---|---|
| Digital threshold module | 1 (HIGH) or 0 (LOW) signal; HIGH or LOW states only | KY-038-style module with a trimmer potentiometer and an OUT or DO pin | Best first build for loud-sound alerts, LED triggers and event counting |
| ADC-based analog | A varying analog signal digitised by an external converter | MAX4466 microphone module with an ADS1115 ADC on a Raspberry Pi 4 | Choose it when you need level values rather than a yes/no answer |
| I2S or USB capture | A digital audio stream | I2S MEMS microphone wired to header pins, or a USB microphone | Choose it when you need to record or analyse the sound itself |
Module behaviour is described in a Hackaday.io sound-activated LED project, and the analog pairing comes from a SparkFun community thread.
A sound sensor raspberry pi setup is simplest with a digital threshold module such as the KY-038: wire its output pin to a GPIO input and read HIGH or LOW in Python. Choose an ADC or digital microphone when you need levels or recordings.
This guide sits alongside our other raspberry pi gpio projects. It works through the build in phases, from a threshold alarm to richer audio capture.
Choosing a listening route
The first decision is what you want to know about the sound. A threshold module answers one question, whether the noise passed a limit you set. An analog or captured route answers how loud it was or what it contained.
The KY-038 belongs to the first group. According to the Hackaday.io project, the common variants output a digital signal, although some variants provide both analog and digital outputs. With the digital output, the module can only send 1 (HIGH) or 0 (LOW), depending on the threshold you have set.
- Pick the digital module for clap switches, door-knock alerts and noise alarms, where a yes/no event is enough and the wiring is only three or four connections.
- Pick an ADC route when you want to graph loudness or set the threshold in software instead of turning a screw.
- Pick I2S or USB when the goal is recording or processing audio, since a threshold module cannot give you the waveform.
Phase 1: Wire the digital module
Wiring is short, but pin numbers matter. The Raspberry Pi header has 40 pins and none carry labels, so keep a pinout guide open while you connect the module.
The example wiring in the Hackaday.io project uses physical pin numbers. Check your module’s datasheet for its supply and output levels before copying it, because the exact board determines what the signal pin delivers.
- Shut the Pi down and disconnect power before touching the header.
- Connect the module’s VCC pin to 5V (Pin 04).
- Connect the module’s GND pin to GND (Pin 06).
- Connect the signal pin to GPIO3 (Pin 05).
- Power the Pi back on once the connections are checked against the pinout.
Three-pin and four-pin boards
Module layouts differ. A 3-pin board exposes a single OUT pin. On a 4-pin board, use the digital output (DO) pin for this build, since the analog pin is a different kind of signal and will not behave like a two-state input.
Phase 2: Read the pin in Python
Any Python IDE on the Pi works for this project. The logic is short: configure the signal pin as an input, check its state in a loop or wait for it to change, and print a message or switch an LED when the pin reports a sound.

The Hackaday.io project lights an LED whenever the module detects a sound that exceeds the threshold. That is a good first test because the LED shows the result before you add logging or alerts.
Polarity is the detail that trips people up. The Hackaday.io project describes the output going HIGH above the threshold, while an Osoyoo Raspberry Pi tutorial says its sensor sends 0 (low voltage) to the Pi when it detects sound. Test your own board with a clap and write your condition to match what you observe.
Phase 3: Set the detection threshold
The threshold is physical on these modules. A trimmer potentiometer mounted directly on the sensor board sets the sensitivity, and the Osoyoo tutorial likewise says sensitivity is adjusted with a resistor on the back of the sensor.
- Place the module in the room where it will run, with the Python loop printing the pin state.
- Turn the trimmer slowly in small steps until the pin reports no sound in ordinary background noise.
- Make the loudest sound you want to catch and check that the state changes.
- If it does not change, turn the trimmer a little further in the sensitive direction and repeat.
Rotation direction varies by model. The Hackaday.io project notes that clockwise increases sensitivity on its module, but the direction may be opposite on your sound sensor module. Let the printed output, not an assumed direction, tell you which way is more sensitive.
Because the output has only two states, a threshold tuned in a quiet room may fire constantly in a noisy one. Retune when the placement changes.
Phase 4: Move to analog or captured audio
Move on from the threshold module when a yes/no answer stops being enough. Both routes below trade wiring simplicity for more information.
ADC-based analog
A community project on the SparkFun forum pairs a MAX4466 microphone module with an ADS1115 ADC on a Raspberry Pi 4. The external converter turns the analog microphone signal into numbers the Pi can read. It is the route to take if you want sound levels you can log, plot or compare against a software threshold.

This also answers a common question about the KY-038. Some module variants expose both analog and digital outputs, but the analog values are not read straight off the digital pin. Use the analog pin with a converter such as the ADS1115 if you want them.

I2S or USB capture
If you want actual audio, use a digital microphone. An I2S MEMS microphone breakout wires to the Pi’s header pins, while a USB microphone plugs straight into a USB port and needs no soldering. The USB route is the easier start; the I2S route suits a compact build with no external sound card.

Troubleshooting
- The output never changes. Check the signal wire is on the pin you named in your script, and that a 4-pin board is using its DO pin rather than the analog one.
- The output is always changing. Sensitivity is likely set too high for the room. Turn the trimmer back until the printed state settles in background noise.
- Sound produces the opposite result. Flip your condition. Boards differ on whether a detected sound reads HIGH or LOW.
- Wrong pin responds. The header is unlabelled, so recheck the physical pin numbers against a pinout guide.
- You need values, not events. A digital module cannot supply them. Move to the ADC or capture route.
Where to go next
Once the sound input is working, other header peripherals follow the same wire, read and test pattern. A raspberry pi gps module adds location data, and the hc-sr04 raspberry pi python guide covers distance sensing with a similar input approach.
Frequently asked questions
Can the KY-038 give analog values directly on the Pi?
Some variants carry an analog output alongside the digital one, but the digital pin only reports two states. For numeric levels, a community setup feeds an analog microphone into an ADS1115 ADC.
Which Python editor should I use?
Any Python IDE installed on the Pi works. The Hackaday.io example uses Thonny, and Mu or the terminal editor also work.
Can I write the detection program in C instead?
Yes. The Osoyoo tutorial compiles a C program against wiringPi with gcc -Wall -o sound sound.c -lwiringPi.
Why do the header pins have no labels?
The Pi’s 40 header pins carry no printed labels, so check each connection against a pinout guide by physical pin number before powering up.



