// This project is intended to implement a sound sensor but since WokWi doesn't have a sound sensor component I chose to use their Motion sensor
// Which works with the same principle
// The source code is available on git at :
// Define the pin configuration of the LED and Sound Sensor
#define Sound_Sensor 35
#define Led_Pin 4
const int Sound_Threathold = 200;
void setup() {
// put your setup code here, to run once:
pinMode(Sound_Sensor, INPUT);
pinMode(Led_Pin, OUTPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int sound = analogRead(Sound_Sensor); // Read the output of the sensor
digitalRead(Led_Pin); // Read the output pin of the LED to update its stae
if (sound>Sound_Threathold && digitalRead(Led_Pin)==false)
{
digitalWrite(Led_Pin, HIGH);
Serial.println("ON");
}
else if (sound>Sound_Threathold && digitalRead(Led_Pin)==true)
{
digitalWrite(Led_Pin, LOW);
Serial.println("OFF");
}
}