NodeMCU with digital sound sensor - Can't find examples or good documentation

Hi,

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 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()
{
  pinMode(sound_din,INPUT);
  pinMode(sound_ain,INPUT);
  Serial.begin(9600);
}
void loop()
{
  ad_value=analogRead(sound_ain);
  if(digitalRead(sound_din)==LOW)
  {
    Serial.println("Noise!");
    Serial.println(ad_value);
  }
  else
  {
    Serial.println("Quiet!");
  }
  delay(500);
}

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()
{
  pinMode(dig_in,INPUT);
  Serial.begin(115200);
}

void loop()
{

  Serial.println(digitalRead(dig_in));
  
  delay(1000);
}

This results in:

 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

Using 9600 baud seems to result in a memory failure.

Any pointers? Thanks!

Gonna bump this.

Guess the analog output of the sensor could be used instead - potentially with an ADC. But I dont really know where to start with that either.