Soil Moisture Sensor หลักการทำงานโดยทั่วไปคือการวัดค่าความต้านทานไฟฟ้าของดิน ซึ่งจะแปรผันตามปริมาณความชื้น
1.ต่ออุปกรณ์
Soil Moisture Sensor > Arduino UNO
VCC>5VGND>GNDAO>A0
2.ลงโปรแกรม
Copy โค้ดด้านล่าง
Arduino
1const int soilSensor = A0;
2
3void setup() {
4 Serial.begin(9600);
5 pinMode(soilSensor,INPUT);
6}
7
8void loop() {
9 int soilMoisture = analogRead(soilSensor);
10 Serial.print("Soil Moisture: ");
11 Serial.println(soilMoisture);
12 delay(1000);
13}1const int soilSensor = A0;
2
3void setup() {
4 Serial.begin(9600);
5 pinMode(soilSensor,INPUT);
6}
7
8void loop() {
9 int soilMoisture = analogRead(soilSensor);
10 Serial.print("Soil Moisture: ");
11 Serial.println(soilMoisture);
12 delay(1000);
13}
3.ผลลัพธ์
ใน Serial Monitor จะแสดงความต้านทานไฟฟ้า เมื่อนำส่วนส้อมไปเสียบในดินที่มีความชื้น จะพบว่าความต้านทานไฟฟ้าลดลง (ค่านี้ไม่ใช้ความชื้นในดินโดยตรง ต้องทำการเปรียบเทียบค่า)
.png?alt=media&token=9aabd6fe-b4c7-4906-9317-3d87cef6cfed)
