Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsMake an LED respond to a clap, using a sound sensor and a guard that ignores the echo. The module's digital output pulses LOW whenever the sound crosses the level set by its onboard potentiometer. The complication is that one clap in a hard-walled room produces several pulses as it echoes off the surfaces. Recording the time of each accepted clap and refusing anything within 300 ms of it filters those echoes out. That guard is the difference between a light that toggles once and one that flickers unpredictably.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
LEDs from the kit's red, green, yellow and blue packs
220 ohm resistors: one in series with every LED
Sound sensor module: AO gives the loudness, DO switches at the knob setting
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_010_clap_detection.inoVerify & upload in Electrolarkint soundPin = 13;
int led = 33;
int buzzer = 32;
bool lightOn = false;
unsigned long lastClap = 0;
unsigned long deadTime = 300; // Ignore echoes for this long
int clapCount = 0;
void setup()
{
pinMode(soundPin, INPUT);
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
Serial.println("Clap to switch the light");
}
void loop()
{
if (digitalRead(soundPin) == LOW)
{
if (millis() - lastClap > deadTime)
{
lastClap = millis();
clapCount = clapCount + 1;
lightOn = !lightOn;
digitalWrite(led, lightOn);
digitalWrite(buzzer, HIGH);
delay(40);
digitalWrite(buzzer, LOW);
Serial.print("Clap ");
Serial.print(clapCount);
Serial.print(" - light is ");
Serial.println(lightOn ? "ON" : "OFF");
}
}
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
Turn it round: the long leg (anode) goes to the GPIO side through the 220 ohm resistor, the short leg to GND.
The active buzzer has a + leg: it goes to the GPIO, the other to GND. Peel off the sticker on top if it has one.
Use the sensor's AO pin on GPIO34 and turn the blue trim pot: the module's LED should flicker when you clap.
The module's digital output pulses LOW whenever the sound crosses the level set by its onboard potentiometer. The complication is that one clap in a hard-walled room produces several pulses as it echoes off the surfaces. Recording the time of each accepted clap and refusing anything within 300 ms of it filters those echoes out. That guard is the difference between a light that toggles once and one that flickers unpredictably.
Clap once and the LED lights with a short chirp. Clap again and it goes out. Echoes in a hard room do not cause extra switching.
Yes. It is project 10 of 120 in the Geekobot Titan Kit, in level 1 (Foundations). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
9 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), PCB Mounted Active Buzzer Module, Generic LM393 Sound Detection Sensor Module – Digital Output and ESP32 38-Pin Expansion Board. 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 30 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (titan_kit_010_clap_detection.ino).
About ₹797 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Sound sensing with a digital output; Using millis() to record when something happened; Guard windows that reject echoes; Combining sensing with a toggled state; Combine projects, put the Bluetooth dashboard on the smart home, or give the obstacle robot the RFID reader so only a registered card can start it; Replace every remaining delay() with millis() so your projects can do several things at once, as Experiment 51 does; Log your readings, stream them over Bluetooth, paste them into a spreadsheet and plot a day's temperature; Store settings in EEPROM so PINs, card UIDs and thresholds survive a power cut; Add a real-time clock module and let the smart home act on the time of day, not just on its sensors; Design your own project from scratch: write down the inputs, the outputs, and the decision in between, then wire and code it.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Clap twice and the lights come on. Clap twice again to switch them off.
Plays a friendly ding-dong whenever someone walks into the shop or room.
Beeps and flashes any message in Morse, or key your own by hand.
Turn a membrane keypad into a two-octave piano.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.