> For the complete documentation index, see [llms.txt](https://krootee.gitbook.io/arduino/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krootee.gitbook.io/arduino/1..md).

# 1.ระบบเช็คความชื้น

```arduino
int sensorPin = A0; // ขาเซ็นเซอร์ความชื้น
int ledPin = 8;     // ขา LED

void setup() {
  pinMode(ledPin, OUTPUT); // ตั้งค่า LED เป็นขาออก
  Serial.begin(9600);      // เริ่มต้นการสื่อสารแบบอนุกรม
}

void loop() {
  int sensorValue = analogRead(sensorPin); // อ่านค่าจากเซ็นเซอร์ความชื้น
  Serial.print("Moisture Level: ");
  Serial.println(sensorValue); // แสดงค่าความชื้น

  if(sensorValue < 300) { // หากค่าความชื้นต่ำกว่า 300 แสดงว่าแห้ง
    digitalWrite(ledPin, HIGH); // เปิด LED
  } else {
    digitalWrite(ledPin, LOW); // ปิด LED
  }

  delay(1000); // หน่วงเวลา 1 วินาที
}
```

<figure><img src="/files/aRyIB8hZkkRqaPI8KwdZ" alt=""><figcaption></figcaption></figure>
