CODE:-
int bulbpin=9;
int soundpin=A3;
int wait=1;
int soundval1;
int soundval2;
boolean bulb=false;
int j;
void setup() {
// put your setup code here, to run once:
pinMode(soundpin,INPUT);
pinMode(bulbpin,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
soundval1=analogRead(soundpin);
Serial.println(soundval1);
delay(wait);
soundval2=analogRead(soundpin);
Serial.println(soundval2);
if (soundval2-soundval1>8) {
delay(500);
if (soundval2-soundval1>12) {
bulb=!bulb;
digitalWrite(bulbpin,bulb);
delay(100);
}
}
}
0 Comments