AI Lab for the Internet of Things

From sensors to intelligent self-deciding systems: lessons, projects, architectures, interactive simulation labs and a specialist AIoT assistant.

20Lesson

Smart Irrigation Controller

A node that measures soil moisture and opens the irrigation valve when needed, within safety limits.

IntermediateSmart AgricultureEducational design: not implemented on hardware

Educational content in scientific-draft form; a specialist should review it before it is adopted as an academic reference. No measurement or performance result that was not actually obtained is shown here.

The problem

Over- or under-irrigation.

Goal

Reduce water waste while keeping moisture within an acceptable range.

Components and requirements

  • ESP32
  • Soil-moisture sensor
  • Relay and solenoid valve
  • A suitable power supply

Sensors

  • soil-moisture

Microcontrollers

  • esp32

Communication protocols

  • mqtt

AI model

A threshold rule with reading smoothing; an optional forecasting model later.

System architecture

A node that reads and decides locally and sends the status over MQTT.

Wiring diagram

Educational text table (check your parts' datasheets before wiring):
moisture sensor → analogue pin
relay → digital pin
valve power supplied separately through the relay

Implementation steps

  1. Collect readings over several days to calibrate the threshold
  2. Smooth the readings with a moving average
  3. Implement the threshold rule with a maximum irrigation duration
  4. Send the status over MQTT
  5. Add a manual override

Code

Reading the sensor (initial skeleton)

CPPIllustrative, not implemented or tested
const int SOIL=34, RELAY=26;
void setup(){ pinMode(RELAY,OUTPUT); Serial.begin(115200);}
void loop(){
  int raw=analogRead(SOIL);
  Serial.println(raw);
  // the threshold is calibrated by your own experiment
  digitalWrite(RELAY, raw>3000 ? HIGH : LOW);
  delay(5000);
}

Expected outcomes

In theory: irrigate when moisture drops, without exceeding a maximum duration. (An outcome expected from the design, not measured)

These are results expected in theory from the design, not experimental results that were measured.

Project tests

  • Test the sensor readings in dry and wet soil
  • Test that the valve closes at the maximum duration
  • Test the device's behaviour when the network is lost

Ideas for research development

  • Forecast moisture with a time-series model
  • Integrate weather forecasts

Implementation status: Educational design: not implemented on hardware

Simulations and labs run inside your browser. Nothing you enter and none of the conversations is stored on the server. Privacy policy