Hackster is hosting Impact Spotlights: Robotics. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Robotics. Stream on Thursday!
utsabkayal001
Published © GPL3+

Clap switch using Arduino

This is a easy clap circuit using arduino uno.

BeginnerFull instructions provided2,256
Clap switch using Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Plastic Enclosure, Project Box
Plastic Enclosure, Project Box
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Relay Module (Generic)
×1
digital sound sensor
×1
5volt smps
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Diagram of the project

Code

code of the project

C/C++
int soundsensor = 7;
int relay = 6;

int clap = 0;
long detection_range_start = 0;
long detection_range = 0;
boolean status_lights = false;
 
void setup() {
  pinMode(soundsensor, INPUT);
  pinMode(relay, OUTPUT);
}
 
void loop() {
  int status_sensor = digitalRead(soundsensor);
  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;
  }
}

Credits

utsabkayal001
0 projects • 0 followers

Comments