ลิงก์ youtueb

อุปกรณ์
- Arduino UNO R3
Relay
Voice Sound Detection Sensor Module
หลอดไฟ
LCD
R ปรับค่าได้ 10 k
Wiring diagram
Code & Libraries
#include <LiquidCrystal.h> int sound_sensor = 1; int relay = 2; int clap = 0; LiquidCrystal lcd(12, 10, 4, 5, 6, 7); long detection_range_start = 0; long detection_range = 0; boolean status_lights = false; void setup() { pinMode(sound_sensor, INPUT); pinMode(relay, OUTPUT); lcd.begin(8,2); } void loop() { int status_sensor = digitalRead(sound_sensor); if (status_sensor == 0) { if (clap == 0) { detection_range_start = detection_range = millis(); clap++; } else if (clap > 0 && millis()-detection_range >= 50) { detection_range = millis(); clap++; } } if (millis()-detection_range_start >= 400) { if (clap == 2) { if (!status_lights) { status_lights = true; digitalWrite(relay, HIGH); lcd.setCursor(3, 0); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("START "); lcd.setCursor(3, 1); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("ON "); } else if (status_lights) { status_lights = false; digitalWrite(relay, LOW); lcd.setCursor(3, 0); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("START "); lcd.setCursor(3, 1); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("OFF"); } } clap = 0; } }
เปิดปิดไฟ AC 220V ด้วยเสียง

อุปกรณ์
- Arduino UNO R3
Relay
Voice Sound Detection Sensor Module
หลอดไฟ
LCD
R ปรับค่าได้ 10 k
Wiring diagram
Code & Libraries
#include <LiquidCrystal.h> int sound_sensor = 1; int relay = 2; int clap = 0; LiquidCrystal lcd(12, 10, 4, 5, 6, 7); long detection_range_start = 0; long detection_range = 0; boolean status_lights = false; void setup() { pinMode(sound_sensor, INPUT); pinMode(relay, OUTPUT); lcd.begin(8,2); } void loop() { int status_sensor = digitalRead(sound_sensor); if (status_sensor == 0) { if (clap == 0) { detection_range_start = detection_range = millis(); clap++; } else if (clap > 0 && millis()-detection_range >= 50) { detection_range = millis(); clap++; } } if (millis()-detection_range_start >= 400) { if (clap == 2) { if (!status_lights) { status_lights = true; digitalWrite(relay, HIGH); lcd.setCursor(3, 0); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("START "); lcd.setCursor(3, 1); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("ON "); } else if (status_lights) { status_lights = false; digitalWrite(relay, LOW); lcd.setCursor(3, 0); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("START "); lcd.setCursor(3, 1); // ไปที่ตัวอักษรที่ 0 แถวที่ 1 lcd.print("OFF"); } } clap = 0; } }


ความคิดเห็น
แสดงความคิดเห็น