整體抽水馬達搭配Arduino的工作原理較一般模組困難。廣泛運用於水泵、灌溉系統、智能植栽等實作中。
(上圖由右至左腳位分別為GND、5V、7)
以下為抽水馬達模組程式碼,按"1"則啟動持續一陣子自動關閉。
char Num;
void setup() {
pinMode(7, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Read character from serial port
if (Serial.available()) {
Num = Serial.read();
Serial.print("Received: ");
Serial.println(Num);
// Toggle relay based on the received character
if (Num == '1') {
digitalWrite(7, HIGH); // Relay ON
Serial.println("Relay ON");
} else {
digitalWrite(7, LOW); // Relay OFF
Serial.println("Relay OFF");
}
// Reset Num to a default value (e.g., '0')
Num = '0';
}
delay(50);
}
可透過以上程式碼驗證該模組是否正常運行。