Complete guide to measuring soil moisture with resistive sensors
Soil moisture sensors measure the water content in soil by detecting changes in electrical resistance between two conductive probes.
| Operating Voltage | 3.3V-5V |
| Output Signal | Analog & Digital |
| Probe Length | 5cm-10cm (typical) |
| Current Consumption | ~35mA |
| Interface | PH2.0-3P connector |
// Basic Soil Moisture Sensor Example
#define SOIL_MOISTURE_PIN A0
void setup() {
Serial.begin(9600);
}
void loop() {
int moistureValue = analogRead(SOIL_MOISTURE_PIN);
int moisturePercent = map(moistureValue, 1023, 300, 0, 100);
Serial.print("Raw Value: ");
Serial.print(moistureValue);
Serial.print(" | Moisture: ");
Serial.print(moisturePercent);
Serial.println("%");
delay(1000);
}
// Soil Moisture with Calibration
#define SOIL_PIN A0
int dryValue = 1023; // Value in dry soil
int wetValue = 300; // Value in wet soil
void setup() {
Serial.begin(9600);
calibrateSensor();
}
void calibrateSensor() {
Serial.println("Dry calibration - place sensor in dry soil and enter value:");
while(!Serial.available());
dryValue = Serial.parseInt();
Serial.println("Wet calibration - place sensor in wet soil and enter value:");
while(!Serial.available());
wetValue = Serial.parseInt();
Serial.print("Calibration complete. Dry: ");
Serial.print(dryValue);
Serial.print(" Wet: ");
Serial.println(wetValue);
}
void loop() {
int sensorValue = analogRead(SOIL_PIN);
int moisturePercent = map(sensorValue, dryValue, wetValue, 0, 100);
moisturePercent = constrain(moisturePercent, 0, 100);
Serial.print("Soil Moisture: ");
Serial.print(moisturePercent);
Serial.println("%");
delay(2000);
}
// Automatic Plant Watering System
#define SOIL_PIN A0
#define RELAY_PIN 3
#define THRESHOLD 30 // Water when moisture < 30%
void setup() {
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Start with pump off
Serial.begin(9600);
}
void loop() {
int moisture = readMoisture();
if(moisture < THRESHOLD) {
waterPlant();
}
delay(3600000); // Check every hour
}
int readMoisture() {
int sensorValue = analogRead(SOIL_PIN);
return map(sensorValue, 1023, 300, 0, 100);
}
void waterPlant() {
Serial.println("Watering plant...");
digitalWrite(RELAY_PIN, LOW); // Turn pump on
delay(5000); // Water for 5 seconds
digitalWrite(RELAY_PIN, HIGH); // Turn pump off
Serial.println("Watering complete");
}
Monitor soil moisture and alert when watering is needed.
Water plants automatically when soil gets dry.
Track soil moisture remotely with WiFi/Bluetooth.
Record soil moisture over time for analysis.
Monitor several plants with one controller.
Automate moisture, temp, and humidity.
// Components needed:
- Multiple soil moisture sensors
- ESP32 with LoRa
- Solar power system
- Water valve control
- Weather station sensors
- Cloud database
// Features:
1. Distributed soil moisture monitoring
2. Weather-based irrigation
3. Remote monitoring via web/mobile
4. Water usage optimization
5. Predictive watering
6. Alert system
// Implementation Tips:
- Use sleep modes for battery operation
- Implement mesh networking for large areas
- Add rain detection to skip watering
- Create moisture maps of fields
- Integrate weather forecasts
- Add manual override capability
| Mistake | Consequence | Solution |
|---|---|---|
| No calibration | Inaccurate readings | Always calibrate for your specific soil |
| Continuous power | Probe corrosion | Power only when taking readings |
| Poor probe placement | Irrelevant measurements | Place near root zone |
| Ignoring soil type | Wrong moisture assessment | Adjust thresholds for soil characteristics |
| No maintenance | Degraded performance | Regular cleaning and inspection |