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

-:เปิด/ปิดไฟด้วยการปรบมือ:-

โปรเจกต์นี้เป็นการสร้างระบบที่เกี่ยวข้องกับระบบอัตโนมัติภายในบ้าน (home automation) โดยสำหรับโปรเจกต์นี้ เราต้องใช้:

Arduino Uno

Relay

Mic Module

Bulb

โดยพื้นฐานแล้ว ให้เชื่อมต่อ Vcc เข้ากับ +5volt

Gnd เข้ากับขา Ground ของ Arduino

และขา data เข้ากับขา digital คุณสามารถใช้ขา digital ใดก็ได้บน Arduino ของคุณและกำหนดค่าในโค้ดของคุณได้เลย

#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; }

รายละเอียดทางเทคนิคเพิ่มเติม

ตรรกะการทำงานของเหตุการณ์อะคูสติก (Acoustic Event Impulse Logic)

โปรเจกต์ home automation ที่ใช้งานได้จริงและสนุกสนาน ซึ่งให้การควบคุมแสงแบบแฮนด์ฟรีโดยใช้ลักษณะเสียงจากการปรบมือของมนุษย์

  • การวิเคราะห์สัญญาณแบบ Envelope-Follower: ใช้ Mic Module ที่มีอัตราขยายสูง โดย Arduino จะไม่สนใจเสียงรบกวนพื้นหลังคงที่ และจะทำงานเมื่อตรวจพบสัญญาณ "Spike" ที่คมชัดเท่านั้น (High Amplitude, Low Duration) ซึ่งเป็นลักษณะเฉพาะของการปรบมือ
  • กลไกการยืนยันการปรบมือสองครั้ง (Double-Clap Verification Kernel): เพื่อป้องกันการทำงานผิดพลาดจากการพูดหรือเสียงเพลง firmware จำเป็นต้องมีการปรบมือสองครั้งภายในช่วงเวลา 500ms โดย Arduino จะจับเวลาช่วงห่างระหว่างสัญญาณ spikes เพื่อยืนยันเหตุการณ์ "Double-Clap" ก่อนที่จะสลับการทำงานของ Relay

ประสิทธิภาพ

  • ตรวจสอบแล้วด้วย Arduino IDE: โค้ดที่เขียนด้วย state-machine ที่แข็งแกร่งซึ่งรับรองว่าไฟจะไม่ "Flickers" หรือทำงานผิดปกติโดยไม่คาดคิดแม้จะมีเสียงดังจากสภาพแวดล้อม

ข้อมูล 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: "th"