Cannot get any sensitivity out of microphone module

I'm trying to use a microphone sensor to eventually trigger a stepper motor. Putting the stepper motor functionality aside for a moment, I can't get any sensitivity out of the mic module on it's own. Here's my code:

const int MIC = A9;
int micVal, amplitude, baseline = 512;


void setup() {

  Serial.begin(9600);
  pinMode(MIC, INPUT);
}

void loop() {

  micVal = analogRead(MIC);
  amplitude = abs(micVal - baseline);
  Serial.println(amplitude);
}

I've adjusted the gain potentiometer so that when the room is silent, the returned amplitude is around 2 to 4 in the serial monitor. I'm working on the premise that without sound, the output wave will sit relatively close to the baseline value. The problem is, unless I get about an inch or 2 from the mic and whistle like I'm calling a dog for dinner (in which case it jumps into the hundreds), I get no change at all. I've tried it with 3 different module all with the same result. I am using a 3.3/5V breadboard PSU jumpered to 5V, with the ground tied to the GND on my Mega 2560. My pinout on the module is as follows:

"G" - GND on the breadbord PSU and the MCU

"+" - Breadboard 5V

AO - A9 pin on the MCU

I've tried messing around with the gain potentiometer using different offsets, but no luck. If I tap gently on the mic i get pretty significant changes. I thought at first it was a dead board, but I've tried 2 with identical results. I tried it on digital, and it has the same sensitivity issues. I even pulled the felt off the mic just to see if it would help at all. It did not./Can anybody give me a push on this? Thanks all!

Showing a link to the specifications of the module would be a much better first step. So far, we do not have a clue about the module. Your results seem to indicate it has a digital output when the audio level exceeds some threshold.

Skip the printing. At the glacial baud rate of 9600, you are sampling the microphone and printing only about 100 times per second.

At that low sample rate, what is the chance that a peak value will be caught? The default analogRead() sample rate is about 10,000 per second (if not bogged down by other program code).

What you have seen is all it can do. It is not a high sensitivity mic.
Buy one with an amplifier.

OR

Try measuring the exact baseline value in setup first.

const int MIC = A9;
int micVal, amplitude, baseline;

void setup() {
  Serial.begin(115200);
  pinMode (MIC, INPUT); // superfluous
  delay (10000); // wait for mic to stabilise
  baseline = analogRead (MIC);
  Serial.print(Baseline: );
  Serial.println(baseline);
}

Fair point. Here's the datasheet. There's 2 outputs, DO (Digital Out) and AO (Analog Out). DO will output a 1 until a given volume threshold is detected, then it will invert and output 0. That threshold can be adjusted by the potentiometer. AO will output essentially a sine wave sitting on an offset voltage of 2.5V (5V / 2) with value either above or below that reference. I've been using it in analogue mode.

KY-037.pdf (218.9 KB)

Thank you. Note, the reference does not include a schematic of the board. But it does tell us the adjustable control is the reference voltage for the comparitor, NOT a gain control! Also they hint that the analog output is just the output from the electret microphone. You have to supply any needed amplification.

Same result unfortunately. So here's something weird though. I've tuned the pot so that the ambient output sits as close to zero as I can get. I included the following code:

void loop() {
  micVal = analogRead(MIC);
  amplitude = abs(micVal - baseline);
  if (amplitude > 18) {
    traverse.step(500);
  }

I created the Stepper object and all that, I just didn't show it here. With this code added, when I whistle nothing happens. If I tap the mic with my finger it actuates the stepper, but then it keeps running. If I include the original Serial.println statement, it shows an initial value of around 4-6, then once I tap it, it jumps up to around 30 (and turns the stepper) and stays at 30 even with no noise (doesn'r drop back down to 4-6). If I whistle again, it will go up to around 45ish, then drops back down to 30. It only resets when I kill the power to the module and the MCU.

Doesn't this model have an amplifier? Doesn't the pot adjust the gain on it?

Thanks for the reply. I was going off of this (from the datasheet):

"The sensor has 3 main components on its circuit board. First, the sensor unit at the front of the module which measures the area physically and sends an analog signal to the second unit, the amplifier. The amplifier amplifies the signal, according to the resistant value of the potentiometer, and sends the signal to the analog output of the module."

I thought the ones I have had amplifiers, but either way, I may try a different model. Have you ever used the ones you linked by chance?

Yes, all electret microphones contain a transistor to bias the microphone, since it is a variable resistor. That could also be called an amplifier. It's output will be a few millivolts. But the whole description is suspect when they write that the front of the module measures the area physically!

No, the pot just sets the threshold for the digital output.
Good for a clap-switch, nothing more.

The pot does change analogue idle voltage (baseline).

Try this (untested).

const byte MIC = A9;
int minPeak, maxPeak; // peak values
int rawValue; // peak to peak
int threshold = 1; // 0-1023
unsigned long startMillis;

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

void loop() {
  maxPeak = 0; // reset
  minPeak = 1023; // reset
  startMillis = millis(); // mark
  while (millis() - startMillis < 20) { // measuring time
    rawValue = analogRead(MIC); // take sample
    if (rawValue > maxPeak) maxPeak = rawValue;
    if (rawValue < minPeak) minPeak = rawValue;
  }
  rawValue = maxPeak - minPeak; // final peak to peak value
  if (rawValue > threshold) {
    Serial.print("Trigger level: ");
    Serial.println(rawValue);
    delay(1000); // only when triggered
  }
}

No to both.

No I have not but Adafruit does provide details about how they work.

What level of sounds are you trying to detect?

The other posts are correct, the microphone analog output is not amplified.

It will help to set the internal analog input voltage reference to 1.1V, which gives you about 1 mV resolution.

  void setup() {
  Serial.begin(115200);
  analogReference(INTERNAL1V1);  //for Mega2560 1.1V AREF
}

This module has a gain of 64, and works well: SparkFun Analog MEMS Microphone Breakout - SPH8878LR5H-1 - SparkFun Electronics

The onboard OpAmp adds a bias voltage of 1/2 VCC to the audio signal. When capturing standard sound sources, such as a normal speaking voice a few feet away, the audio (AUD) output signal will register at about 200mV peak-to-peak. This helps provide a cleaner audio signal.

3.3V power only!

What happens if you just kill the power to stepper ?

Not going to work, because the audio is biased on about 2.5volt DC.

According to the schematic, the offset on AO depends on the power supply voltage and the pot setting.