Cảm biến độ ẩm của đất
Để tạo hệ thống tưới nước tự động cho cây hay vườn thì không thể thiếu module cảm biến độ ẩm đất. Cảm biến sẽ giúp bạn xác định được độ ẩm của đất qua đầu dò cắm sâu xuống đất và trả về giá trị Analog hoặc Digital qua 2 chân, để giáo tiếp với vi điều khiển hoặc vi xử lý và xử lý những tác vụ sau đó.
THÔNG SỐ KỸ THUẬT
- Điện áp hoạt động: 3.3~5VDC
- Tín hiệu đầu ra:
- Analog: theo điện áp cấp nguồn tương ứng. (Ở cân A0)
- Digital: High hoặc Low (Ở chân D0)
- Kích thước: 3 x 1.6cm.
DEMO THỬ NGHIỆM VỚI MODULE CẢM BIẾN ĐỘ ẨM ĐẤT THÔNG QUA ARDUINO
- Sơ đồ chân
- Code mẫu
int rainPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 800;
void setup(){
pinMode(rainPin, INPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(rainPin);
Serial.print(sensorValue);
if(sensorValue < thresholdValue){
Serial.println(” – Doesn’t need watering”);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
else {
Serial.println(” – Time to water your plant”);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
}
delay(500);
}