動機:
因為大一打完球回宿舍時常常還得等上10分鐘等水熱,等待的這段時間非常難熬,又看到網路上有能用WIFI控制的冷氣,所以我們也想試著做出相同概念的東西。
所需要的材料:
arduino版
ESP32(接收WIFI訊號)
LM2596(降壓模組)
電源模組
馬達(換成TD8120MG)
支架(3D列印)
程式碼:
#define BLYNK_TEMPLATE_ID "TMPL6idsV24Mq"
#define BLYNK_TEMPLATE_NAME "WaterHeater"
#define BLYNK_AUTH_TOKEN "a_OBMhh0ocPQdZNTNeMka58gbyFWjA4C"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
// --- WiFi 設定 ---
char ssid[] = "poo";
char pass[] = "45864586";
// --- 伺服馬達與腳位設定 ---
Servo myservo;
const int servoPin = 13; // 訊號線接 GPIO 13
// 預設邏輯:平時停在中間 (90度),要開就推到 140度,要關就推到 40度
const int angleIdle = 90;
const int angleON = 140;
const int angleOFF = 40;
const int pushDuration = 1000; // 推桿持續時間 (1秒)
void setup() {
Serial.begin(115200);
// 初始化伺服馬達
myservo.setPeriodHertz(50);
myservo.attach(servoPin, 500, 2500);
// 先歸零到待機位置
Serial.print("歸零中...");
myservo.write(angleIdle);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
Blynk.run();
}
void performAction(int targetAngle) {
myservo.attach(servoPin); // 確保馬達有連上
myservo.write(targetAngle);
delay(pushDuration); // 等待馬達推到位
myservo.write(angleIdle); // 縮回待機位置
delay(500); // 等它縮回來
// myservo.detach(); // 斷開訊號讓馬達完全放鬆
}
// --- Blynk 按鈕指令接收區 ---
// 當按下 V0 (開啟熱水)
BLYNK_WRITE(V0) {
int pinValue = param.asInt();
if (pinValue == 1) {
Serial.println("收到指令:開啟熱水器 (ON)");
performAction(angleON);
}
}
// 當按下 V1 (關閉熱水)
BLYNK_WRITE(V1) {
int pinValue = param.asInt();
if (pinValue == 1) {
Serial.println("收到指令:關閉熱水器 (OFF)");
performAction(angleOFF);
}
}
心得:
411214321黃昱晨:在這次VIP課程我負責蒐集資料及簡報製作和報告其中我遇到最大的問題是沒想到一開始的伺服馬達不夠力,期中報告助教有提醒我可能要更換馬達後來才換了一顆,才沒有遇到馬達推不動開關的問題
411214309田禹炫:這次專案遇到的問題是:開發初期電腦使用者名稱為中文所引發的編譯路徑錯誤,我學會了如何跳出系統限制,用全英文開發,這屆決了路徑錯誤問題
梁翔:我負責材料採買及資料蒐集,遇到問題是一開始採購的廠家發票太晚給所以沒報到帳。