Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsA loudness sensor outputs a voltage that rises with sound level. The ESP32 reads it many times a second, finds the loudest peak in each half second, and only sounds the alarm if the noise stays above the limit for three seconds. That avoids false alarms from a single dropped book. The reading is a relative level, not calibrated decibels, so you set the limit by experiment.
Tick anything you already have and the total updates.
Loudness sensor
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger.
noise_alarm.inoVerify & upload in Electrolarkconst int MIC = 34, BUZZER = 25;
const int LIMIT = 1800; // set from your own quiet and loud readings
const unsigned long HOLD_MS = 3000;
unsigned long loudSince = 0;
void setup() {
Serial.begin(115200);
pinMode(BUZZER, OUTPUT);
}
void loop() {
int peak = 0, low = 4095;
unsigned long start = millis();
while (millis() - start < 500) {
int v = analogRead(MIC);
peak = max(peak, v);
low = min(low, v);
}
int level = peak - low; // swing of the signal, 0 when silent
Serial.println(level);
if (level > LIMIT) {
if (loudSince == 0) loudSince = millis();
if (millis() - loudSince > HOLD_MS) digitalWrite(BUZZER, HIGH);
} else {
loudSince = 0;
digitalWrite(BUZZER, LOW);
}
}
Lower LIMIT after reading the Serial Monitor values with loud noise.
Raise LIMIT or turn the sensor gain knob down.
Keep the sensor away from the buzzer, whose sound feeds back into it.
No. It gives a relative level. The INMP441 decibel meter project is closer to real dB.
Yes, add an LED on another pin.
So that a single bang does not trigger the alarm.
5 parts: ESP32-WROOM-32 38-Pin Development Board, Seeed Studio Studio Grove Loudness Sensor – Analog Output, Gain Adjustable, Buzzer Module 3.3–5V, 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 45 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (noise_alarm.ino).
About ₹1,182 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Sampling an analog sound sensor; Finding the peak in a time window; Using a duration so one-off noises are ignored.
Ideas that reuse this build: ESP32 INMP441 decibel meter. They are listed under Take it further on this page.
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.
Learning project. Check every circuit and the datasheet of each part before you power it up.