กลับไปหน้ารวมไฟล์
light-onoff-by-clapping-6f8055-en.md

-: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.

ข้อมูล Frontmatter ดั้งเดิม

title: "Light on/off by clapping"
description: "So, basically in this project, I have on or off my home lights using Arduino UNO, relay and mic module"
author: "ItsArduinoBoy"
category: ""
tags:
  - "lights"
  - "home automation"
  - "smart appliances"
  - "internet of things"
views: 3547
likes: 1
price: 870
difficulty: "Intermediate"
components:
  - "1x Relay Module (Generic)"
  - "1x mic module"
  - "1x Arduino UNO"
  - "1x Jumper wires (generic)"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "08db9965f65f65ef07288dd33c4d1178917830842392efd2956c528a72486179"
encryptedPayload: "U2FsdGVkX1/lSuS4gnVVLRD1B+z5e3yOTdh4SQM4g1JwG8u3SPSBe3L2/6DwReE24zX8ip5QbOFlgLcfF1hYY5P4qvd22hGESmZPku0Og74="
seoDescription: "Control lights by clapping! DIY Arduino UNO project using a Relay and Mic Module. Simple guide for electronics beginners."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/light-onoff-by-clapping-6f8055_cover.jpg"
lang: "en"