📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ คำสั่งเขียน
int sensorPin = A1; // select the input pin for the Soil moisture sensor
int sensorValue = 0; // variable to store the value coming from the sensor
int ledPin1 = 12;
void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
delay(500);
Serial.print("sensor = " );
Serial.println(sensorValue);
if(sensorValue <= 300)
{
Serial.println("Dry Soil");
digitalWrite(ledPin1, HIGH);
}
else if(sensorValue > 300 && sensorValue <= 700)
{
Serial.println("Humid Soil");
digitalWrite(ledPin1, LOW);
}else
{
Serial.println("in Water");
digitalWrite(ledPin1, LOW);
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น
ครูเต้ง เทคโนฯ