May 5, 2024

This is a simple sound sensor experiment. That takes a sound to turn on or turn off an LED. Here we use digital output from the sensor to measure the presence of the sound. The DO will goto pin 2 in arduino.  LED’s +ve is connected to 4.  Other circuit diagram is simple negative to negative and positive to +5v. Note: Dont forget to connect appropriate resistor to LED (minimum 150 ohms).

 

int soundSensor=2;
int LED=4;
boolean LEDStatus=false;

void setup() {
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);

}

void loop() {

int SensorData=digitalRead(soundSensor);
if(SensorData==1){

if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}
}
}