Arduino Nano Microphone Sound Sensor Module
The Microphone Sound Sensor Module project demonstrates how to interface an electret‑microphone‑based sound sensor (such as KY‑038 or LM393 sound modules) with an Arduino Nano. These modules sense the sound intensity of the environment and output both analog and digital signals that Arduino can read to trigger LEDs, relays, or Serial‑Monitor messages in response to noise or claps.
What Is a Microphone Sound Sensor?
A typical sound sensor module includes an electret condenser microphone, an amplifier (such as LM393), and adjustable sensitivity via an onboard potentiometer. The module provides a DC‑biased analog output (AO) that follows the sound level and a digital output (DO) that toggles HIGH when the noise exceeds a set threshold.
This sensor is widely used for clap‑control lighting, noise‑activated alarms, and simple sound‑level meters, but it cannot distinguish specific frequencies or complex audio patterns like a full voice‑recognition system.
Components Needed
- Arduino Nano
- Microphone sound sensor module (e.g. KY‑037 / KY‑038 / LM393‑type)
- LED (optional, for sound‑triggered light)
- 220 Ω resistor (for LED)
- Jumper Wires
- Breadboard
Circuit Setup
1. Connect Sound Sensor to Arduino Nano:
Most microphone sound‑sensor modules expose three main pins:
- VCC → 5V on the Arduino Nano.
- GND → GND on the Arduino Nano.
- DO (Digital Output) → any digital pin, commonly D2.
- AO (Analog Output) → any analog pin, commonly A0 (for level‑based control).
If you want a simple sound‑activated LED:
- Connect the anode of an LED to a digital pin (e.g. D3) through a 220 Ω resistor.
- Connect the LED cathode to GND.
How the Sound Sensor Works
When no loud sound is present, the module’s digital output (DO) stays LOW. When a sound (such as a clap or shout) exceeds the threshold set by the onboard potentiometer, the DO pin goes HIGH for a short time. The analog output (AO) continuously varies around half‑VCC, with peaks corresponding to louder sounds, so you can use `analogRead()` to get a measure of the current noise level.
By using either digital or analog mode, you can build clap‑controlled lights, sound‑level meters, or basic alarm systems that act when the module threshold is crossed.
/*
Microphone Sound Sensor with Arduino Nano
(ky‑037 / ky‑038 style module)
*/
// Microphone sound sensor digital output
const int soundPin = 2;
// LED for sound activation
const int ledPin = 3;
void setup() {
pinMode(soundPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("=== MICROPHONE SOUND SENSOR READY ===");
Serial.println("Make a sound or clap to trigger the sensor.");
}
void loop() {
// Read the digital sound sensor state
int soundState = digitalRead(soundPin);
if (soundState == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Sound detected!");
} else {
digitalWrite(ledPin, LOW);
}
delay(50);
}
Instructions
1. Circuit Setup:
Wire the microphone sound sensor module to the Arduino Nano as described in the circuit setup section, taking care that VCC, GND, DO, and AO (if used) are connected to the correct pins.
2. Adjust Sensitivity:
Rotate the onboard potentiometer on the module to increase or decrease the detection threshold. Turn it until the LED (or the module’s built‑in LED) reacts reliably to a clap or shout but not to background noise.
3. Code Upload:
Connect the Arduino Nano to your computer via USB, open the Arduino IDE, paste the provided sound‑sensor code, and upload it to the board.
4. Testing:
Open the Serial Monitor (9600 baud). Make a sound or clap near the microphone; the LED should light and the Serial Monitor should print "Sound detected!".
Using Analog Output for Level‑Controlled Lights
If you want to dim an LED or make a more sensitive sound level meter, you can read the analog output instead of the digital one:
/*
Analog mode: LED brightness following sound level
Use PWM on the LED pin (e.g. pin 3)
*/
const int soundAnalogPin = A0;
const int ledPin = 3;
const int baseLevel = 512; // Around VCC/2 for DC‑bias
const int threshold = 50; // How much deviation to count as sound
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int raw = analogRead(soundAnalogPin);
int diff = abs(raw - baseLevel);
// Map deviation to LED brightness (0–255)
int brightness = constrain(diff, 0, 255);
analogWrite(ledPin, brightness);
// Optional: print to Serial for debugging
Serial.print("Raw: ");
Serial.print(raw);
Serial.print(" Diff: ");
Serial.println(diff);
delay(10);
}
Applications
Clap‑Controlled Lights: Turn on room lights, desk lamps, or other LEDs when a clap or sound is detected, avoiding the need to reach a switch.
Noise‑Activated Alarms: Use the sound sensor to trigger buzzers or relays when loud or sudden noise occurs, useful for security or baby‑monitor‑style projects.
Sound‑Level Meters: Display the analog sound level on an LED bar graph, LCD, or TFT screen to monitor ambient noise and environment quality.
Troubleshooting
- No response to sound? Check that VCC and GND are connected correctly and that the sensitivity potentiometer is not turned too low.
- False triggering in silence? Turn the potentiometer down slightly and avoid placing the sensor near vibrating motors, fans, or loudspeakers.
- LED flickers when sound is detected? Ensure the LED is driven through a current‑limiting resistor and that the sound sensor’s power supply is stable.
Best Practices and Notes
- Position the microphone at an angle away from annoying noise sources so it responds mainly to intentional sounds such as claps or voice commands.
- For better reliability, use the analog output with a small smoothing or averaging routine instead of relying solely on the simple digital ON/OFF.
- Avoid exposing the microphone to water or high‑humidity environments; use a protective grill or enclosure if needed.
Extensions and Ideas
You can extend this project by combining the sound sensor with an LDR so that lights only turn on by clap in darkness, or by using multiple sensors to detect sound direction, or by logging sound levels over time on an SD card for environmental‑noise analysis.