Recognizing loud sounds.

Hello everyone,

I want to build an arduino controlled machine that recognizes if someone is shouting and react to that.
It should messure the the length of the shout.

I thought of something like this:

microphone ->preamp -> arduino
(if sound is going louder than xy start messure Time, if sound is not louder than xy anymore stop messure Time
-> 30% of the messured Time = doing nothing
-> than trigger a Relais for 100% of the messured Time)

I hope you understand that, my english isn't that good on Sundays :slight_smile:

It seems like an easy thing to do to me, is it?!

Ah btw. i want it standalone, without a PC. Dont know if it makes any difference.

You see I am pretty new to arduino, so maybe you know some existing codes that could be used for it? Or just some general advice how to realize the interpreting of the audio in signal etc.

Best Max

Hi Max, welcome where are you from (I can't see in your profile)

Think you have a reasonable idea how you would do it. Have you checked the tutorial section allready, There are several samples that contain code parts that I recognize in your project.

learn how to measure time wilt millis()

Here some code to get started...

void setup()
{
  Serial.begin(115200);
  Serial.println("Soundmeter 0.1");
}

void loop()
{
  // DO MEASUREMENT
  unsigned long startTime= millis();
  while (analogRead(A0) > 300);  // 300 threshold to be tuned  
  unsigned long duration = millis() - startTime;

  Serial.print("duration:\t ");
  Serial.println(duration);

  if (duration > 10000) // 10 seconds minimum value to be tuned
  {
     // wait 30%
     
    // switch on Relay 100%
    
 
  }
}

now it's your turn to finish it :wink:

It seems like an easy thing to do to me, is it?!

No.
Because a microphone gives you the whole audio waveform. It is only the size of the peaks that determin the loudness.
So you have to do one of a few things
Just filter out the peak readings.
Take an RMS value from a number of readings.
Have an envelope detector between your amplifier and the arduino's input.

Grumpy_Mike:

It seems like an easy thing to do to me, is it?!

No.
Because a microphone gives you the whole audio waveform. It is only the size of the peaks that determin the loudness.
So you have to do one of a few things
Just filter out the peak readings.
Take an RMS value from a number of readings.
Have an envelope detector between your amplifier and the arduino's input.

thanks both of you!!!

Is this working for that purpose?

Yes D1, R2 and C2 together form an envelope detector.

Just remembered now and thought i post my final code here:

int sensorValue;

boolean measuring = false;

boolean action = false;

unsigned long startTime;

unsigned long duration = 0;

unsigned long LEDStart;

const int threshold = 600;



void setup()

{ 

  pinMode(12, OUTPUT);      

  Serial.begin(9600);  // sets the serial port to 9600

}



void loop()

{

  sensorValue = analogRead(0);       // read analog input pin 0

  delay(100);      // wait 100ms for next reading

  

  //Messung anfangen falls gerade nicht gemessen wird und die

  //Lautstaerke den Schwellwert ueberschreitet

  if(measuring == false && sensorValue >= threshold)  {

    startTime= millis();

    measuring = true;

  }

  

  //Messung beenden falls gemessen wurde und die Lautstaerke

  //den Schwellwert unterschreitet

  if(measuring == true && sensorValue < threshold) {

    duration = millis() - startTime;

    measuring = false;

  }

  

  Serial.print("sensorValue:\t ");

  Serial.println(sensorValue, DEC);

  Serial.print("duration:\t ");

  Serial.println(duration);

  

  //30% der gemessenen Zeit nichts machen

  delay(0.5*duration);

  

  //LED 100% der gemessenen Zeit aktivieren

  LEDStart = millis();

  while(millis() - duration < LEDStart) {

    digitalWrite(12, HIGH);

    if(!action) action = true;

  }

  if(action) {

    digitalWrite(12, LOW);

    duration = 0;

    action = false;

    delay(10000);

  }

  

    

    

  }

sorry for german comments and maybe not the best style but i think everyone get it anyway :slight_smile: