You can read this and other amazing tutorials onElectroPeak's official website
OverviewIn 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
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 ArduinoTo 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.
CircuitConnect the sensor to Arduino as the following picture
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);
}
}
}
- 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.
Comments