Home Code KY038 Microphone Module and Arduino example

KY038 Microphone Module and Arduino example

by shedboy71

The ky-38 sound sensor is a very basic sound level detector module which features an electric condenser microphone. It is part of  a sensor kit that can be purchased and the main part of the module is an LM393 comparator. There are 2 LEDs on board, one is for power and the other indicates when the sensor reaches a certain value

The board has 2 outputs

  1. AO, analog output, real-time output voltage signal of the microphone
  2. DO, when the sound intensity reaches a certain value, the output goes high

The sensitivity can be adjusted via the potentiometer on the module

Here is a schematic of the module

Connection

This is the basic connection of the Ky-038 module to an Arduino Uno

 

Basic Example

[codesyntax lang=”cpp”]

int soundPin = A0;
int sensorValue = 0;

void setup () 
{
Serial.begin (9600);
}

void loop () 
{
sensorValue = analogRead (soundPin);
Serial.println (sensorValue, DEC);
delay (1000);
}

[/codesyntax]

Output

Open the serial monitor and make noise near the microphone, you should values – the higher the value the louder the noise

165
28
27
29
27
16
228

Another Example

This example will switch on the on board Arduino LED if the analog value exceeds 200.

[codesyntax lang=”cpp”]

int soundPin = A0;
int ledPin = 13;
int sensorValue = 0;
 
void setup () 
{
  Serial.begin (9600);
  pinMode (ledPin, OUTPUT);
}
 
void loop () 
{
  sensorValue = analogRead (soundPin);
  Serial.println (sensorValue, DEC);
  //if sensor goes above max light led (could be buzzer)
  if(sensorValue > 200)
  {
    digitalWrite (ledPin, HIGH);
    delay (1000);
  }
  //switch off LED
  digitalWrite (ledPin, LOW);
  delay (1000);
}

[/codesyntax]

 

Links

A very low cost module, comes in under $0.50

KY-038 4pin Mini Voice Sound Detection Sensor Module Microphone Transmitter

The set of sensors cost about $10

37 IN 1 sensor kit for Arduino starter kit high-quality (Works with Arduino Boards) landzo

Share

You may also like

1 comment

Leave a Comment