Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsA sound sensor module has a small microphone and a comparator that gives a digital pulse when a loud sound occurs. The ESP32 watches for two pulses less than a second apart and treats that as a double clap, then toggles a relay. Requiring two claps stops a single door slam or a cough from switching the light. A short lockout after each toggle avoids echoes being counted twice.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Tick anything you already have and the total updates.
Analog sound sensor microphone module
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger. Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
clap_switch.inoVerify & upload in Electrolarkconst int MIC_PIN = 27, RELAY_PIN = 26;
bool on = false;
unsigned long firstClap = 0, lockUntil = 0;
int claps = 0;
void setup() {
Serial.begin(115200);
pinMode(MIC_PIN, INPUT);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // most relay modules are OFF when HIGH
}
void loop() {
unsigned long now = millis();
if (digitalRead(MIC_PIN) == HIGH && now > lockUntil) {
lockUntil = now + 150; // ignore echoes of the same clap
if (claps == 0 || now - firstClap > 1000) { claps = 1; firstClap = now; }
else claps++;
Serial.printf("clap %d\n", claps);
if (claps >= 2) {
on = !on;
digitalWrite(RELAY_PIN, on ? LOW : HIGH);
claps = 0;
lockUntil = now + 800;
}
}
}
Lower the sensitivity with the screw, or move the sensor away from fans and speakers.
Raise the sensitivity, check the DO wiring, and clap close to the microphone.
Flip HIGH and LOW in the sketch if your relay is active-high.
Not really. It reacts to any sharp loud sound; the double-clap rule reduces false triggers.
Yes. Change the claps >= 2 test to 3.
Yes. Use one clap for one relay and two for another.
5 parts: ESP32-WROOM-32 38-Pin Development Board, Generic Analog Sound Sensor Microphone Module for Arduino, 5V Relay Module with Optocoupler, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (clap_switch.ino).
About ₹634 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading a digital sound sensor; Detecting a double clap with timing; Switching a relay from the result.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Ideas that reuse this build: ESP32 IR remote relay switch. They are listed under Take it further on this page.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Learning project. Check every circuit and the datasheet of each part before you power it up.