Sound Sensor - Value keeps rising over time

Hi,

i use the Grove Sound Sensor and i notice that the value keeps rising.

Its an Arduino Wifi Rev2, with the Grove Shield v2 and Grove Sensors



Does anyone have an idea why this happens? Is it the code or the sensor?



Here is a graph: i.imgur.c o m/92BqrHy.png (remove whitespace - i cant post pictures yet)



And this is my full sketch:
[code]// WIFI
#include <SPI.h>
#include <WiFiNINA.h>
#include “arduino_secrets.h”
#include <WiFiUdp.h>
#include “DHT.h”
WiFiUDP udp;
int status = WL_IDLE_STATUS; // the Wifi radio’s status

// Network
IPAddress dns(8, 8, 8, 8);
IPAddress influxserver(redacted);
const int influxport = 8090;
unsigned int localport = 8080;

// DHT22
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);

// Digital Light Sensor
#include <Digital_Light_TSL2561.h>
#include <Digital_Light_ISL29035.h>
#include <Wire.h>

void setup() {
Wire.begin();

Serial.begin(9600);
while (!Serial) {
;
}

// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println(“Communication with WiFi module failed!”);
while (true);
}

while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(WIFI_SSID);
status = WiFi.begin(WIFI_SSID, WIFI_PASS);

delay(5000); // wait 5 seconds for connection

}
Serial.println(“You’re connected to the network”);
WiFi.setDNS(dns);

delay(10000);
dht.begin(); // Init DHT22
TSL2561.init();
udp.begin(localport);
}

void loop() {
//delay(1000);
String tempLine, humLine, soundLine, lightLine, temperature, humidity, sound, light;

// DHT22 Temperature
temperature = String(getTemperature(), 2);
if (temperature)
{
tempLine = String(“temperature value=” + temperature);
//Serial.println(tempLine);

String beginpacket, printpacket, endpacket;
udp.beginPacket(influxserver, influxport);
udp.print(tempLine);
udp.endPacket();

}

// DHT22 Humidity
humidity = String(getHumidity(), 2);
if (humidity)
{
humLine = String(“humidity value=” + humidity);
//Serial.println(humLine);
udp.beginPacket(influxserver, influxport);
udp.print(humLine);
udp.endPacket();
}

// Sound
sound = String(getSound(), 2);
if (sound)
{
soundLine = String(“sound value=” + sound);
//Serial.println(soundLine);
udp.beginPacket(influxserver, influxport);
udp.print(soundLine);
udp.endPacket();
}

// Light
light = String(getLight());
if (light)
{
lightLine = String(“light value=” + light);
//Serial.println(lightLine);
udp.beginPacket(influxserver, influxport);
udp.print(lightLine);
udp.endPacket();
}
}

float getTemperature() {
float t = dht.readTemperature();
if (isnan(t))
{
Serial.println(“Failed to read Temperature from DHT22”);
return 0;
}
else
{
return t;
}
}

float getHumidity() {
float h = dht.readHumidity();
if (isnan(h))
{
Serial.println(“Failed to read Humidity from DHT22”);
return 0;
}
else
{
return h;
}
}

float getLight() {
int l = TSL2561.readVisibleLux();
if (isnan(l))
{
Serial.println(“Failed to read Light value”);
return 0;
}
else
{
return l;
}
}

float getSound() {
const int pinAdc = A0;
long sum = 0;
for (int i = 0; i < 32; i++)
{
sum += analogRead(pinAdc);
}

sum >>= 5;

if (isnan(sum))
{
Serial.println(“Failed to read Sound”);
return 0;
}
else
{
return sum;
}
}[/code]

Does anyone have an idea why this happens? Is it the code or the sensor?

Hello,

It looks that there is no problem with your code.

I suggest you test the official example of the sound sensor to see if the phenomenon still happens. Then you can find if there is a problem with your hardware.

Your experiment lasted half an hour, so although the ambient noise has changed, it might be invisible for the human. And the value you read is right.