Search code examples
arduinoiotmicrophoneesp8266nodemcu

Using a "big sound" module with arduino to create a decibel meter


I am trying to create a sound meter to measure the decibels in a room and I am currently using a nodemcu 12e as I want to insert those measures to a row in a mySQL server and a "big sound module" (https://tkkrlab.nl/wiki/Arduino_KY-038_Microphone_sound_sensor_module).

Sound detection schematics

The only thing I have achieved so far is to get the raw values of the sensor, as they don't seem to change, although I have tried to adjust the gain turning the screw in the microphone, with no result, as it seems to stay in the same values even when playing loud music.

It seems to react to loud noises, and clapping makes the output to spike up - allowing me to control that lighting up the connected led:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "yourssid";
const char* password = "yourpass";

ESP8266WebServer server(80);

const int led = 13;

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = D7; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup(void){
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  });

  //SETUP SOUND SENSOR 
  pinMode (ledPin, OUTPUT);
}

void loop(void){
  sensorValue = analogRead (sensorPin);
  Serial.println (sensorValue);//, DEC);
  if (sensorValue > 100){
    digitalWrite (ledPin, HIGH);
    delay (1000);
    digitalWrite (ledPin, LOW);
  }
}

I am reading the analog value of the sensor and I tried to get the lower values possible as seen I was trying to calibrate the mic. The values I am constantly getting are between 19 and 20:

Obtained values

As you can see, on clapping I get a spike of the value.

The thing is that the values don't change at all when loud music is playing, only getting different values when it detects a loud noise (like clapping). How can I change the code or system to get the values in decibels?


Solution

  • You might not get this running with this microphone module.

    The mdule act as a switch. The switching threshold is set by the potentiometer on board of the microphone module.

    What you would need is a low-level amlified microphone. Then you would get an input range from 0 (no noise) to 1023 (loud noise). This value then could be mapped to decibel. But again - not with this module.

    Regards Harry