Clap Switch with Arduino and Sound Sensor, Arduino project with code

Clap Switch with Arduino and Sound Sensor, Arduino project with code
Clap Switch with Arduino and Sound Sensor, Arduino project with code

The clap switch is used in a wide range of electronic projects, to control devices by clapping or making a specific sound. The clap switch consists of a Sound Sensor module connected to a microcontroller, or to an Arduino board. And through a software code, the audio signal can be converted into a key to turn on and off electronic devices or electronic circuits.
In this post we will learn: How To Make Clap Switch with Arduino and Sound Sensor.

Electronic components needed :

  • 1 Resistance ( 220 Ohm )
  • 1 Led
  • Sound Sensor Module KY-038
  • Electrical wires
  • Arduino UNO
  • Breadboard

Clap Switch with Arduino and Sound Sensor, Arduino project with code

Schema of the circuit :

Clap Switch with Arduino and Sound Sensor

Arduino programming code :

int Sensor = A0;
int clap = 0;
long detection_range_start = 0;
long detection_range = 0;
boolean status_lights = false;
// By www.andprof.com
void setup() {
pinMode(Sensor, INPUT);
pinMode(10,OUTPUT);
}

void loop() {
int status_sensor = digitalRead(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(10, HIGH);
}
else if (status_lights)
{
status_lights = false;
digitalWrite(10, LOW);
}
}
clap = 0;
}
}

Explainer video :

Discover also :

How To Use Sound Sensor With Arduino

How to make fire detector using arduino

How to control LED lights with Arduino

How to use digit 7-Segment LED Display with Arduino