Friday, 26 May 2017

CLAP SENSOR CODE



                                                 CLAP                                        SENSOR



PLEASE SUBSCRIBE TO MY CHANNEL :

https://www.youtube.com/c/simplehomemadeprojects



HOW TO MAKE A CLAP SENSOR VIDEO LINK :


https://www.youtube.com/watch?v=-WmPslyRpdo&list=PLrZzOA0JyPbsa294s6sG_oiwcKkkg1KwM&index=12





PROGRAM CODE :

int sound_sensor = 4;
int relay = 5;

int clap = 0;
long detection_range_start = 0;
long detection_range = 0;
boolean status_lights = false;
 
void setup() {
  pinMode(sound_sensor, INPUT);
  pinMode(relay, OUTPUT);
}
 
void loop() {
  int status_sensor = digitalRead(sound_sensor);
  if (status_sensor == 0)
  {
    if (clap == 0)
    {
      detection_range_start = detection_range = millis();
      clap++;
    }
    else if (clap > 0 && millis()-detection_range >= 50)
    {
      detection_range = millis();
      clap++;
    }
  }
  if (millis()-detection_range_start >= 400)
  {
    if (clap == 2)
    {
      if (!status_lights)
        {
          status_lights = true;
          digitalWrite(relay, HIGH);
        }
        else if (status_lights)
        {
          status_lights = false;
          digitalWrite(relay, LOW);
        }
    }
    clap = 0;
  }
}

2 comments:

  1. Hiii this project same but using microcontroller 8081? Please send reply

    ReplyDelete
  2. is there any problem with the code? even tho i exactly do what you do on the video (even to the cable color) and copy the code, upload the code,then turn on arduino,the LED doesnt detect the clap. what's wrong?

    ReplyDelete