Arnov Sharma
Published © CC BY

Clap Switch with Relay

Clap twice to turn ON or OFF the load which is connected to relay.

BeginnerFull instructions provided18 minutes5,573
Clap Switch with Relay

Things used in this project

Hardware components

Microphone Amplifier Breakout
Adafruit Microphone Amplifier Breakout
×1
Arduino UNO
Arduino UNO
×1
Relay (generic)
×1
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
everything above can be found here for a low price
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

sound_sensor_connection_iotboys_com_wiring_wkfols3kjv_Gu6JRKFdel.png

replace led with relay

Code

Untitled file

C/C++
int sound_sensor = A0;
int relay = 13;

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;
  }
}

Credits

Arnov Sharma

Arnov Sharma

302 projects • 305 followers
Just your average MAKER

Comments