How to make clap switch

Posted by moudud 13/04/2019 0 Comment(s)

 

HOW TO MAKE CLAP SWITCH


Circuit Diagram :

 


 

 

Relay connection with Arduino
ServoArduino
VCC5V
GNDGND
SignalD13

 

 

 

 

 

 

 

 

Sound sensor connection with Arduino
Sound sensor Arduino
VCC5V
GNDGND
OUTD2

 

 

 

 

 

 

 

 


Code

 

 

int inPin = 2;        
int outPin = 13;       

int state = HIGH;      
int reading;           
int previous = LOW;    


long time = 0;         
long debounce = 200;   

void setup()
{
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);
  
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(outPin, state);

  previous = reading;
}


 

 

 

Write a Comment