Weird average signal voltage dropping minute by minute

I recently bought a Grove sound sensor from the Arduino Official Store and connected it to Arduino Mega 2560. I wanted to measure the mid voltage I'm getting in silence and surprisingly found out that it is dropping as minutes go by.

It starts at 140 and then eventually goes down to 61, rises to 76 and start decreasing again ...

Here is the code that I'm using:

void loop () {
        static unsigned long cnt = 0;
        static unsigned long long sum = 0;

        sum += analogRead (0);
        if (++cnt == 10000) {
                Serial.print ("soundMid = "); Serial.println ( (float) sum / (float) cnt );
                cnt = 0;
                sum = 0;
        }
}

Does anyone have any suggestions on how to overcome this?

Please show your entire code.
Are you using a grove shield?
If not how is the sensor connected?

The entire code is a messy work in progress right now. So I kept only the essential part in the sketch to demonstrate the problem:

void setup () {
        Serial.begin (9600);
}

void loop () {
        static unsigned long cnt = 0;
        static unsigned long sum = 0;

        sum += analogRead (0);
        if (++cnt == 10000) {
                Serial.print ("soundMid = "); Serial.println ( (float) sum / (float) cnt );
                cnt = 0;
                sum = 0;
        }
}

The connection is pretty straightforward too:

I would try to put a resistor (10/22/33 kohm, whatever you have available) between A0 and GND.

Ciao, Ale.

So what is the purpose of your system?
The grove module can only detect how loud something is and does not output the actual audio signal.

I did try with 2K, 20K and 300K, they all seem sto stabilize the output but oslo brings it down to 8, which is too low.

Thank you anyway.

Hi, @bojan_jurca

Have you looked here;

Use the sample code and see if the plot they show is what you need.

Tom.... :smiley: :+1: :coffee: :australia:

I've got the feeling that it actually detects sound through analog output (AO). The signal was rather poor but I thought this was because of the low sampling rate (9 kHz). Before addressing this issue I noticed that I'm already having a problem with the input.

I want to build a neural network on Arduino Mega that would recognize claps. I'm aware that there are easier ways but I'm doing this just for fun.

Thank you, but what I need to do is extract the sound from analog input, which can easily be done by (analogRead (0) - soundMid). The problem that I'm having is that soundMid should be a constant but it drops a lot in, say 10 minutes of operation.

Well, basically it can detect any loud noise but you can't distuinguish between a clap or say a jackhammer. You just need to set a threshold for the analog input. Maybe anything over 250 is a clap (or other loud noise).

Did you try a resistor like @ilguargua suggested?

Well, this is the point - distinguishing a clap from other loud noises (dog barks for example). Beside amplitude there are other sound features that can be used, like signal zero-crossings, distribution of sound energy through time, ... This is why I need to get correct audio samples first.

I did try different resistors but still couldn't get a good audio recording. I found another microphone in my drawer that seems to work though.

You can't with the grove sensor

Is this your sensor. This diagram.

The output seems AC coupled (220n cap).
That means that the Arduino input is floating (for DC).
One way to fix this is to mid-bias your analogue input mid-voltage with two 1Megohm resistors. One from pin to ground and one from pin to 5volt.
Leo..

This is it. Thank you!