How to Use KY-037 Sound Detection Sensor with Arduino © GPL3+

You’ll learn how to use the KY-037 sound detection sensor with Arduino. You can measure changes in the intensity of sound in an environment.

  • 2,573 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

You can read this and other amazing tutorials onElectroPeak's official website

Overview

In this tutorial, you’ll learn how to use the KY-037 sound detection sensor with Arduino. You can measure changes in the intensity of sound in the environment using this module.

What You Will Learn

  • Introduction to KY-037 sound detection sensor
  • How to use KY-037 sound detection module with Arduino

What is KY-037 Sound Detection Sensor?

This module consists of a sensitive capacitance microphone for detecting sound and an amplifier circuit. The output of this module is both analog and digital. The digital output acts as a key, and it

activates when sound intensity has reached a certain threshold. The sensitivity threshold can be adjusted via the potentiometer on the sensor.

The analog output voltage changes with the intensity of sound received by the microphone. You can connect this output to Arduino analog pins and process the output voltage.

Interfacing KY-037 Sound Detection Module with Arduino

To use this module with Arduino simply connect the supply voltage of the module and, according to your need, connect its analog or digital pins to Arduino.

Here we used analog output.

Circuit

Connect the sensor to Arduino as the following picture

Code

After connecting the circuit, do the following steps:

Step 1: Upload the following code on your Arduino board:

void setup() {
Serial.begin(9600); // setup serial
}
void loop() {
Serial.println(analogRead(A0));
delay(100);
} 

Step 2: Open the Serial Monitor window. Now turn the potentiometer to turn off the LED on digital output. Write down the number displayed in the Serial Monitor immediately after the LED turns off.

Displaying the analog output of the sensor on the chart

Connect the analog output of the sensor to Arduino A0 pin and upload the following code on your Arduino board. Then choose the Serial plotter from Tools menu.

Step 3: Write the number you have noted before in the following code (as threshold variable) and upload the code on your board.

/*
KY-037 Sound Detection Sensor + Arduino
modified on 16 Apr 2019
by Mohammadreza Akbari @ Electropeak
https://electropeak.com/learn/
*/
int sensor_value = 0;
int threshold = 540; //Enter Your threshold value here
int abs_value = 0;
int ledCount = 10; //number of Bargraph LEDs
int bargraph[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // Bargraph pins
void setup() {
Serial.begin(9600); // setup serial
for (int i = 0; i <= ledCount; i++) // Define bargraph pins OUTPUT
{
pinMode(bargraph[i], OUTPUT);
}
for (int i = 0; i <= 9; i++)
{
digitalWrite(i, LOW);
}
}
void loop() {
sensor_value = analogRead(A0);
abs_value = abs(sensor_value - threshold);
int ledLevel = map(abs_value, 0, (1024 - threshold), 0, ledCount);
for (int i = 0; i < ledCount; i++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (i < ledLevel) {
digitalWrite(bargraph[i], HIGH);
Serial.println(i);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(bargraph[i], LOW);
}
}
}

What’s Next?

  • Build a spy device. When the sound reaches a specific threshold, the device starts storing the sound automatically. (You can use modules such as VS1053 to store audio.)
  • If you find this tutorial helpful and interesting please like us on facebook.

Code

Code 1Arduino
void setup() {

Serial.begin(9600); // setup serial

}

void loop() {

Serial.println(analogRead(A0));

delay(100);

}
code 2Arduino
/*

KY-037 Sound Detection Sensor + Arduino

modified on 16 Apr 2019

by Mohammadreza Akbari @ Electropeak

https://electropeak.com/learn/

*/

int sensor_value = 0;

int threshold = 540; //Enter Your threshold value here

int abs_value = 0;

int ledCount = 10; //number of Bargraph LEDs

int bargraph[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // Bargraph pins

void setup() {

Serial.begin(9600); // setup serial

for (int i = 0; i <= ledCount; i++) // Define bargraph pins OUTPUT

{

pinMode(bargraph[i], OUTPUT);

}

for (int i = 0; i <= 9; i++)

{

digitalWrite(i, LOW);

}

}

void loop() {

sensor_value = analogRead(A0);

abs_value = abs(sensor_value - threshold);

int ledLevel = map(abs_value, 0, (1024 - threshold), 0, ledCount);

for (int i = 0; i < ledCount; i++) {

// if the array element's index is less than ledLevel,

// turn the pin for this element on:

if (i < ledLevel) {

digitalWrite(bargraph[i], HIGH);

Serial.println(i);

}

// turn off all pins higher than the ledLevel:

else {

digitalWrite(bargraph[i], LOW);

}

}

}

Comments

Similar projects you might like

Easy Motion and Gesture Detection by PIR Sensor & Arduino

Project tutorial by ElectroPeak

  • 59,979 views
  • 13 comments
  • 290 respects

Sound Sensor Activated LEDs with LCD for Sound Level Data!

Project tutorial by HeathenHacks

  • 6,381 views
  • 5 comments
  • 17 respects

Smoke Detection using MQ-2 Gas Sensor

by Aritro Mukherjee

  • 309,332 views
  • 51 comments
  • 194 respects

Coolest Motion Detection Sensor Ever

by remnis

  • 15,016 views
  • 3 comments
  • 12 respects

Alcohol Detection Sensor

by Yashik Ibrahim

  • 7,898 views
  • 3 comments
  • 9 respects
Add projectSign up / Login