← All Projects

Clap Switch — Sound Activated Light

246 viewsMarch 7, 2026
ArduinoSound SensorRelayHome AutomationBeginner

Turn a lamp on and off by clapping twice. Uses a sound sensor module to detect sharp sounds and a relay module to toggle a mains-powered light or appliance. Classic home automation project.

Components & Supplies

×1Arduino Uno R3
×1KY-037 Sound Sensor Module
×15V Relay Module (1-Channel)

Circuit Connections

ComponentPinPinComponent
ArduinoD2→DOUTSound Sensor
Arduino5V→VCCSound Sensor
ArduinoGND→GNDSound Sensor
ArduinoD7→INRelay

Overview

The clap switch listens for two quick clap sounds using a sound sensor module. When two claps are detected within 500ms, the relay toggles on or off. This provides a hands-free way to control any appliance plugged into the relay.

The sound sensor's sensitivity can be adjusted with its onboard potentiometer. Set it so that normal conversation doesn't trigger it, but a sharp clap does.

arduino— Clap Switch Sketch
const int soundPin = 2;
const int relayPin = 7;
bool lightOn = false;
int clapCount = 0;
unsigned long lastClap = 0;

void setup() {
  Serial.begin(9600);
  pinMode(soundPin, INPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
}

void loop() {
  if (digitalRead(soundPin) == HIGH) {
    unsigned long now = millis();
    if (now - lastClap > 200) {
      clapCount++;
      lastClap = now;
      Serial.print("Clap #");
      Serial.println(clapCount);
    }
  }

  if (clapCount >= 2) {
    lightOn = !lightOn;
    digitalWrite(relayPin, lightOn ? LOW : HIGH);
    Serial.println(lightOn ? "Light ON" : "Light OFF");
    clapCount = 0;
    delay(500);
  }

  if (clapCount > 0 && millis() - lastClap > 800) {
    clapCount = 0;
  }
}