Skip to content

How to Use KY-037 Sound Sensor to Turn On LED using Arduino

In this tutorial, you are going to learn how to connect the KY-037 sound sensor using an Arduino. We will go over the components needed for this tutorial and see how we can leverage the sound sensor to trigger other functionality.

This tutorial is intended to be beginner-friendly with thorough explanations guided with diagrams and examples to help you understand the KY-037 sound sensor, showing you how we can turn on LED lights with Arduino whenever the sound sensor detects a sound and transmits digital or analog signals to Arduino.

What Materials You Will Need

Hardware

This is the list of all components needed in this tutorial.

Set of 5mm LED Lightsx 1Amazon
Breadboardx 1Amazon
Set of Jumper Wiresx 1Amazon
Arduino Uno R3x 1 Amazon
Arduino UNO USB Data Sync Cablex 1Amazon
Set of 220 Ohm Resistorsx 1Amazon
KY-037 Sound Sensorx 1 Amazon

However, if you like learning electronics and Arduino, I recommend getting the following starter kit which has all the elements for this tutorial.

ELEGOO UNO R3 Project Most Complete Starter Kit w/Tutorial Compatible with Arduino IDE (63 Items)x1 Amazon

Note: This kit uses ELEGOO Uno R3 instead of Arduino Uno R3, which is a replica of Arduino Uno R3 and is compatible with Arduino IDE.

Software

Arduino IDE

What is the KY-037 component?

The KY-037 is a microphone sound sensor module that sends an analog and digital signal whenever the sensor detects a sound.

KY-037 Specifications

The KY-037 has the following parts:

  • AO or Analog Output Pin: Emits an analog signal based on the sound detected.
  • DO or Digital Output Pin: Emits a digital signal based on the sound detected in comparison to the reference level.
  • G or Ground Pin
  • + or Input Voltage which can be between 3.3V and 5V
  • LED 1: Shows the sensor is powered with voltage
  • LED 2: Shows a sound ahas been detected.
  • Potentiometer: Adjusts the resistance value or reference level.
KY-037 Parts

Adjusting KY-037 sound sensor sensitivity

To adjust the sensitivity of the KY-037, locate the potentiometer and use a screwdriver to:

  • Turn the potentiometer clockwise to increase sensitivity. Hence, the resistance value in the potentiometer will decrease.
  • Turn the potentiometer anti-clockwise to reduce sensitivity. Hence, the resistance value in the potentiometer will increase.
Adjusting KY-037 sound sensor sensitivity

Connect KY-037 sound sensor using digital output to turn on LED lights using Arduino

In this first tutorial, we are going to build a circuit to turn on LED lights based on the digital signal emitted by the KY-037.

Breadboard Diagram

Let’s start building the circuit based on the following diagram.

Breadboard Diagram – Sound Sensor KY-037 connected to Arduino using digital output

Note: Unfortunately, we couldn’t find an image of the sound sensor with 4 pins when designing the diagram. However, notice the KY-037 pins used in this circuit are:

  • +: pin receiving the voltage to power the sensor. In this circuit, Arduino 5V pin is providing the power supply
  • G: pin connected to ground
  • DO: pin connected to the digital pin 2 of Arduino
  • AO: pin NOT used in this circuit

Finally, Arduino digital pins 3 – 9 are each connected to a 220Ω resistor to drop the voltage to prevent burning the connected LED light.

Upload the Code

If you haven’t installed Arduino IDE on your computer, download it and install the software.

Once installed, open the software and create a new project by clicking on File on the menu. Then, select the New option.

Now, copy the following code and paste it into the Arduino IDE project. Inside the Arduino IDE, click on the Verify option to make sure there are no errors in the code.

/*
    How to Use KY-037 Sound Sensor using digital signal to Turn On LED using Arduino 
    
    For more guides and tutorials: https://www.thecircuitmaker.com
*/

int digitalPin = 2;

void setup(){
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(digitalPin, INPUT);
}

void loop(){
  int digital = digitalRead(digitalPin);

  if (digital == HIGH )
  {
    digitalWrite (3, HIGH);
    digitalWrite (4, HIGH);
    digitalWrite (5, HIGH);
    digitalWrite (6, HIGH);
    digitalWrite (7, HIGH);
    digitalWrite (8, HIGH);
    digitalWrite (9, HIGH);
  }
  else
  {
    digitalWrite (3, LOW);
    digitalWrite (4, LOW);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    digitalWrite (7, LOW);
    digitalWrite (8, LOW);
    digitalWrite (9, LOW);
   }
}

Finally, upload the code to Arduino. To do so, make sure to have the Arduino connected to your computer using Arduino UNO USB Data Sync Cable. Then, go to the Arduino IDE and click on the menu option Sketch and select the option Upload.

Understanding the Code

First, we define a variable called digitalPin to store the digital pin number receiving the digital signal of the sound sensor.

int digitalPin = 2;

In the setup function of the code, we configure the digitalPin as INPUT mode using the pinMode function. In Arduino, you can set up different pin modes: INPUT, OUTPUT, or INPUT_PULLUP. We use the INPUT mode to configure the digitalPin to receive signals.

Also, notice how we set pins 3 through 9 as OUTPUT so we can later emit a voltage to the LED lights.

void setup(){
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(digitalPin, INPUT);
}

Finally, in the loop section, we program the logic that turns on and off the LED light based on the value of the digital signal received from the sound sensor.

void loop(){
  int digital = digitalRead(digitalPin);

  if (digital == HIGH )
  {
    digitalWrite (3, HIGH);
    digitalWrite (4, HIGH);
    digitalWrite (5, HIGH);
    digitalWrite (6, HIGH);
    digitalWrite (7, HIGH);
    digitalWrite (8, HIGH);
    digitalWrite (9, HIGH);
  }
  else
  {
    digitalWrite (3, LOW);
    digitalWrite (4, LOW);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    digitalWrite (7, LOW);
    digitalWrite (8, LOW);
    digitalWrite (9, LOW);
   }
}

The digitalWrite function determines whether to emit 0V or 5Vs from a specific pin.

  • When we use the digitalWrite function using HIGH, it means the voltage coming out from a specific pin number will be 5V.
  • When we use the digitalWrite function using LOW, it means the voltage coming out from a specific pin number will be 0V.

Result

Depending on the resistance value set in the potentiometer, the LED lights will automatically be turned on or off. If the LED lights are on, decrease the sensor sensitivity by adjusting the potentiometer until the LED lights turn off.

Once the sensor sensitivity is adjusted, feel free to make noise nearby the KY-037’s microphone to see if LED lights start blinking. In our case, we played music close to the circuit to see how the LED lights turn on and off based on a song’s beats, and the results varied based on the song we played. Luckily, we found a good song, and with a little bit of sensitivity adjustment of the sound sensor, we got good results, which you can check out in the following video.

Final result after connecting KY-037 sound sensor with Arduino pins to turn on LED lights

Connect KY-037 sound sensor using analog output to turn on LED lights using Arduino

In this second tutorial, we are going to build a similar circuit to turn on and off LED lights using the KY-037 sound sensor. In this case, we are going to use the analog output of the KY-037.

Breadboard Diagram

Check out the following diagram to build the circuit. If you built the circuit where the KY-037 sensor uses the digital output, you will fill find almost all connections remain the same.

Breadboard Diagram – Sound Sensor KY-037 connected to Arduino using analog output

Note: Unfortunately, we couldn’t find an image of the sound sensor with 4 pins when designing the diagram. However, notice the KY-037 pins used in this circuit are:

  • +: pin receiving the voltage to power the sensor. In this circuit, Arduino 5V pin is providing the power supply
  • G: pin connected to ground
  • DO: pin NOT used in this circuit
  • AO: pin connected to the analog pin 5 of Arduino

Finally, Arduino digital pins 3 – 9 are each connected to a 220Ω resistor and a LED light.

Upload the Code

Now, copy the following code and paste it into the Arduino IDE project. Inside the Arduino IDE, click on the Verify option to make sure there are no errors in the code.

/*
    How to Use KY-037 Sound Sensor using analog signal to Turn On LED using Arduino 
    
    For more guides and tutorials: https://www.thecircuitmaker.com
*/

int analogPin = A5;

void setup(){
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(analogPin, INPUT);
}

void loop(){
  int analog = analogRead(analogPin);
  Serial.println(analog);
  
  if (analog >= 500)
  {
    digitalWrite (3, HIGH);
    digitalWrite (4, HIGH);
    digitalWrite (5, HIGH);
    digitalWrite (6, HIGH);
    digitalWrite (7, HIGH);
    digitalWrite (8, HIGH);
    digitalWrite (9, HIGH);
  }
  else
  {
    digitalWrite (3, LOW);
    digitalWrite (4, LOW);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    digitalWrite (7, LOW);
    digitalWrite (8, LOW);
    digitalWrite (9, LOW);
  }
}

After verifying there are no errors, upload the code to Arduino. To do so, make sure to have the Arduino connected to your computer using Arduino UNO USB Data Sync Cable. Then, go to the Arduino IDE and click on the menu option Sketch and select the option Upload.

Understanding the Code

The code is very similar to the code used to connect the turn on LED lights based on the digital signal emitted by the sound sensor. In this case, we are defining the variable analogPin to store the analog pin value.

Then, inside the setup function, we define the analogPin with a pin mode of INPUT.

Finally, in the loop section, we read the analog value of the analogPin using the analogRead function and compare it against a reference value which determines whether to turn on or off the LED lights.

Notice we printed the analog value using Serial.println(analog);. In this way, whenever we upload the code to Arduino, we can check logs of the value emitted by the analog output of the sound sensor whenever there is no sound.

To check the logs, go to the top menu of Arduino IDE, select Tools. Then, click on Serial Monitor. Make sure to do this whenever Arduino is connected to the computer and the code is uploaded. You will immediately see numbers displayed.

As you adjust the KY-037 potentiometer, these analog values will change. Adjust the potentiometer until you see the numbers are below the reference number used in the code, which is 500.

Conclusion

In this tutorial, you learned about the KY-037 sound sensor and how to connect it to Arduino whether you use the digital pin or the analog pin to receive sensor signals. While the final result of the circuit was to turn on and off LED lights based on the sound sensor, now you can get a better idea of how devices, such as cameras can send alert notifications based on sound detection.

Did you like this article?

I hope this article was not only helpful but also educational. If you liked it, share this article with friends who are interested in electronics and enjoy doing fun projects.

If you have any doubts, questions, or run into issues while following this tutorial, don’t hesitate to leave a comment in the section below.

Note that comments are held for moderation to prevent spam.