Using FC-04 to detect sound in an environment. The threshold can be changed with the potentiometer.
The sensor can detect the intensity of the sound environment. The sensitivity is adjustable with the potentiometer.
The working voltages are 3.3 V to 5 V and the output works as a digital switch output (1 and 0 ).
/*
FC-04 sound detection sensor
VCC to arduino 5v GND to arduino GND
*/
#define led_1 52
#define led_2 53
#define sound 7
int vol = 0;
long time_1, time_2;
int cont = 0;
void setup() {
Serial.begin (9600);
pinMode(led_1, OUTPUT);
pinMode(led_2, OUTPUT);
digitalWrite(led_1, LOW);
digitalWrite(led_2, HIGH);
}
void loop() {
vol = analogRead(sound);
Serial.println(vol);
delay(200);
time_2 = millis();
if ( vol > 500 && cont == 0 ){
digitalWrite(led_1, HIGH);
digitalWrite(led_2, LOW);
time_1 = millis();
cont = 1;
}
if ( vol < 500 && ( time_2 >= time_1 + 2000) ) {
digitalWrite(led_1, LOW );
digitalWrite(led_2, HIGH);
cont = 0;
}
}