KY-037 & KY-038 microphone sound sensor with Arduino

How to use a sound sensor module with Arduino, how the sound sensor works & what is working principle of a sound sensor are some questions that may arise in your mind while using a sound sensor with Arduino.

Hello guy! Welcome back to my blog today we are going to see about both KY 037 sound sensor, KY 028 sound sensor and Arduino so let’s begin.

What is Sound Sensor?? 

Sound is an energy wave that is created by the vibration of an object. Sound needs a medium to travel it can be air, water, or solid material. Sound waves consist of the sinusoidal wave where aptitude varies for each sound depending upon the frequency or a sound pitch, or medium it travels. The human ear has an eardrum inside the ears which vibrates when a sound wave hits the eardrum and gives us the sound information (hears a sound). We cannot sound vibration below 20 vibrations per second, for example, we cannot hear the vibration of waving a hand in the air. The human ear can hear sounds from 20 Hz up to about 20 kHz. Cats & dogs can hear sound frequencies higher than humans. They can hear approximately between 40 Hz to 60 kHz. Where BATS can hear more hearing abilities they can hear sound approximately between 9 kHz and to120 kHz which helps them to fly in dark without hitting any obstacles. To detects or sense the presence of sound we required a sound sensor. the sound sensor is also known as s noise sensor.

sound sensor Arduino

The Sound sensor works similarly to our Ears, it senses the sound waves using the diaphragm and converts vibration into electrical signals. We have seen sound sensors in our day-to-day life in consumer electronics, earphones, phones, music systems, microphones, etc.

How does a Sound Sensor works??

Capacitance of Conductor

The sound sensor consists of a capacitor having two parallel plates. Where one plate of the capacitor is fixed and another vibration on sound produces electrical signals.

To understand the working of sound sensors we see the basic of capacitors

 C = εA/d

 C is capacitance, ε is permittivity, dielectric material stores an electric field, A is the parallel plate area, and d is the distance between the two conductive plates.

Charge = capacitance x voltage

Q = C x V

  C = Q/V

Q = (εA / d) x V

  Therefore, d = (εA / Q) x V

           Here you can see if distance d is directly proportional to voltage V.

capacitive sound sensor

If a sound wave hits the diaphragm then it starts to vibrate, the distance between two plates changes, and capacitance changes which generates a voltage proportional to sound wave that has struck the diaphragm.

capacitive sound sensor working principle

This sensor is capable to determine noise levels within DBs or decibels at 3 kHz 6 kHz frequencies. This sensor uses the microphone to sense the sound waves. When a sound is detected by this sensor then an electrical signal is generated corresponding to the sound wave which is fed to the comparator. 

ky-037 & ky-038 sound sensor

The sensor has an LM393 voltage comparator IC and potentiometer. The potentiometer is used to adjust the sensitivity. We can set predefined values which can vary using a potentiometer. The comparator compares both values i.e. value that is sensed by the sound sensor and the predefined value set by the potentiometer. If the value sensed by the sound sensor is less than the predefined value then the sensor will give digital output as 0 or LOW and if the value sensed by the sound sensor is greater than the predefined value then the sensor will digital output as 1 or HIGH. By rotating the knob of the potentiometer clockwise or anti-clockwise, we can change predefined values or adjust the sensitivity of the sensor. When it is set to less sensitive then the sensor needs more sound to get trigged or it will get only get the drive to louder sound or we can say it will only detect greater sound. If we set the sensor to higher sensitivity or increase the sensitivity then the sensor can detect or sense even smaller sounds. As discussed earlier we can set sensitivity through a potentiometer.

The sound sensor has two built-in LEDs. One LED indicates the sensor board module is in an ON state and another LED indicates the signal received by the sensor. It has four pins (Analog Output, Digital Output, Ground, and VCC). The sound sensor has a microphone, LM393 sound sensor, and potentiometer. We have two sound sensors KY-037 and KY-038 to detect the sound. Both these sound sensors are almost the same, the only difference is that KY-037 has a microphone with a higher sensitivity than KY-038. The sound sensor can be sensitive to noise signals produced by the power supply also microphones can also be affected by a false signal caused by the surrounding environment such as wind or metallic vibration.

Ky-037 & ky-038 sound sensors consist of both analog and digital output along with a built-in LED & built-in potentiometer to set the threshold. it also has comparator LM393. By rotating the potentiometer, we can increase sensitivity or threshold value. If the value from the sensor is less than the threshold value then it will read 0 (LOW). If the value from the sensor is more than the threshold then it will read as 1(HIGH). 

Application of sound sensor

  • Home automation using whistle or clap sound
  • Smart Phones
  • Inside libraries turn alarmed if sound reaches higher than the threshold for maintaining silence
  • Security systems
  • In Door cams when sound is detected then turn on the camera
  • Sound level recognition circuit
  • Noise pollution detection circuit
  • Robotics applications
  • Baby monitoring and dork bark detector circuit
  • Basic sound-based RC car

Circuit Diagram

Arduino KY 038 microphone sound sensor module

Connect the ground pin of the ky-038 sensor to the ground pin of Arduino, Analog pin to A2. VCC pin to 5v and digital Signal pin to 9. Also, connect the positive lead of LED to Arduino pin 11.

sound sensor module Arduino

Connect the ground pin of the ky-037 sensor to the ground pin of Arduino, Analog pin to A2. VCC pin to 5v and digital Signal pin to 9. Also, connect the positive lead of LED to Arduino pin 11.

Code -

int digital_Sound_pin = 9;
int analog_Sound_pin = A2;
int Led_pin = 11;
int digital_value;
int analog_value;
void setup() 
{
  Serial.begin(115200);
   pinMode(Led_pin,OUTPUT);
   pinMode(digital_Sound_pin,INPUT);
   pinMode(analog_Sound_pin,INPUT);
}
void loop() 
    {
 digital_value = digitalRead(digital_Sound_pin);
 analog_value = analogRead(analog_Sound_pin);
 Serial.print("Digital_Output :");
 Serial.println(digital_value);
 Serial.print("Analog_Output :");
 Serial.println(analog_value);
 if(digital_value == HIGH){
  digitalWrite(Led_pin,HIGH);
  }
  else{
    digitalWrite(Led_pin,LOW);
    }
   delay(500);
} 

First, initialize the pins of the sound sensor & LED. We have declared a variable name digital_value and analog_value to read both values digital and analog from the same hall sensor. In the void setup, we configure pins as INPUT or OUTPUT. We want to read values from the sound sensor pin so we will declare it as INPUT and LED as OUTPUT. We also configure the baud rate to 115200.

In the void loop, we continuously read values from the sound sensor and store values in variables. if we make a sound or noise close to the sound sensor then the output we get is HIGH or logic 1. here we used LED which gets turned ON when output is HIGH & gets turned OFF when output is LOW.  

Controlling LED by Clap Using Sound Sensor (Arduino Clap sensors)

int soundpin=2;
int Ledpin=9;
int sensorvalue;
boolean lastStatus=false;

void setup() {
 pinMode(soundpin,INPUT);
 pinMode(Ledpin,OUTPUT);
 Serial.begin(115200);

}

void loop() {

  sensorvalue = digitalRead(soundpin); 
  if(sensorvalue==HIGH){

    if(lastStatus==false)
    {
        digitalWrite(Ledpin,HIGH);
        lastStatus=true;
        
    }
    else{
        digitalWrite(Ledpin,LOW);
        lastStatus=false;
    }
  }
 } 

Here we have to declare a Boolean variable that will use as a toggle switch. first, we have declared a Boolean variable as false. when clap sound is detected the sound sensor output will be HIGH, here we have included a condition that if the output of the sound sensor is high then it will check another condition whether a Boolean variable is false or not. if the variable is false we will turn the LED ON and change the value of the Boolean variable to true. then if we clap again then once again the output of the sensor will be HIGH and it will check the Boolean variable if it's true or false if true (from the last previous state) then the LED will be turned OFF and the state of the Boolean variable will change from true to false. In this way LED toggles with help of change in a Boolean variable.    

Conclusion - 

Today we learn about an Arduino sound sensor or Arduino microphone sensor, an analog sound sensor with Arduino, how to use a sound sensor with Arduino, & working principle of sound sensor. sound sensors have wide applications for security systems, voice-operated systems, clap circuits, and various robotics applications.


"I hope you find this IoT blog very helpful to you. In the upcoming lesson, we will see more about IoT sensors till then bye. See you all in my next blog."

Close Menu