Microphone Sound Detection Sensor Module for Arduino



Microphone Sound Detection Sensor Module for Arduino

http://dx.com/p/arduino-microphone-sound-detection-sensor-module-red-135533

/* Test of Noise Level Sensor SKU 135533 http://dx.com/p/arduino-microphone-sound-detection-sensor-module-red-135533 */


 * 1) define TIME 100


 * 1) define APIN A0
 * 2) define DPIN 9

int counter = 0; boolean flag = false; int sensorMaxValue = 0; int sensorAvgValue = 0;

void setup { pinMode(DPIN, INPUT); Serial.begin(9600); }

void loop { int sensorValue= analogRead(APIN); sensorAvgValue+=sensorValue; if(digitalRead(DPIN)==HIGH) flag=true; if(sensorValue>sensorMaxValue) sensorMaxValue=sensorValue; if(counter++>TIME) { Serial.print(sensorAvgValue/TIME); Serial.print(" "); Serial.print(sensorMaxValue); Serial.print(" "); if(flag) Serial.print(flag); Serial.println;

flag = false; counter = 0; sensorMaxValue = 0; sensorAvgValue = 0; } delay(1); }