Skip to content
Buy 10+ on select items — save 10% auto-applied
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Skip to main content

Arduino Nano KY-037: Double-Clap Relay Switch | ShillehTek

May 24, 2026 13 views

Arduino Nano KY-037: Double-Clap Relay Switch | ShillehTek
Project

Build an Arduino Nano KY-037 double-clap relay switch to toggle a mains lamp with two claps, using simple timing logic and an adjustable sensor threshold from ShillehTek.

30 min Beginner4 parts

Project Overview

Arduino Nano + KY-037 sound sensor clap switch: A KY-037 sound sensor detects sharp claps, and the Arduino Nano measures the time between claps to toggle a 5V relay, turning a lamp on or off with a double clap.

Clap once for nothing, then clap twice within about one second to flip the relay state. The same setup can control a fan, coffee machine, or other mains-powered device through the relay.

  • Time: ~30 minutes
  • Skill level: Beginner
  • What you will build: A double-clap-controlled relay that switches a lamp on and off.
Arduino Nano wired to KY-037 sound sensor and 5V relay module for a clap-controlled lamp switch
KY-037 + relay + Arduino = the classic Clapper.

Parts List

From ShillehTek

External

  • Mains lamp + plug (routed through the relay)

Safety: Relays here switch mains AC. If you are not comfortable with mains wiring, use a smart plug controlled via Wi-Fi instead for a similar effect with less risk.

Step-by-Step Guide

Step 1 - Inspect the KY-037

Goal: Understand what the KY-037 provides so you can set a reliable clap threshold.

What to do: Identify the microphone, the trim-pot (threshold adjust), and the output pins. This build uses the digital output (DOUT), which goes HIGH when the sound level crosses the threshold.

KY-037 sound sensor module close-up showing the electret microphone, trim-pot, and output pins
Electret mic + op-amp + comparator + trim-pot threshold. Both analog and digital outputs.

Expected result: You know which pin is DOUT and where the sensitivity/threshold trim-pot is.

Step 2 - Wire it

Goal: Connect the KY-037 and relay module to the Arduino Nano with a shared ground.

What to do: Make the following connections:

Wiring diagram showing Arduino Nano connected to KY-037 DOUT on D2 and relay IN on D3 with common 5V and GND
KY-037 DOUT → D2; relay IN → D3; common GND.
  • KY-037 VCC → 5V, GND → GND, DOUT → D2
  • Relay VCC → 5V, GND → GND, IN → D3
  • Lamp routed through relay COM and NO
Full clap switch circuit showing Arduino Nano, KY-037 sound sensor, and 5V relay module controlling a lamp through COM and NO
Full circuit - adjust the KY-037 trim-pot until a normal clap reads HIGH on DOUT.

Expected result: The Arduino Nano, KY-037, and relay module are powered from 5V and share ground, with DOUT on D2 and relay IN on D3.

Step 3 - Upload the sketch (double-clap detection)

Goal: Detect two claps close together and toggle the relay output.

What to do: Upload the code below. It debounces the sensor and counts claps within a one-second window to toggle the relay state.

Code:

const int MIC = 2;
const int RELAY = 3;
bool relayOn = false;
unsigned long lastClap = 0;
int clapCount = 0;

void setup() {
  pinMode(MIC, INPUT);
  pinMode(RELAY, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(MIC) == HIGH) {
    unsigned long now = millis();
    if (now - lastClap < 80) return;   // debounce
    if (now - lastClap < 1000) {
      clapCount++;
    } else {
      clapCount = 1;
    }
    lastClap = now;
    if (clapCount == 2) {
      relayOn = !relayOn;
      digitalWrite(RELAY, relayOn ? HIGH : LOW);
      Serial.println(relayOn ? "ON" : "OFF");
      clapCount = 0;
    }
  }
}

Expected result: Opening Serial Monitor at 9600 baud prints ON and OFF each time you successfully double-clap.

Step 4 - Test and adjust the threshold

Goal: Make the clap detection reliable without false triggers.

What to do: Power the circuit and try two claps. If voices or room noise trigger the sensor, turn the KY-037 trim-pot to make it less sensitive, then retest.

Arduino Nano clap switch running on a breadboard with KY-037 sensor and relay module while toggling a lamp
Clap, clap → lamp toggles. Adjust the KY-037 trim-pot if false triggers happen from voices.
Lamp turned on by an Arduino Nano KY-037 double-clap relay switch
Two claps and the lamp comes on.

Expected result: A double clap toggles the lamp reliably, and normal background sound does not.

Step 5 - Where to take it next

Goal: Explore safe, incremental extensions of the same concept.

What to do: Try one of these ideas:

  • Two-mode switch: single clap → fan, double clap → light
  • Multi-channel relay → control 4 separate appliances by clap count
  • Pair with HC-SR501 PIR so claps only count when you are in the room
  • Swap KY-037 for an INMP441 I2S mic + ESP32 + ML to detect specific gestures / words

Expected result: You have a clear next modification that still builds on clap detection and relay control.

Conclusion

You built an Arduino Nano KY-037 clap switch that detects a double clap and toggles a 5V relay to control a lamp. Along the way, you used threshold detection, basic debouncing, and simple timing logic with millis().

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.