Microphone Sensor (KY-038)

By Luan Mateus Vick


Introduction

    When microphones were created in 1877, they were primarily used only to transmit sound in speakers or to record music. 137 years later, it is possible to notice that they are more important than ever in our society. They can be found in cellphones, cars, video game consoles, computers and even televisions, and are used for different purposes in each situations.

    However, one of the most recent trends in the uses for microphones is voice control, were users are able to use their voices to control a computer or other electronic device without having to physically interact with it.

    Many "smart homes" use microphone-enabled systems to allow the user to control, for example, a lamp. Inspired by this idea, this tutorial aims to teach how to make a clap-controlled lamp with an Arduino, demonstrating the use of a microphone sensor.

Technical Details

Microphone specifications
  • Frequency range:100 ~ 10,000 Hz.
  • Sensitivity: - 46 ± 2.0, ( 0 dB = 1V / Pa ) at 1K Hz. 
  • Power supply: 5V maximum
  • Minimum Sensitivity to Noise Ratio: 58dB
Microphone dimensions*
  • Diameter: 9.7mm
  • Height: 4.5mm
  • Weight: 0.7 grams

*Dimensions for the microphone only, not the complete microphone module.

Relay specifications

  • 10A 250VAC
  • 10A 125VAC
  • 10A 30VDC
  • 10A 28VDC

Relay dimensions (in millimeters)

      Similar Modules

          There are many different models of microphones available for purchase, with different sensitivities, precision, frequency ranges and more. 

      Example of Use

          The Arduino board is able to analyze certain levels of sound being detected by the microphone, and, if the level is high enough, it sends a signal to the relay, allowing power to flow to the lamp. 

      Materials / Equipment
      Wiring Instructions

          On the microphone, wire the pin named AG to a analog input header on the Arduino board (in this case, A0). After this, wire the pin named G to a ground header on the board, and wire the pin named "+" to a 5V power output header in the Arduino board. Finally, wire the DO pin to a digital output header on the Arduino board (in this case, header 2). On the relay, wire the S pin to a digital header on the Arduino board (in this case, header 1). The "+" pin should be wired to a 5V power output, while the "-" pin should be wired to a ground header.


      Sketch Instructions
        
        After wiring everything up, upload this code to your Arduino board.

      Sketch Code

      \\ Sound-activated lamp with Arduino (Analog mode)

      const int buttonPin = 0; 
      const int ledPin = 1; 


      int buttonstate = 16;
      int ledstate = 0;

      void setup() {

      pinMode(ledPin, OUTPUT); 

      pinMode(buttonPin, INPUT); 
      }

      void loop(){

      buttonstate = analogRead(buttonPin);
      ledstate = digitalRead(ledPin);

      if (ledstate == HIGH && buttonstate > 17) { 
      delay(250);
      digitalWrite(ledPin, LOW); 
      delay(250);
      }
      if (ledstate == LOW && buttonstate > 17) { 
      delay(250);
      digitalWrite(ledPin, HIGH); 
      delay(250);
      }
      }

          In case the microphone is not detecting your sounds properly, try changing its sensitivity, either in the hardware (by rotating a small screw on the blue resistor on the microphone) or in the software (by changing the number 17 in ledstate == HIGH && buttonstate > 17 and on ledstate == LOW && buttonstate > 17 to a different value).

      Try also...

          Instead of using the microphone in analog input, try testing the digital mode. To do this, try this code:

      Sketch Code

      \\ Sound-activated lamp with Arduino (Digital mode)

      const int buttonPin = 2; 
      const int ledPin = 1; 


      int buttonstate = 16;
      int ledstate = 0;

      void setup() {

      pinMode(ledPin, OUTPUT); 

      pinMode(buttonPin, INPUT); 
      }

      void loop(){

      buttonstate = digitalRead(buttonPin);
      ledstate = digitalRead(ledPin);

      if (ledstate == HIGH && buttonstate > 17) { 
      delay(250);
      digitalWrite(ledPin, LOW); 
      delay(250);
      }
      if (ledstate == LOW && buttonstate > 17) { 
      delay(250);
      digitalWrite(ledPin, HIGH); 
      delay(250);
      }
      }


      Resources & Related Links
      Comments