How To Make Clap Switch with Arduino and Sound Sensor

How To Make Clap Switch with Arduino and Sound Sensor | | Module KY-038 | Arduino UNO R3 projects for beginners.
How To Make Clap Switch with Arduino and Sound Sensor

In this post, we will learn how to make a clap switch, using an audible signal or clapping. This switch is used in a wide range of electronic devices, household appliances, and other electronic innovations. This switch is made using a sound sensor. In this post, we’ll discover how to make clap switch with Arduino and sound sensor (Module KY-038), as well as the programming code that used.

Electronic components that we need:

  • sound sensor (Module KY-038)
  • 1 LED
  • 1 resistor (220 Ohm)
  • Electrical wires
  • Arduino UNO
  • Breadboard

Circuit diagram:

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() {
// put your setup code here, to run once:
pinMode(Sensor, INPUT);
pinMode(10, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int status_sensor = digitalRead(Sensor); // reads analog data from 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(10, HIGH);
}
else if (status_lights)
{
status_lights = false;
digitalWrite(10, LOW);
}
}
clap = 0;
}
}

Explanatory Video:

How To Make Clap Switch with Arduino and Sound Sensor | Arduino projects with code and circuit diagram

Previous articleHow to use sound sensor with Arduino