const int SOUND_SENSOR_PIN = 9;
int lastState = HIGH;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(SOUND_SENSOR_PIN, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int currentState = digitalRead(SOUND_SENSOR_PIN);
if (lastState == HIGH && currentState == LOW)
Serial.println("The sound has been detected");
else if (lastState == LOW && currentState == HIGH)
Serial.println("The sound has disappeared");
}