4

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?

PayToPwn
  • 1,238
  • 1
  • 16
  • 29

2 Answers2

1

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

Harald
  • 26
  • 1
1

To read a stream of audio signal via analog0 input you need a board that has an analog output. The board you're using has a Digital output which outputs a signal whenever it's threshold it's exceed the limit you set on the potentiometer (yes the potentiometer you were moving just set the limit when the microphone will output a digital pulse).

So you have you should purchase another microphone like this one.

The one you have only tells you if there is sound or no sound.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • Hey there, even with your suggested mic (with analog output), I am still getting same results as author of this question, constant stream of some value, that changes only when I directly tap fingers on mic. Any advice? – Pirozek Mar 10 '19 at 22:59
  • Maybe the sensibility of the microphone is set to low. You have to adjust it by turning the potentiometer that goes with the board (usually a blue box with a screw on top). Which mic model are you using? – Diego Cabral Mar 11 '19 at 19:33
  • I am using KY-038 with analog output. Tried to turn potentiometer but in only changes what number appears in constant stream of values :( – Pirozek Mar 11 '19 at 23:08