York St John University β COM6017M: The Internet of Things (Level 6)
This project implements a Smart Irrigation System that combines IoT, Machine-to-Machine (M2M) communication, Edge AI, and cloud analytics to automate watering based on real sensor data.
Unlike basic timer-based irrigation, this system performs local decision-making at the edge:
- A rule-based gate with hysteresis decides WHEN to irrigate (safe and explainable).
- A Random Forest dose regressor predicts HOW MUCH to irrigate (pump duration in seconds), running on a Raspberry Pi Edge AI node.
Telemetry and decisions are uploaded to ThingSpeak for monitoring and analysis.
Manual irrigation and fixed schedules often waste water and fail to adapt to changing conditions (soil moisture drift, indoor heating, humidity, day/night cycles). This project addresses that by:
- continuously sensing soil and environment,
- making control decisions locally (Edge AI),
- applying controlled irrigation doses via a peristaltic pump,
- logging and visualising the system behaviour in the cloud.
- Real sensors: 2Γ soil moisture, DHT22 (temperature + humidity), LDR (light)
- Closed-loop control: sensor β edge inference β command β actuator
- M2M communication:
- UART: Arduino β ESP32
- Bluetooth SPP: ESP32 β Raspberry Pi
- Edge AI:
- ON/OFF gating using soil_avg hysteresis
- Dose selection using RandomForestRegressor (seconds)
- Cloud visibility (ThingSpeak):
- live telemetry, decision flag, and watering duration
- Safety-first actuation:
- timed pump activation, clamp limits, and a dry-run mode
The following diagrams document the overall design and data flow of the system:
-
Arduino UNO R4 WiFi (Sensor + Actuator Node)
- Reads sensors
- Executes timed pump actuation via TIP122 driver
- Sends telemetry to ESP32 via UART
- Receives commands from ESP32 via UART
-
ESP32 (Gateway + Cloud Uplink)
- Parses UART telemetry from Arduino
- Forwards telemetry to Raspberry Pi over Bluetooth SPP
- Receives control commands from Raspberry Pi and relays them to Arduino
- Uploads telemetry + decisions to ThingSpeak over HTTP
-
Raspberry Pi (Edge AI Node)
- Receives telemetry via Bluetooth SPP
- Runs real-time control logic:
- ON/OFF hysteresis gate
- Random Forest regression for pump duration
- Sends commands back to ESP32 (
CMD:...;SEC:...)
[Soil1, Soil2, DHT22, LDR]
β
Arduino UNO R4 (sensing + actuation)
β UART
ESP32 Gateway (routing + cloud)
β Bluetooth SPP
Raspberry Pi (Edge AI inference)
β Bluetooth SPP commands
ESP32 Gateway
β UART commands
Arduino (timed pump control)
ESP32 β ThingSpeak (HTTP)
Architecture diagrams are stored in
docs/diagrams/.
The Raspberry Pi sends a single-line command:
CMD:<WATER_ON|WATER_OFF>;SEC:<int>\n
Examples:
CMD:WATER_OFF;SEC:0CMD:WATER_ON;SEC:14
The ESP32 forwards the same command over UART to the Arduino. The Arduino parses it deterministically and (if actuation is enabled) runs the pump for SEC seconds.
Early iterations used a TinyML-style binary classifier trained on a synthetic dataset to validate the end-to-end pipeline (data collection β cloud β training β deployment). This baseline is kept for documentation and comparison, but it is not the final controller.
The deployed system uses a two-layer controller:
- ON/OFF gating (explainable, safe)
- Computes
soil_avg = (soil1 + soil2) / 2 - Applies hysteresis thresholds to prevent flapping:
- Start watering when the soil is dry (above a dry threshold)
- Stop watering once the soil reaches a wet threshold
- Dose prediction (Edge AI model)
- A RandomForestRegressor predicts
watering_seconds - Output is snapped to an allowed set:
{8, 14, 18, 24}seconds
Trainingβserving contract
- The production model is exported with an explicit feature list to prevent silent feature-order bugs:
models/rf_dose_regressor_prod.joblibmodels/rf_dose_features_prod.json
Decision-time features only
- Training includes a strict βproduction modeβ filter so the model only uses features available at inference time.
The ESP32 uploads telemetry and control signals to ThingSpeak.
- field1 β
soil1 - field2 β
soil2 - field3 β
temperature_c - field4 β
humidity_percent - field5 β
light_ldr - field6 β
decision_flag(0= WATER_OFF,1= WATER_ON) - field7 β
watering_seconds(0or one of{8,14,18,24})
firmware/
arduino_edge/ # Arduino sensor + actuator node
esp32_gateway/ # ESP32 gateway: UART β BT β ThingSpeak
edge/
raspberry_pi/
app/ # BT inference service (real-time control)
model/ # model loading utilities
config/ # runtime config
scripts/
build_training_set.py # window extraction + feature engineering
train_rf_dose_model.py # RF regressor training + evaluation
smoke_test_prod_inference.py
models/
rf_dose_regressor_prod.joblib
rf_dose_features_prod.json
data/
labels/irrigation_events.csv
docs/
project_log.md
diagrams/
figures/
The electronic circuit was validated using a simulation-based approach during early development. The schematic includes:
- dual soil moisture sensors (analogue inputs),
- DHT22 temperature and humidity sensor,
- LDR for ambient light sensing,
- TIP122 transistor driver stage for the peristaltic pump.
The simulation files and notes are stored in hardware/tinkercad/.
- Arduino UNO R4 WiFi
- ESP32
- Raspberry Pi
- Sensors: 2Γ soil moisture, DHT22, LDR
- Actuator: peristaltic pump + TIP122 driver + flyback diode + base resistor
- Flash Arduino firmware: reads sensors, sends UART telemetry, receives commands.
- Flash ESP32 gateway: reads UART telemetry, talks BT SPP to RPi, uploads to ThingSpeak.
- On Raspberry Pi:
- pair with ESP32 via Bluetooth SPP
- bind RFCOMM device (e.g.,
/dev/rfcomm0) - run the inference service (real-time control loop)
Detailed setup notes and development history are tracked in
docs/project_log.md.
- The Arduino supports a dry-run / log-only mode so testing can be performed without energising the pump.
- Timed irrigation uses non-blocking logic and includes a maximum duration clamp to avoid runaway watering.
- Recommended: verify pump routing into a container before watering a real plant.
This artefact demonstrates:
- IoT sensing + actuation
- M2M communication (UART + Bluetooth)
- Edge AI inference on-device (Raspberry Pi)
- Cloud analytics/visualisation (ThingSpeak)
It supports responsible water use and aligns with sustainable resource management goals.
This project pushed my understanding of:
IoT & Edge Computing:
- Real-world M2M communication protocols (UART, Bluetooth SPP)
- Trade-offs between edge processing vs. cloud inference
- Distributed system design with multiple microcontrollers
Machine Learning in Production:
- Feature engineering for time-series sensor data
- Model deployment on resource-constrained devices (Raspberry Pi)
- Training-serving contract to prevent silent bugs
Systems Engineering:
- Closed-loop control with hysteresis (preventing oscillation)
- Safety-first design (dry-run mode, duration clamping)
- End-to-end integration: sensors β inference β actuation β telemetry
Outcome: Achieved First Class grade (88/100) demonstrating practical IoT/ML integration.
MIT License.



