Clap On/ Clap Off
Pin Connections:
Sensor Out -- Pin 8
Sensor Vcc -- 5V
Sensor GND - GND
-------------------------- Copy code below
int led = 13;
int soundPin = 8;
bool ledstate = LOW;
bool clap = LOW;
void setup()
{
pinMode(13,OUTPUT);
pinMode(12, INPUT);
//Serial.begin(9600);
}
void loop()
{
clap = digitalRead(soundPin);
//Serial.println(value);
if(clap == HIGH && ledstate == LOW)
{
ledstate = HIGH;
digitalWrite(led,HIGH);
delay(300);
}
else if(clap == HIGH && ledstate == HIGH)
{
ledstate = LOW;
digitalWrite(led,LOW);
delay(300);
}
//delay(100);
}
No comments:
Post a Comment