Guide for Microphone Sound Sensor with Arduino

This post shows how to use the microphone sound sensor with the Arduino board.

The Microphone Sound Sensor

The microphone sound sensor, as the name says, detects sound. It gives a measurement of how loud a sound is.

There are a wide variety of these sensors.  In the figure below you can see the most common used with the Arduino.


At the leftmost side, you can see the KY-038 and at the right the LM393 microphone sound sensor.

Both sensor modules have a built-in potentiometer to adjust the sensitivity of the digital output pin.

Where to buy?

You can go to Maker Advisor and find the sensor’s best price.

Pin wiring

Wiring your sensor to the Arduino is pretty straightforward:

Pin Wiring to Arduino
A0 Analog pins
D0 Digital pins

If you’re using the LM393 module, you should connect the OUT pin to an Arduino digital pin.

Example: Sound Sensitive Lights

In this example, a microphone sensor will detect the sound intensity of your surroundings and will light up an LED if the sound intensity is above a certain threshold.

Parts required

For this example you’ll need the following components:

You can use the preceding links or go directly to to find all the parts for your projects at the best price!


Assemble all the parts by following the schematics below:



Upload the following code to your Arduino board.

 * Rui Santos 
 * Complete Project Details

int ledPin=13;
int sensorPin=7;
boolean val =0;

void setup(){
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin (9600);
void loop (){
  val =digitalRead(sensorPin);
  Serial.println (val);
  // when the sensor detects a signal above the threshold value, LED flashes
  if (val==HIGH) {
    digitalWrite(ledPin, HIGH);
  else {
    digitalWrite(ledPin, LOW);

View raw code


After uploading the code, you can clap next to the sensor. If the LED is not lighting up, you need to change the sensor sensitivity by rotating the potentiometer.


You can also adjust the sensitivity so that the LED follows the beat of a certain music.

Add more LEDs for a more spectacular effect!

Wrapping up

I hope you’ve found this guide useful.

What ideas do you have to use the sound sensor module?

Let me know by posting a comment down below.

If you’d like to know more about arduino sensor modules, make sure you take a look at the following posts:

Thanks for reading.

Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

39 thoughts on “Guide for Microphone Sound Sensor with Arduino”

  1. Hi.
    I know this is a really old post, but I’ve built the circuit as described … but watching the serial output the level never drops below 1, so the led won’t go off…on the microphone both leds are lit, is that right?

    Thanks in advance

    • Hi Andy.
      That example outputs 1, if the sound levels are above a certain threshold, and 0, if they are below.
      If you are always getting 1, it means that your threshold is too low.
      You need to adjust the threshold of your sensor by rotating the potentiometer at the back.
      I made this tutorial a long time ago, but if I can remember, one LED indicates the sensor is being powered, and the other indicates the digital output. So, if you are always getting 1, the two LEDs on the sensor are lit. If you get 0, the second LED should be off.
      Alternatively, if your sensor has an analog output pin, you can read that pin instead using the analogRead() function. You’ll get varying values between 0 and 255 depending on the sound intensity.
      I hope this helps 🙂

    • Hi, I was facing the same problem but got fixed by doing what Sara Santos said. I.e. rotating the potentiometer screw anti-clockwise until ‘LED2’ on module turned off. No need to connect via Arduino while doing all this threshold setting module itself turn LED2 according to the threshold.

  2. What should one do, if I wanted to do the same, but instead of turning on a led, turning on a fan? considering the amperage differences and connections

  3. I have been doing something alike but with a led strip but my problem is that the sensor works fine on its own(it returns 1 when there is sound)but when i connect the led the values readed by the sensor change and it just returns 1,any ideas?

  4. my problem is that the sensor works fine on its own(it detects sound) but when i connect the led it just keeps reading 1s

    • Hi Ramon.
      Have you experimented controlling the module and the LED individually? Did they work fine?
      Without further information, it is very difficult to understand what is going on.

  5. Hello, can I ask how to detect only one noise/sound in this device? And all the unnecessary noise will be blocked? Specifically, the device will only detect the cry of a baby. Please help me. I would really appreciate it. SO MUCH!

    • Hi Rachell.
      This sensor is not suitable for what you want to do.
      It simply outputs a value based on the sound intensity. It can’t distinguish between different sounds.

  6. Hello.
    I have a system in a lab that monitors CO2 levels in tanks, and when they get too low it throws an audible-alarm (High -pitched & very high-volume piezo). I am trying to use this build to listen for this alarm and send an email if it does.

    For this, using your excellent tutorial as a base, I simply added a +1 counter for high values. Low resets counter to 0. This is to make sure a cough or bang doesn’t trigger an email.

    My issue is that the value is not consistent when the alarm is sounding (this thing is LOUD). The value jumps high/low without a pattern. The alarm is also very high pitched. Could this be a frequency problem?

  7. You did this project with an unique led but, what if we want to do the same but with a led stripe and we want to add some effects like rainbow, fade, blink…? I’m looking for an example of this to see how is the code and to make my own code for Christmas ilumination 🙂

  8. Hi Sara,
    What should I do if LED2 never turns off no matter how far left or right I turn the screw? Using the serial port reader I see the values change as I turn the screw. I thought they were only supposed to go to 255. I am up to 287.

    Let me know. Thanks for your help.

  9. Would you please recommend a sound sensor that has two potentiometers, one for gain and one for threshold.

    I found this:

    but I can’t find where to buy it separately.

  10. Is there any way to control a servo with the 4 pin sensor? I’ve been trying to make a light switch but I am new to arduino and do not know much.

  11. Hi,
    If I want to turn on 2 different colored led according to different sound levels, would that be possible with these modules, by just changing the code?

  12. Is it possible to use that long module for voice recognition?
    I want to make voice control, and I already have this sensor

  13. I have had a smimilar issue extracting the data to ardino module.
    -with 5V power supply the counts were varying from 1009~1023.
    -with 3.3V power supply the counts were in the range of 610~640

    I connected an scope and found out the MIC module gives an AC outputput of 340mV max sitting over DC signal of 3.3(at 5V supply) and 1.7(at 3.3Vsupply).

    On thing was very clear that However the MIC is giving and out put, we need to consider the analoag ref. voltage, for an ADC the input can never be higher than Vref. i.e. 2.56V.So 5V suppy is not going to work. Also if 1.1 Vref is selected the ADC will remain saturaed alaways at 1023 and won’t work.
    Also consider a need to subtruct and offset of 1.7V while working with 3.3V supply.

    As a summary,
    1- Set Vref of Arduino ADC module to 2.56V
    2- Use 3.3V supply for VMA309 sound sensor
    3- Consider a DC offset of 640 counts approx and the actual voice signal will be sitting on this offset value. May need to decouple in a software code.
    4- Set a VMA309 sound sensor module threshold at a reasonable point to capture the full spectrum of voice.
    5- The delay(ms) in a code shall be removed to get max capture rate or Set an ADC in a free running mode to caputure at max sampling rate(15KSPS for ATmega2560).

  14. SOMEBODY KNOW rge curve of frequebcy of these microphone
    is it able to go from 50Hz to more then 2kHz

    the curve llok like very bad
    no qY TO AEE IT


Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.