I'm very new to this world, and trying to hack one of my first projects have proven hard without solid documentation or examples to copy like I usually do.

I've got a https://www.gearbest.com/transmitters-receivers-module/pp_366523.html NodeMCU ESP8266 board that I'm trying to pair with a Sound Sensor. I wanted digital and simple solution, but I'm thinking I might need a library to make it work?

The closes examples I've found are DHT11/22-sensors using the DHTlib library.

The Waveshare-Wiki contains the following expample that I've tried to modify without any luck.

int sound_din=2;
int sound_ain=A0;
int ad_value;
void setup()
void loop()

I've also tried to modify/simplify this code to just print the digital output:

#include <ESP8266WiFi.h>

int dig_in=4; //Using D2-pin on my NodeMCU-board
int dig_value;

void setup()

void loop()


This results in varius gibborish and junk. I've seen plenty of various errors, and the board seems to crash quite a lot. I've tried swapping out the NodeMCU and the Sound level sensor with new ones, but still seem to be getting the same problems.

Any pointers? Thanks!

UPDATE: I've gotten further by using the following code from this example:

// Program: Sound Level Measurement   
#include <ESP8266WiFi.h>

int num_Measure = 1280 ; // Set the number of measurements   
int pinSignal = A0; // pin connected to pin O module sound sensor   
long Sound_signal;    // Store the value read Sound Sensor   
long sum = 0 ; // Store the total value of n measurements   
long level = 0 ; // Store the average value   

void setup ()  
  pinMode (pinSignal, INPUT); // Set the signal pin as input   
  Serial.begin (74880);  

void loop ()  
  // Performs 128 signal readings   
  for ( int i = 0 ; i <num_Measure; i ++)  
   Sound_signal = analogRead (pinSignal);  
    sum =sum + Sound_signal;  

  level = sum / num_Measure; // Calculate the average value   
  Serial.print("Sound Level: ");
  Serial.println (level);  
  sum = 0 ; // Reset the sum of the measurement values  

The result is an output that seems to be pretty close to the relative sound level in the room. I've got a couple of issues that I'm still working on:

  1. NodeMCU randomly crashing. The stacks are not exactly alike, but I've copied one of them down below. I've yet to decode this.
  2. Pretty high noise floor. I.e. anything below around 60dB reads as 3/4/5. I've got to test this some more, it might just be the microphone is not sensitive enough.

    Exception (0): epc1=0x40103861 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    ctx: sys sp: 3ffffcd8 end: 3fffffb0 offset: 01a0

    stack 3ffffe78: 3fffc200 00000022 00000000 03c4345f
    3ffffe88: 00000000 4000050c 3fffc278 4010268c
    3ffffe98: 3fffc200 00000022 3ffffeb0 00000000
    3ffffea8: 000002ea 00000000 40000f68 00000030
    3ffffeb8: 0000001e ffffffff 40000f58 00000000
    3ffffec8: 00000020 00000000 3ffe91f0 c06301dc
    3ffffed8: 3ff20a00 c0000000 00003000 00000000
    3ffffee8: 00000058 3fffdab0 00000000 3fffdcc0
    3ffffef8: 3ffe8b88 00000030 00000000 00000000
    3fffff08: 00000020 40101612 3ffe8ae0 40203ebb
    3fffff18: 3fff01ac 40106fb4 00000000 40208a24
    3fffff28: 3ffed518 40222a2d 3ffef904 3ffef900
    3fffff38: 01331819 40105e3e 00000000 00000000
    3fffff48: 60000600 00000100 00000058 00000001
    3fffff58: 4010483a 3ffecc60 3fff01ac 401011a6
    3fffff68: 00000001 00000000 402187a8 40100f73
    3fffff78: 00000000 00000000 40100fae 00000000
    3fffff88: 00000002 3fffdcb0 40203b76 3fffdab0
    3fffff98: 00000000 40202303 3ffe8b88 40000f49
    3fffffa8: 3fffdab0 40000f49 40000e19 40001878

  • 1
    Where did you copy and paste from to get that question title? – Majenko Jan 4 at 21:39
  • Found it. Crosspost from: forum.arduino.cc/index.php?topic=587394.0 – Majenko Jan 4 at 21:52
  • the schematic on the wiki shows that the module has two outputs ..... one is an analog output and the other is digital ..... the digital output is generated by amplifying the analog output by a large amount and clipping the result ..... the digital signal leading and trailing edges probably coincide with the zero crossings of the analog signal – jsotola Jan 5 at 5:23
  • Majenko: did I mess up the title when crossposting? :) @jsotola so I guess I can just as well go with the the analog signal only? I spent a lot of time last night trying to figure this out, and I've gotten a lot further I think. I'm updating the original post. – Mixy Jan 5 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.