[personal profile] chebe
I've had one of these for a while now. What is it? It's a microphone, with all the added bits necessary (opamp etc) to create a signal loud/strong enough to be read by microcontrollers, and other things. But, I've been having a hard time learning how to use it.

First there was the physical hurdle, is it even connected properly? I eventually grabbed a six-pin header (female on top, like on the Arduino itself) and used three of its pins. VCC goes to 5V, GND to GND, and AUD to Analog In pin 0.

Now I'm struggling with how to read the values. If I just print the readings as fast as the Arduino can handle (by default, meaning no delay()s), I get a range that approximates a nice sine or cosine wave, centered maybe (evaluating by eye) around 510. But what do I do with it?

Well, I've managed loud sudden noise detection, like a bang, a knock, or a loud clap. It's actually rather like an analog version of the push-button switch state from my LED-top.

//You set the previous value to be the sensor value.
previousReading = sensorReading;


//Then you update the sensor value with a new reading.
sensorReading = analogRead(mic);


//You take the difference between the two values.
readingDifference = sensorReading - previousReading;


//You set a desired sensitivity rating, in this case 100.
//If the difference exceeds the sensitivity threshold it's an event, do something.
if(readingDifference > 100)
  {
    numBeats = numBeats + 1;
    Serial.print("Beat ");
    Serial.println(numBeats);
  }


So now I guess I could hook-up those lights that turn on and off with clapping, but there's not much else this would be good for. Maybe a more sensitive version for just pulsing lights with a strong bass-beat in songs? Ideas on a postcard. Have to study more about sound wave analysis to be able to use this sensor data to more advantage.