Pages: [1]   Go Down
Author Topic: Recognizing loud sounds.  (Read 1566 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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...

Code:
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 smiley-wink

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
http://wiring.org.co/learning/basics/microphone.html
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:



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 smiley
Logged

Pages: [1]   Go Up
Jump to: