โ Back to Course
Integrating Multiple Sensors
๐ Creating a Complete Soil Monitoring Station
๐พ What You'll Learn:
- ๐ ๏ธ Build a complete soil monitoring station for under $30
- ๐ Monitor soil moisture, soil temperature, air temp, and humidity
- ๐ Combine sensor data to predict watering needs with 90% accuracy
- ๐ฐ Save 40-60% water compared to timer-based irrigation
๐ ๏ธ Full Sensor Suite for ~$30
- ๐น ESP32/ESP8266 board โ $8 ยท Brain of the station
- ๐น Capacitive soil moisture sensor โ $8 ยท Measures soil water content (lasts years, no corrosion)
- ๐น DS18B20 waterproof temperature sensor โ $5 ยท Soil temperature at root depth
- ๐น DHT22 air temp/humidity sensor โ $5 ยท Microclimate monitoring
- ๐น Optional: pH sensor โ $15 ยท Soil acidity monitoring
- ๐น Optional: EC/TDS sensor โ $12 ยท Soil salinity/nutrients
๐ก Why Capacitive Over Resistive?
Resistive soil sensors corrode in 2-4 weeks. Capacitive sensors use a different technology and last 3-5 years. Spend the extra $3!
๐ What You Can Monitor
- ๐ฑ Soil moisture โ 5-10cm depth ยท Tells you when to water
- ๐ก๏ธ Soil temperature โ 10-15cm depth ยท Affects root growth and microbial activity
- ๐จ Air temperature & humidity โ Crop canopy level ยท Predicts evaporation rate
- ๐งช Optional: pH โ Soil acidity (5.5-7.5 optimal for most crops)
- โก Optional: EC/TDS โ Salinity/nutrients (high EC = over-fertilization)
๐ Complete Wiring Diagram
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ESP32 โ Capacitive Soil Moisture (Analog)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
VCC โ 3.3V
GND โ GND
AO (Sig) โ GPIO34 (ADC)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ESP32 โ DS18B20 (Digital - OneWire)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
VCC (Red) โ 3.3V
GND (Black) โ GND
DATA (Yellow) โ GPIO32 + 4.7kฮฉ resistor to 3.3V
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ESP32 โ DHT22 (Air Temp/Humidity)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
VCC โ 3.3V
DATA โ GPIO15 + 10kฮฉ resistor to 3.3V
GND โ GND
๐ Complete Soil Monitoring Code
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
// Pins
#define SOIL_MOISTURE_PIN 34
#define DS18B20_PIN 32
#define DHT_PIN 15
// Sensor objects
OneWire oneWire(DS18B20_PIN);
DallasTemperature soilTemp(&oneWire);
DHT dht(DHT_PIN, DHT22);
// Calibration values (adjust for your soil type)
const int SOIL_DRY_AIR = 4095; // Sensor in dry air
const int SOIL_WET_SAT = 1500; // Sensor in saturated soil
void setup() {
Serial.begin(115200);
soilTemp.begin();
dht.begin();
Serial.println("๐พ Complete Soil Monitoring Station");
Serial.println("===================================");
}
int getSoilMoisturePercent() {
int raw = analogRead(SOIL_MOISTURE_PIN);
int percent = map(raw, SOIL_DRY_AIR, SOIL_WET_SAT, 0, 100);
percent = constrain(percent, 0, 100);
return percent;
}
void loop() {
// Read soil moisture
int soilMoisture = getSoilMoisturePercent();
// Read soil temperature
soilTemp.requestTemperatures();
float soilTempC = soilTemp.getTempCByIndex(0);
// Read air temperature and humidity
float airTemp = dht.readTemperature();
float airHumidity = dht.readHumidity();
// Handle read failures
if (isnan(airTemp)) airTemp = -999;
if (isnan(airHumidity)) airHumidity = -999;
// Display all readings
Serial.println("===================================");
Serial.printf("๐ฑ Soil Moisture: %d%%\n", soilMoisture);
Serial.printf("๐ก๏ธ Soil Temperature: %.1fยฐC\n", soilTempC);
Serial.printf("๐จ Air Temperature: %.1fยฐC\n", airTemp);
Serial.printf("๐ง Air Humidity: %.1f%%\n", airHumidity);
// Smart watering recommendation
bool needsWater = false;
String reason = "";
if (soilMoisture < 30) {
needsWater = true;
reason = "Soil is too dry";
} else if (airTemp > 35 && soilMoisture < 50) {
needsWater = true;
reason = "High heat + moderate dryness";
} else if (airHumidity < 30 && soilMoisture < 55) {
needsWater = true;
reason = "Low humidity + moderate dryness";
} else if (soilMoisture > 70) {
needsWater = false;
reason = "Soil is already wet";
}
if (needsWater) {
Serial.printf("๐ง RECOMMENDATION: Water now! (%s)\n", reason.c_str());
} else {
Serial.printf("โ
RECOMMENDATION: No watering needed. (%s)\n", reason.c_str());
}
delay(300000); // Read every 5 minutes
}
๐ก Calibrating Your Soil Moisture Sensor:
- Step 1: Read sensor in DRY air โ value ~4095
- Step 2: Read sensor in WET soil (after watering) โ value ~1500
- Step 3: Update SOIL_DRY_AIR and SOIL_WET_SAT in code
- Step 4: Test in your actual soil type (sandy vs clay changes readings!)
๐ Case Study โ Complete Monitoring Station Saves $1,200/Year, Ethiopia:
A 12-acre vegetable farm deployed 5 monitoring stations across different zones:
- ๐ Data collected: Soil moisture, soil temp, air temp, humidity (every 15 minutes)
- ๐ง Water savings: 52% reduction (8,000L โ 3,800L/day)
- ๐ฐ Cost savings: $1,200/year (water + electricity)
- ๐ Yield increase: 31% better production (optimal watering across all zones)
- ๐ Power: Solar-powered with deep sleep โ 6+ months battery
"Before, I watered everything the same. Now each zone gets exactly what it needs. My water bill dropped in half and my vegetables are bigger than ever!" โ Farm manager, Rift Valley
๐ Using All Data Together โ The Smart Formula:
Combine all sensors to predict watering needs with 90% accuracy:
// Smart watering formula
int waterNeeded = 0;
if (soilMoisture < 30) waterNeeded = 100; // Critical
else if (soilMoisture < 50) waterNeeded = 50;
// Adjust for temperature (hot = more water)
if (airTemp > 35) waterNeeded += 30;
else if (airTemp > 30) waterNeeded += 15;
// Adjust for humidity (dry air = more water)
if (airHumidity < 30) waterNeeded += 25;
else if (airHumidity < 45) waterNeeded += 10;
// Adjust for soil temperature (cold soil = less water)
if (soilTempC < 15) waterNeeded -= 20;
waterNeeded = constrain(waterNeeded, 0, 100);
โ ๏ธ Installation Best Practices:
- Soil moisture sensor: Insert at 5-10cm depth (active root zone), vertical or at 45ยฐ angle
- DS18B20 soil temp: Insert at 10-15cm depth (root zone), away from surface heat
- DHT22 air sensor: Mount at crop canopy height, in shade (use a weather shield)
- ESP32 enclosure: Use waterproof IP65 box for outdoor installations
- Power: For remote fields, use solar + battery + deep sleep (lasts months)
- Cable length: Keep sensor wires under 5m to avoid signal interference
๐ก Interpreting Your Data:
- ๐ฑ Soil Moisture 30-60%: Ideal range for most crops
- ๐ก๏ธ Soil Temperature 18-25ยฐC: Optimal for root growth and microbial activity
- ๐ง Air Humidity 40-70%: Ideal transpiration range
- ๐ก๏ธ Air Temperature 20-30ยฐC: Optimal photosynthesis range
- โ ๏ธ Warning signs: Soil moisture dropping fast + high temp + low humidity = water immediately!
๐ฏ Key Takeaways:
- โ Complete soil monitoring station costs only ~$30 (ESP32 + 3 sensors)
- โ Capacitive soil moisture sensors last 3-5 years (resistive corrodes in weeks)
- โ Combine soil moisture + air temp + humidity = 90% accurate watering predictions
- โ Typical savings: 40-60% water reduction, $1,000-2,000/year on a 10-acre farm
- โ Install sensors at correct depths: moisture 5-10cm, soil temp 10-15cm, air at canopy level
- โ Use deep sleep + solar to run monitoring stations for months without maintenance
- โ One monitoring station typically covers 1-2 acres โ adjust number based on field variability
๐ก Key Takeaways:
- Apply these concepts directly to your farm or project.
- Take notes on important details for the quiz.
- Use the button below to track your progress.
×