Help with digital out on micophone

Ok. So I’m in a pickle. Also, I’m a newbie, so bear with me.

I’m trying to set a activation for a relay using a 10 second sound detection, using a microphone with digital outputs.

Issue being is that the arduino, even when the microphone is held at max volume and the sensor light is illuminated, doesn’t consistently read that the digital output is at “1” instead of “0”. The higher the volume, it seems to help, but I’d rather have it consistent at any volume. Long wires are not an issue, and I’ve got the pentameter right on the cusp of the threshold.

Any advice would be great, and thanks in advance. (I’ve included a picture of the microphone I’m using, as well as a picture of my board.)

int sensorPin = 3;
int ledPin=13;
int sound =0;
int pushPin=9;
int buttonPin=7;
float pressLength_milliSeconds = 0;
float pressLength_milliSecondsmic = 0;
boolean val =0;
unsigned long previousMillis = 0;
const long interval = 1000;
unsigned long time_1 = 0;

void print_time(unsigned long time_millis);

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pushPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(sensorPin, INPUT);
}

void loop() {
sound =digitalRead(sensorPin);
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;

Serial.println (sound);

if ((millis() - time_1) > 4000)
{pressLength_milliSecondsmic = 0;
digitalWrite(ledPin, LOW);}

if (sound==HIGH){
digitalWrite(ledPin, HIGH);
time_1 = millis();
print_time(time_1);
pressLength_milliSecondsmic = pressLength_milliSecondsmic + 100;
Serial.print("micms = ");
Serial.println(pressLength_milliSecondsmic);}

if (pressLength_milliSecondsmic >= 1000) {
digitalWrite(pushPin, HIGH);}

if (pressLength_milliSeconds >= 500) {
digitalWrite(ledPin, HIGH);
digitalWrite(pushPin, HIGH);}

if (digitalRead(buttonPin) == LOW ){
delay (1000);
pressLength_milliSeconds = pressLength_milliSeconds + 100;
Serial.print("buttonms = ");
Serial.println(pressLength_milliSeconds);}

}
}

void print_time(unsigned long time_millis){
Serial.print("Time: ");
Serial.print(time_millis/1000);
Serial.print("s - ");
}

What does the data sheet for the mike board say about the digital output? Did you set the level control to detect a quiet sound.

Paul

Paul_KD7HB:
What does the data sheet for the mike board say about the digital output? Did you set the level control to detect a quiet sound.

Paul

Hiya Paul, thanks for the response. I'm like, a complete newbie, and I don't know what the data sheet is, or where to find it. And I didn't set any level control, outside of the microphone pentameter. How would you do that?

The datasheet is the detailed specifications. Do you have any links or a model number? Reliable suppliers will have all of the details. If you but cheap stuff on eBay, or from 3rd-party Amazon suppliers, etc., you don’t know what you’re getting.

There are (at least) 4 kinds of microphone boards, some of them have multiple functions/outputs.

1 - There are digital microphones with I2C outputs. These have a built-in analog-to-digital converter. I’m pretty sure that’s NOT what you have.

2 - Some have an amplified & biased analog output. These connect to the Arduino analog input and you read the actual audio waveform (biased so you can read the negative half of the waveform). Since the output is biased, with silence it reads about 512 (half of the ADC range). The voltage will “jump around” near 512 and with quiet sound and will jump around between zero and 1023 with very-loud sounds. It’s always “jumping around” even with a constant tone because you are sampling a waveform.

3 - Some have an analog envelope-follower (AKA peak detector). These have an analog DC output where the voltage represents the “loudness”. Silence will read zero and very-loud sounds will read near 1023.

4 - Some have a digital output that reads low (about zero volts) when the signal is below the threshold and high (about 5V when above the threshold).

Issue being is that the arduino, even when the microphone is held at max volume and the sensor light is illuminated, doesn’t consistently read that the digital output is at “1” instead of “0”. The higher the volume, it seems to help, but I’d rather have it consistent at any volume. Long wires are not an issue, and I’ve got the pentameter right on the cusp of the threshold.

I’m not sure what you’re saying… If you have a high/low digital output and you’re on the “cusp of the threshold” you should be able to adjust it so it’s on sometimes and off sometimes.

BTW - That is a multi-turn pot.

DVDdoug:
The datasheet is the detailed specifications. Do you have any links or a model number? Reliable suppliers will have all of the details. If you but cheap stuff on eBay, or from 3rd-party Amazon suppliers, etc., you don’t know what you’re getting.

There are (at least) 4 kinds of microphone boards, some of them have multiple functions/outputs.

1 - There are digital microphones with I2C outputs. These have a built-in analog-to-digital converter. I’m pretty sure that’s NOT what you have.

2 - Some have an amplified & biased analog output. These connect to the Arduino analog input and you read the actual audio waveform (biased so you can read the negative half of the waveform). Since the output is biased, with silence it reads about 512 (half of the ADC range). The voltage will “jump around” near 512 and with quiet sound and will jump around between zero and 1023 with very-loud sounds. It’s always “jumping around” even with a constant tone because you are sampling a waveform.

3 - Some have an analog envelope-follower (AKA peak detector). These have an analog DC output where the voltage represents the “loudness”. Silence will read zero and very-loud sounds will read near 1023.

4 - Some have a digital output that reads low (about zero volts) when the signal is below the threshold and high (about 5V when above the threshold).
I’m not sure what you’re saying… If you have a high/low digital output and you’re on the “cusp of the threshold” you should be able to adjust it so it’s on sometimes and off sometimes.

BTW - That is a multi-turn pot.

Ah, I think I get it! Thank you for the help.