Build it step by step
0 of 4 doneWire the sound module
+ to 5V, G to GND, DO to D2.
Set the sensitivity
Turn the module's trimmer until its DO LED is off in a quiet room but blinks when you clap 1 m away.
Wire the relay and lamp
Relay IN to D7. Switch the 12 V LED strip through COM and NO.
Upload and clap
Clap twice quickly (like "clap-clap"). Then try a single clap and a door bang.
How do you build a double-clap light switch?
Clap twice and a relay toggles a lamp. A sound sensor module and a little timing logic ignore single bangs. You need Arduino Uno R3, Sound sensor module (KY-038), Relay Module 5V, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female) and Jumper wires male to female (40 pcs). It takes 4 steps and about 50 minutes.
- Level
- Beginner
- Time
- About 50 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- SensorsBuy
- InterfacesBuyRelay Module 5V × 1
- OptoelectronicsBuyA safe 12 V practice lamp
- PowerBuy
- PowerBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Sound module + / G | Uno 5V / GND | Module power |
| Sound module DO | Uno D2 | Goes HIGH on a loud sound (set with the trimmer) |
| Relay VCC / GND / IN | Uno 5V / GND / D7 | Lamp control |
| 12 V + | Relay COM; NO to LED strip + | Lamp switched by the relay |
| LED strip − | 12 V − | Return |
Code
Arduino IDE, board "Arduino Uno". No extra libraries.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int MIC = 2, RELAY = 7;
const bool ON = LOW;
bool lamp = false;
unsigned long firstClap = 0;
int claps = 0;
void setup() {
pinMode(MIC, INPUT); pinMode(RELAY, OUTPUT); digitalWrite(RELAY, !ON);
Serial.begin(9600);
}
void loop() {
if (digitalRead(MIC) == HIGH) {
unsigned long now = millis();
if (claps == 0 || now - firstClap > 800) { claps = 1; firstClap = now; } // start a new pattern
else if (now - firstClap > 150) claps = 2; // second clap 150-800 ms later
delay(120); // skip the echo of this clap
}
if (claps == 2) {
lamp = !lamp; digitalWrite(RELAY, lamp ? ON : !ON);
Serial.println(lamp ? "Lamp ON" : "Lamp OFF");
claps = 0;
}
if (claps == 1 && millis() - firstClap > 800) claps = 0; // single clap: forget it
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Two claps about half a second apart | Relay clicks, lamp toggles, serial says ON or OFF |
| A single clap | Nothing happens |
| Talking normally near it | Nothing happens |
If it does not work
Never reacts
Turn the trimmer until the DO LED just goes off in silence, then test again.
Toggles on any noise
The module is too sensitive. Turn the trimmer back a little.
Toggles twice
Raise the delay(120) to 200 so one clap's echo is not counted.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the double-clap light switch?
Arduino Uno R3, Sound sensor module (KY-038), Relay Module 5V, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female) and Jumper wires male to female (40 pcs). 12 V LED strip warm white (5 m, 2835): A safe 12 V practice lamp.
How long does the double-clap light switch take to build?
About 50 minutes for a beginner maker, in 4 steps.
How do I know the double-clap light switch works?
Two claps about half a second apart: Relay clicks, lamp toggles, serial says ON or OFF. A single clap: Nothing happens. Talking normally near it: Nothing happens.
Never reacts: what should I check?
Turn the trimmer until the DO LED just goes off in silence, then test again.
Toggles on any noise: what should I check?
The module is too sensitive. Turn the trimmer back a little.
Toggles twice: what should I check?
Raise the delay(120) to 200 so one clap's echo is not counted.
