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.

sound-sensor

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
GND GND
VCC 5V

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 MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematics

Assemble all the parts by following the schematics below:

microphone-sound-sensor_bb

Code

Upload the following code to your Arduino board.

/*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
*/

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

Demonstration

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.

demo-gif

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 program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

20 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.
      Regards,
      Sara

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.