Soil and Agriculture Sensors
Soil and agriculture sensors are used to measure conditions that affect plant growth, irrigation, soil quality, and agricultural productivity.
They are especially useful in smart farming and IoT agriculture.
Typical parameters include:
- Soil moisture
- Soil temperature
- Soil pH
- Electrical conductivity (EC)
- Salinity
- Nutrients such as NPK
- Rainfall
- Water level
- Air temperature and humidity
- Light intensity
Basic smart-farming system:
FARM ↓ ┌────────┴────────┐ ↓ ↓ Soil Sensors Weather Sensors ↓ ↓ └────────┬────────┘ ↓ ESP32 ↓ Decision / Control ↓ Water Pump ↓ Irrigation
1. Soil Moisture Sensor
A soil moisture sensor measures the amount of water/moisture present in soil.
This is one of the most commonly used agriculture sensors.
Dry Soil ↓ Low moisture Wet Soil ↓ High moisture
The controller can use this information to decide when to turn the irrigation system ON.
2. Why Soil Moisture Matters
Plants need an appropriate amount of water.
Too little:
Dry soil ↓ Plant stress ↓ Poor growth
Too much:
Waterlogged soil ↓ Less oxygen around roots ↓ Root problems
Therefore:
Measure moisture ↓ Determine irrigation requirement ↓ Control water
3. Resistive Soil Moisture Sensor
A common beginner sensor has two exposed metal probes.
Probe 1 Probe 2 │ │ ↓ ↓ ─┐ ┌─ │ SOIL │ │ │ ─┘ └─
The electrical resistance between the probes changes with soil moisture.
Generally:
More moisture ↓ More conductivity ↓ Resistance changes
4. Problems with Resistive Sensors
Exposed metal probes can suffer from:
- Corrosion
- Electrolysis
- Soil chemistry effects
- Changing readings over time
Because of this, they are good for basic experiments, but not always ideal for long-term agricultural deployment.
5. Capacitive Soil Moisture Sensor
A capacitive soil moisture sensor measures changes in capacitance associated with the soil's dielectric properties.
It does not require exposed conductive electrodes to directly pass current through the soil in the same way as a resistive probe.
Basic concept:
Soil moisture ↓ Dielectric properties change ↓ Capacitance changes ↓ Sensor output changes ↓ ESP32
Capacitive sensors are generally preferred over cheap resistive probes for longer-term hobby/IoT installations.
6. Capacitive vs Resistive Soil Sensor
| Feature | Resistive | Capacitive |
|---|---|---|
| Measurement principle | Resistance/conductivity | Capacitance/dielectric change |
| Exposed electrodes | Usually yes | Usually no |
| Corrosion | Higher risk | Lower |
| Long-term use | Less suitable | Generally better |
| Cost | Very low | Low |
| Common use | Basic projects | Smart agriculture |
7. Soil Moisture Sensor with ESP32
A typical analog capacitive sensor can be connected like:
Sensor ESP32 VCC ────────────── 3.3V* GND ────────────── GND AO ────────────── GPIO 34
* Check your exact sensor's supply requirements.
Example:
#define SOIL_PIN 34 void setup() { Serial.begin(115200); } void loop() { int value = analogRead(SOIL_PIN); Serial.print("Soil Sensor: "); Serial.println(value); delay(1000); }
The direction of the reading depends on the particular sensor.
8. Converting Soil Reading to Percentage
A raw sensor value is not automatically a true moisture percentage.
You normally need calibration.
For example:
Dry calibration = 3000 Wet calibration = 1200
You can map the raw value to an approximate percentage.
Conceptually:
Dry → 0% Wet → 100%
For sensors where a lower ADC value means wetter soil, a simple mapping can be:
int moisture = map(value, 3000, 1200, 0, 100); moisture = constrain(moisture, 0, 100);
But the calibration values must be determined experimentally for your sensor, soil, depth, and application.
9. Why Calibration Is Important
The same sensor can give different readings in:
- Sandy soil
- Clay soil
- Garden soil
- Compost
- Different fertilizer concentrations
Even the same soil can produce different readings depending on:
- Sensor depth
- Temperature
- Soil density
- Salinity
Therefore:
Raw ADC value ≠ universal moisture %
Calibration is essential.
10. Soil Temperature Sensor
Soil temperature affects:
- Seed germination
- Root growth
- Microbial activity
- Nutrient availability
- Plant development
A waterproof temperature sensor such as DS18B20 can be used.
Soil ↓ DS18B20 ↓ ESP32 ↓ Temperature
Example:
Soil Temperature: 24.6°C
11. Soil pH Sensor
pH indicates whether a substance is acidic, neutral, or alkaline.
The basic scale is:
0 ←──── Acidic ──── 7 ──── Alkaline ────→ 14 Neutral
Different crops prefer different soil pH ranges.
A soil pH measurement system typically uses:
pH Probe ↓ pH Interface Circuit ↓ ESP32 / Arduino ↓ pH Calculation
12. Why Soil pH Matters
Soil pH affects nutrient availability.
For example:
Incorrect pH ↓ Nutrient availability changes ↓ Plant may show deficiencies
Therefore farmers can use pH information to make better soil-management decisions.
13. Soil pH Measurement
A typical pH system contains:
- pH electrode/probe
- Signal-conditioning circuit
- ADC/controller
- Calibration solutions
The probe itself should not simply be connected directly to an ESP32 GPIO.
Concept:
Soil ↓ pH Probe ↓ Signal Circuit ↓ ADC ↓ ESP32
14. pH Calibration
pH probes require calibration.
Common laboratory calibration uses standard buffer solutions such as:
pH 4 pH 7 pH 10
The exact calibration procedure depends on the probe and interface.
A simplified concept:
Known Buffer ↓ Sensor Reading ↓ Calibration ↓ Unknown Soil ↓ Estimated pH
15. NPK Sensor
NPK refers to three important plant nutrients:
N → Nitrogen P → Phosphorus K → Potassium
These nutrients play different roles in plant growth.
Nitrogen
Important for:
- Vegetative growth
- Leaf development
Phosphorus
Important for:
- Root development
- Energy-related plant processes
Potassium
Important for:
- Overall plant health
- Water regulation
- Stress resistance
16. NPK Measurement
Some commercial/industrial soil nutrient sensors use electrical, chemical, or ion-selective measurement methods.
Some low-cost agricultural sensor modules communicate digitally, often through interfaces such as:
RS485 Modbus RTU
Example architecture:
NPK Soil Sensor ↓ RS485 ↓ ESP32 ↓ Modbus Data ↓ N / P / K values
17. RS485 NPK Sensor
A typical system may look like:
NPK Sensor │ │ RS485 ↓ MAX485 / RS485 Interface ↓ ESP32
RS485 is useful because it supports:
- Longer cable distances
- Better noise immunity than simple TTL wiring
- Multi-device bus configurations
The exact protocol and register addresses depend on the sensor manufacturer.
18. Soil Electrical Conductivity (EC)
Electrical conductivity (EC) measures how easily electrical current passes through the soil solution.
It is influenced by dissolved ions/salts.
Higher EC can indicate:
More dissolved ions ↓ Higher conductivity
But interpretation depends on soil, moisture, temperature, and the measurement method.
19. Soil Salinity
High soil salinity can negatively affect many plants.
Concept:
Salt accumulation ↓ Higher soil EC ↓ Water uptake becomes more difficult ↓ Plant stress
Therefore EC/salinity monitoring can be useful in:
- Irrigation management
- Greenhouses
- Hydroponics
- Agricultural research
20. EC Sensor
Basic concept:
Soil / Nutrient Solution ↓ EC Probe ↓ Signal Circuit ↓ ESP32 ↓ EC Reading
EC sensors generally require temperature compensation for better accuracy.
21. Rain Sensor
A rain sensor detects the presence of water/rain.
A simple module may contain a conductive plate:
Rain ↓ ↓ ↓ ↓ ↓ ┌────────────────┐ │ Conductive │ │ Sensor Plate │ └────────────────┘ ↓ Resistance/ Conductivity change ↓ ESP32
22. Rain Sensor Applications
It can be used for:
- Automatic rain detection
- Closing windows
- Retracting awnings
- Smart irrigation control
- Weather stations
- Agriculture automation
Example:
Rain detected ↓ ESP32 ↓ Stop irrigation
23. Important Limitation of Cheap Rain Sensors
The common exposed-track rain sensor boards can corrode over time.
For long-term outdoor systems, consider:
- Better-designed rain sensors
- Optical rain sensors
- Tipping-bucket rain gauges
- Weather-station-grade sensors
depending on what you actually need to measure.
24. Rain Gauge
A rain gauge measures rainfall amount rather than simply detecting whether it is raining.
A tipping-bucket rain gauge works approximately like:
Rain ↓ Funnel ↓ Small bucket ↓ Bucket tips ↓ Magnetic/reed pulse ↓ ESP32
If each tip represents a known volume:
Rainfall = Number of Tips × Volume per Tip
The exact conversion depends on the gauge.
25. Water Level Sensor for Agriculture
Water-level sensors are useful for:
- Irrigation tanks
- Reservoirs
- Water storage
- Underground tanks
- Hydroponics
Example:
Water Tank ┌─────────────────┐ │ │ │ WATER │ │ │ │ ↓ │ │ Level Sensor │ └─────────────────┘
The ESP32 can automatically control a pump.
26. Automatic Irrigation
This is one of the most useful IoT agriculture projects.
Components:
- ESP32
- Soil moisture sensor
- Relay/MOSFET
- Water pump
- Water tank
- Pipes
- Optional rain sensor
System:
SOIL ↓ Moisture Sensor ↓ ESP32 ↓ ┌───────┴───────┐ ↓ ↓ Pump ON Pump OFF ↓ Irrigation
27. Automatic Irrigation Logic
For example:
Moisture < 30% ↓ Start pump Moisture > 60% ↓ Stop pump
Using two thresholds prevents the pump from rapidly switching ON/OFF around one boundary.
This is called hysteresis.
28. Irrigation with Rain Detection
You can combine moisture and rain data:
┌──────────────┐ │ ESP32 │ └──────┬───────┘ │ ┌────────┼────────┐ ↓ ↓ ↓ Soil Rain Water Moisture Sensor Level ↓ ↓ ↓ └────────┼────────┘ ↓ Pump Control
Example:
Soil dry + No rain ↓ Pump ON Soil dry + Rain detected ↓ Pump OFF
29. Smart Agriculture with DHT22
Agriculture monitoring can also include air conditions.
DHT22 ↓ Temperature Humidity ↓ ESP32
Now the system can monitor:
Soil moisture Soil temperature Air temperature Air humidity Rain Water level
This gives a more complete picture of the growing environment.
30. Agriculture Monitoring Dashboard
ESP32 can send sensor data over Wi-Fi.
Sensors ↓ ESP32 ↓ Wi-Fi ↓ Server / Cloud ↓ Web Dashboard
Example dashboard:
┌──────────────────────────┐ │ SMART FARM │ ├──────────────────────────┤ │ Soil Moisture: 42% │ │ Soil Temp: 25.4°C │ │ Air Temp: 28.1°C │ │ Humidity: 67% │ │ Rain: NO │ │ Tank: 78% │ │ Pump: OFF │ └──────────────────────────┘
31. Sensor-Based Irrigation vs Timer Irrigation
Timer-Based
8:00 AM ↓ Pump ON ↓ 10 minutes ↓ Pump OFF
Problem:
It doesn't know whether the soil actually needs water.
Sensor-Based
Measure soil ↓ Is soil dry? ↙ ↘ YES NO ↓ ↓ Pump ON Pump OFF
Sensor-based irrigation can respond to actual conditions.
32. Smart Irrigation with Multiple Conditions
A better system can use several conditions:
IF soil moisture < threshold AND rain is not detected AND water tank level is sufficient THEN pump ON
Otherwise:
Pump OFF
This is much safer than using only one sensor.
33. Soil Moisture + Pump Example
Simplified ESP32 logic:
#define SOIL_PIN 34 #define RELAY_PIN 26 void setup() { Serial.begin(115200); pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); } void loop() { int soil = analogRead(SOIL_PIN); Serial.println(soil); if (soil > 2500) { // Dry soil digitalWrite(RELAY_PIN, HIGH); } else { // Wet soil digitalWrite(RELAY_PIN, LOW); } delay(1000); }
Important: Relay modules can be active LOW or active HIGH, so the ON/OFF logic may need to be reversed for your module.
Also, never power a pump directly from an ESP32 GPIO.
34. Pump Safety
A water pump typically requires much more current than an ESP32 GPIO can provide.
Use:
ESP32 ↓ Relay / MOSFET Driver ↓ External Power Supply ↓ Pump
For DC pumps, a properly rated MOSFET driver is often preferable for efficient switching.
For inductive loads, use appropriate protection such as a flyback diode where applicable.
35. Soil Sensors in Different Farming Systems
Open Field
Useful sensors:
Soil moisture Rain Temperature EC Weather
Greenhouse
Useful sensors:
Temperature Humidity Light Soil moisture CO₂ EC pH
Hydroponics
Useful sensors:
pH EC Water temperature Water level
Smart Nursery
Useful sensors:
Soil moisture Temperature Humidity Light Water level
36. Hydroponics
Hydroponics grows plants without conventional soil.
A basic monitoring system can measure:
Water ↓ pH EC Temperature Level ↓ ESP32
For example:
pH too low ↓ Warning EC too high ↓ Warning Water level low ↓ Pump / Refill
37. Light Monitoring in Agriculture
Plants require appropriate light.
A light sensor can measure:
Light intensity ↓ ESP32 ↓ Control shade / grow lights
Depending on the application, sensors such as LDRs or digital light sensors can be used.
For more meaningful plant-light measurement, specialized sensors for parameters such as PAR/PPFD may be more appropriate than a simple LDR.
38. Soil Moisture Sensor Placement
Sensor placement matters.
Too shallow ↓ May measure surface moisture Too deep ↓ May not represent root-zone moisture
The sensor should generally be placed where you want to monitor the plant's relevant root-zone moisture.
Different crops have different root structures, so there is no universal depth.
39. Multiple Soil Sensors
For a larger field:
Zone 1 → Moisture Sensor Zone 2 → Moisture Sensor Zone 3 → Moisture Sensor Zone 4 → Moisture Sensor
Then:
ESP32 / | \ Z1 Z2 Z3 ↓ ↓ ↓ Pump1 Pump2 Pump3
This allows zone-based irrigation.
40. Agriculture IoT Architecture
A larger system could look like:
SMART FARM │ ┌─────────────┼──────────────┐ ↓ ↓ ↓ Soil Sensors Weather Water System ↓ ↓ ↓ └─────────────┼──────────────┘ ↓ ESP32 ↓ Wi-Fi ↓ Cloud Server ↓ Web Dashboard ↓ Farmer's Phone
41. Important Comparison
| Sensor | Measures | Main Application |
|---|---|---|
| Resistive soil sensor | Moisture-related resistance | Basic projects |
| Capacitive soil sensor | Soil moisture | Smart irrigation |
| DS18B20 | Temperature | Soil/environment |
| pH probe | Acidity/alkalinity | Soil/hydroponics |
| NPK sensor | Nutrient-related parameters | Soil analysis |
| EC sensor | Conductivity | Salinity/nutrients |
| Rain sensor | Rain presence | Irrigation/weather |
| Rain gauge | Rainfall amount | Weather monitoring |
| Water-level sensor | Water level | Tank/pump control |
42. Common Problems
Soil Moisture
- Sensor calibration
- Different soil types
- Sensor placement
- Salinity effects
pH
- Probe calibration
- Probe maintenance
- Temperature effects
- Poor-quality probes
NPK
- Sensor-specific calibration
- Soil conditions
- Communication/protocol configuration
EC
- Temperature effects
- Probe calibration
- Soil moisture dependence
Rain Sensor
- Corrosion
- Dirt accumulation
- False readings from water droplets
43. Best Sensor Selection
Choose a capacitive soil sensor when:
You need affordable long-term soil-moisture monitoring.
Choose a resistive probe when:
You need a very simple demonstration or low-cost experiment.
Choose a load/industrial soil moisture system when:
You need more reliable agricultural measurements.
Choose a pH sensor when:
Soil or nutrient-solution acidity is important.
Choose an EC sensor when:
You need information about dissolved ions/salinity.
Choose an NPK sensor when:
You need nutrient-related measurements and have a suitable calibrated sensor.
44. Complete Smart Farming Example
A practical IoT farm can combine:
SMART FARM │ ┌────────────┼────────────┐ ↓ ↓ ↓ Soil Moisture DHT22 Rain ↓ ↓ ↓ └────────────┼────────────┘ ↓ ESP32 ↓ ┌─────────┼─────────┐ ↓ ↓ ↓ Pump Display Wi-Fi ↓ ↓ Irrigation Dashboard
Advanced version:
Soil Moisture Soil Temperature pH EC NPK Rain Air Temperature Humidity Water Level Light ↓ ESP32 ↓ Data Processing ↓ Automatic Irrigation ↓ Cloud Dashboard ↓ Mobile Notification
45. Key Points to Remember
Soil Moisture → Determines how wet/dry the soil is. Resistive Sensor → Measures moisture-related resistance/conductivity. Capacitive Sensor → Measures moisture-related changes in dielectric properties. Soil Temperature → Important for roots and plant growth. pH → Indicates acidity/alkalinity. NPK → Nitrogen, Phosphorus and Potassium. EC → Indicates electrical conductivity related to dissolved ions/salts. Rain Sensor → Detects rain/water presence. Rain Gauge → Measures rainfall amount. Water Level Sensor → Determines available irrigation water. Smart Irrigation → Uses sensor data to control water automatically.
Complete concept
🌱 PLANT │ ┌───────────┼───────────┐ ↓ ↓ ↓ WATER SOIL WEATHER ↓ ↓ ↓ Moisture pH/EC Rain/Temp ↓ ↓ ↓ └───────────┼───────────┘ ↓ ESP32 ↓ Decision Making ↓ ┌──────┴──────┐ ↓ ↓ Pump ON Pump OFF ↓ Irrigation ↓ 🌱