เซนเซอร์วัดความชื้นในดินแบบ Capacitive Soil Moisture Sensor SNP-00136
รหัสสินค้า: SNP-00136

เซนเซอร์วัดความชื้นในดินแบบ Capacitive Soil Moisture Sensor SNP-00136

Capacitive Soil Moisture Sensor เป็นเซ็นเซอร์ที่ใช้วัดความชื้นในดินโดยอาศัยหลักการเปลี่ยนแปลงของค่าความจุไฟฟ้า (Capacitance) เซ็นเซอร์นี้ประกอบด้วยแผ่นโลหะที่ไม่สัมผัสกับดินโดยตรง แต่จะสร้างสนามไฟฟ้า เมื่อความชื้นในดินเปลี่ยนแปลง ค่าความจุของเซ็นเซอร์จะเปลี่ยนตาม ทำให้สามารถวัดระดับความชื้นได้

1.อุปกรณ์ที่ต้องใช้

2.ต่ออุปกรณ์

เซนเซอร์วัดความชื้นในดินแบบ Capacitive Soil Moisture Sensor SNP-00136

 

Arduino UNO
Soil Moisture Sensor
5V
VCC
GND
GND
A0
AOUT

3.ลงโปรแกรม 

Copy โค้ดด้านล่าง

Arduino
1/* Change these values based on your observations */
2#define wetSoil 277   // Define max value we consider soil 'wet'
3#define drySoil 380   // Define min value we consider soil 'dry'
4
5// Define analog input
6#define sensorPin A0
7
8void setup() {  
9  Serial.begin(9600);
10}
11
12void loop() {
13  // Read the Analog Input and print it
14  int moisture = analogRead(sensorPin);
15  Serial.print("Analog output: ");
16  Serial.println(moisture);
17  
18  // Determine status of our soil
19  if (moisture < wetSoil) {
20    Serial.println("Status: Soil is too wet");
21  } else if (moisture >= wetSoil && moisture < drySoil) {
22    Serial.println("Status: Soil moisture is perfect");
23  } else {
24    Serial.println("Status: Soil is too dry - time to water!");
25  }
26  Serial.println();
27  
28  // Take a reading every second
29  delay(1000);
30}

3.ผลลัพธ์

โค้ดนี้ทำหน้าที่อ่านค่าความชื้นในดินจาก Capacitive Soil Moisture Sensor ที่เชื่อมต่อกับขาอนาล็อก A0 ของ Arduino โดยจะเปรียบเทียบค่าที่อ่านได้กับค่าที่กำหนดไว้สำหรับดินที่เปียกและแห้ง จากนั้นจะแสดงสถานะความชื้นของดินผ่าน Serial Monitor เป็น 3 สถานะ ได้แก่ "ดินเปียกเกินไป," "ความชื้นในดินเหมาะสม," และ "ดินแห้งเกินไป" เพื่อให้ผู้ใช้ทราบว่าควรให้น้ำต้นไม้หรือไม่ โค้ดจะทำการอ่านค่าทุก ๆ 1 วินาที

เซนเซอร์วัดความชื้นในดินแบบ Capacitive Soil Moisture Sensor SNP-00136