Moisture sensor allows arduino to read amount of moisture present in soil. Sensor consists of two parts:


Simple here, you put it into the soil. Probe will pass currency through soild and read resistance level. If in soil is more water the resistance is lower otherwise resistance will be high.

Detector module with potentiometer

This module have one analog and digital output. Analog output will allow you to read approximation moisture level in range:

  • Dry soil: 0 ~300
  • Humid soil: 300~700
  • In water: 700~950

Digital output is configured using potentiometer. You need to set threshold beyond which the digital output changes from high to low.



Example code

const short MOISTURE_THRESHOLD = 10; const short DRY_SOIL = 300 + MOISTURE_THRESHOLD; const short HUMID_SOIL = 700 + MOISTURE_THRESHOLD; void setup() { Serial.begin(9600); } void loop() { int moisture = analogRead(A0); moisture = map(moisture, 0, 1023, 1023, 0); Serial.print("Moisture Sensor: "); Serial.print(moisture); Serial.println(); if (moisture <= DRY_SOIL) { Serial.println("Dry soil"); } else if (moisture <= HUMID_SOIL) { Serial.println("Humid soil"); } else { Serial.println("In Water!"); } delay(1000); }