///ELECTRONCS MALAYALAM CLAP SWITCH

 const int  buttonPin = 2;    

const int ledPin = 13;       

int buttonPushCounter = 0;  

int buttonState = 0;        

int lastButtonState = 0;     


void setup() {

  

  pinMode(buttonPin, INPUT);

  

  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);

}



void loop() {





  buttonState = digitalRead(buttonPin);


  // compare the buttonState to its previous state

  if (buttonState != lastButtonState) {

    // if the state has changed, increment the counter

    if (buttonState == HIGH) {

      // if the current state is HIGH then the button went from off to on:

      buttonPushCounter++;

      Serial.println("on");

      Serial.print("number of button pushes: ");

      Serial.println(buttonPushCounter);

    } else {

      Serial.println("off");

    }

    

    delay(50);

  }

  lastButtonState = buttonState;

if (buttonPushCounter % 4 == 0)

  {

    digitalWrite(ledPin, HIGH);

 } 

  else 

  {

    digitalWrite(ledPin, LOW);

   }

}


 For All Electronics Projects