
const int analogInPin = A5;
const int relay = 2;
const int relay = 2;
int sensorValue =
0; // ตัวแปรค่า Analog
int outputValue = 0; // ตัวแปรสำหรับ Map เพื่อคิด %
int outputValue = 0; // ตัวแปรสำหรับ Map เพื่อคิด %
void setup() {
Serial.begin(9600);
pinMode(relay, OUTPUT);
}
Serial.begin(9600);
pinMode(relay, OUTPUT);
}
void loop() {
sensorValue = analogRead(analogInPin);
sensorValue = analogRead(analogInPin);
Serial.print("Soil Moisture = ");
Serial.print(outputValue);
Serial.println(" %");
Serial.print(outputValue);
Serial.println(" %");
if
(outputValue <= 40) { //ตั้งค่า % ที่ต้องการจะรดน้ำต้นไม้
digitalWrite(relay, HIGH);
}
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
delay(1000);
}
digitalWrite(relay, LOW);
}
delay(1000);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น