Skip to main content
Technical Architecture & Logic Flow

How the AgriSense System Works

From soil capacitive sensing to optoisolated relay activation, explore how AgriSense automates precision crop watering without risking hardware damage.

System Signal Pipeline

Complete unidirectional signal and power flow from agricultural soil to pump actuation

  1. STAGE 1Soil MatrixMoist Root Zone
  2. STAGE 2Capacitive ProbeAnalog Voltage
  3. STAGE 3ADS1115 ADC16-Bit I2C Bus
  4. STAGE 4Raspberry Pi 3B+Python Logic Loop
DECISION

Moisture < Threshold?

Evaluates against crop moisture target

SWITCHING

5V Relay Module

COM & NO Contacts Close

ACTUATION

5V DC Submersible Pump

Powered by separate 5V rail

Crucial Electrical Engineering Principle

Strictly Isolated Power Circuits: Why Raspberry Pi Doesn’t Power the Pump

A frequent vulnerability in college IoT implementations is attempting to power inductive DC motor loads directly from the Raspberry Pi’s 5V or GPIO header. Doing so creates severe voltage dropouts, brownouts, unexpected kernel crashes, or permanent microcontroller burnout from back-EMF inductive flyback spikes.

Raspberry Pi Logic Circuit

Powered independently by an official 5V 2.5A micro-USB power brick. Supplies low-power 3.3V to the ADS1115 ADC and sends a tiny 5mA trigger signal from GPIO 17 to the relay’s optocoupler.

Pump Actuation Circuit

Powered by a distinct external 5V 1A DC adapter or USB power bank. The positive rail routes through the relay’s Normally Open (NO) and Common (COM) terminals to ensure complete galvanic isolation.

Step-by-Step Irrigation Cycle

The closed-loop feedback algorithm executed continuously by the AgriSense Python daemon

  1. 01

    Read Soil Moisture

    The capacitive probe creates an electrostatic field in the root zone. Changes in soil water permittivity modulate the analog voltage output (1.2V–3.0V) without galvanic metal oxidation.

  2. 02

    Analog to Digital Conversion

    The ADS1115 16-bit ADC samples the analog voltage and converts it into a high-precision 16-bit integer sent across the I2C bus (address 0x48) to the Raspberry Pi.

  3. 03

    Python Controller Processing

    The script converts raw ADC integer values into relative moisture percentages and evaluates against the specific crop's configured lower moisture threshold.

  4. 04

    Relay Circuit Switching

    If moisture is below the calibrated minimum threshold, Raspberry Pi sets GPIO 17 HIGH, triggering the relay's internal optocoupler and closing the COM to NO switch.

  5. 05

    Metered Water Delivery

    The 5V DC pump draws power from its independent external 5V power supply rail, pumping water through drip tubing for a predetermined pulse duration.

  6. 06

    Stabilization Soak Period

    The pump switches OFF and the script enters a 10–15 minute soak delay, allowing water to percolate through soil particles before re-evaluating root moisture.

Raspberry Pi Controller Source Code

agrisense_controller.py

Python 3 • RPi.GPIO & Adafruit_ADS1x15
import time
import RPi.GPIO as GPIO
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# GPIO Pin Configuration
RELAY_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(RELAY_PIN, GPIO.OUT)
GPIO.output(RELAY_PIN, GPIO.HIGH) # Relay is active-LOW (OFF)

# I2C and ADS1115 Setup
i2c = busio.I2C(board.SCL, board.SDA)
ads = ADS.ADS1115(i2c)
channel = AnalogIn(ads, ADS.P0)

# Calibrated ADC Thresholds (Sample for Loam Soil)
DRY_ADC_VALUE = 24500  # Raw reading in completely dry air
WET_ADC_VALUE = 11200  # Raw reading in saturated water

def get_moisture_percentage(raw_val):
    pct = ((DRY_ADC_VALUE - raw_val) / (DRY_ADC_VALUE - WET_ADC_VALUE)) * 100.0
    return max(0.0, min(100.0, pct))

def irrigation_loop(target_min_moisture=55.0, pump_run_seconds=6):
    print("AgriSense Monitoring Daemon Active...")
    while True:
        raw = channel.value
        moisture = get_moisture_percentage(raw)
        print(f"Current Soil Moisture: {moisture:.1f}% (ADC: {raw})")

        if moisture < target_min_moisture:
            print("Moisture below minimum threshold! Activating Relay...")
            GPIO.output(RELAY_PIN, GPIO.LOW)  # Engage Relay (Pump ON)
            time.sleep(pump_run_seconds)
            GPIO.output(RELAY_PIN, GPIO.HIGH) # Disengage Relay (Pump OFF)
            print("Pump interval complete. Waiting 10 minutes for water absorption...")
            time.sleep(600)  # Wait for soil matrix percolation
        else:
            time.sleep(15)   # Standard polling interval

* Note: Reference logic implemented on the AgriSense Raspberry Pi 3B+ testbench. Calibration constants (DRY_ADC_VALUE and WET_ADC_VALUE) must be calibrated according to specific field soil matrix conditions.

Explore Crop Specific Moisture Requirements

Check out target moisture ranges, soil percolation timing, and growth stages in the Crop Guide.

Open Crop Guide