-:Light On/Off By Clapping:-
So, basically in this project, I have made system related to home automation so for this project we need:-
Arduino Uno
Relay
Mic Module
Bulb
so basically connect Vcc to +5volt
Gnd to Ground pin of Arduino
and data pin to digital pin you can use any digital pin of you Arduino and configure to your code
#define signalToRelayPin 13
#define sensorPin 2
int lastSoundValue;
int soundValue;
long lastNoiseTime = 0;
long currentNoiseTime = 0;
long lastLightChange = 0;
int relayStatus = HIGH;
void setup() {
pinMode(sensorPin, INPUT);
pinMode(signalToRelayPin, OUTPUT);
}
void loop() {
soundValue = digitalRead(sensorPin);
currentNoiseTime = millis();
if (soundValue == 1) { // if there is currently a noise
if (
(currentNoiseTime > lastNoiseTime + 200) && // to debounce a sound occurring in more than a loop cycle as a single noise
(lastSoundValue == 0) && // if it was silent before
(currentNoiseTime < lastNoiseTime + 800) && // if current clap is less than 0.8 seconds after the first clap
(currentNoiseTime > lastLightChange + 1000) // to avoid taking a third clap as part of a pattern
) {
relayStatus = !relayStatus;
digitalWrite(signalToRelayPin, relayStatus);
lastLightChange = currentNoiseTime;
}
lastNoiseTime = currentNoiseTime;
}
lastSoundValue = soundValue;
}
EXPANDED TECHNICAL DETAILS
Acoustic Event Impulse Logic
A practical and fun home automation project that provides hands-free light control using the acoustic signature of a human clap.
- Envelope-Follower Signal Analysis: Uses a high-gain microphone module. The Arduino ignores steady background noise and only triggers when it detects a sharp "Spike" (High Amplitude, Low Duration) characteristic of a clap.
- Double-Clap Verification Kernel: To prevent false triggers from speech or music, the firmware requires two claps within a 500ms window. The Arduino times the interval between spikes to verify a "Double-Clap" event before toggling the relay.
Performance
- Verified with Arduino IDE: Coded with a robust state-machine that ensures the light never "Flickers" or behaves unpredictably during loud environmental sounds.