Fuzzy greenhouse climate control
A fuzzy-PI controller with a digital twin, model predictive control and AI fault detection for greenhouses, vertical farms and cold stores.
- Origin
- Started as a MATLAB fuzzy controller
- Built with
- Python
- Fuzzy logic
- MPC
- ROS 2 Humble
- Modbus TCP
- MQTT
- IEC 61131-3
- scikit-learn
The first version was a MATLAB Mamdani controller that turned a sensed and a target temperature into two PWM signals, one for a heater and one for a cooler. Fuzzy logic suits this job because it works with terms such as “cold”, “warm” and “hot” the way an operator would, and moves smoothly between them.
Version 2 keeps fuzzy logic at the core and builds an industrial system around it.
What version 2 adds
- A redesigned controller. An incremental fuzzy-PI with a 7 × 7 rule base that works on the error, so one rule base serves every crop and setpoint.
- Split-range actuation. Heating, free cooling through vents, then pad or compressor cooling, with no heating and cooling at the same time.
- A safety supervisor. Redundant sensor validation, frost and heat limits, interlocks and a fail-safe mode.
- A digital twin. A grey-box thermal model with solar gain, crop transpiration and realistic sensors with injectable faults.
- Model predictive control that uses weather forecasts, with fuzzy-PI as fallback.
- Anomaly detection that finds drifting, frozen or spiking sensors and removes them from the fusion.
- Field integration. A ROS 2 package, a Modbus TCP link to a PLC, MQTT telemetry, and export of the controller as IEC 61131-3 Structured Text or a C99 header.
Results on the digital twin

| Scenario | Controller | RMSE | Time in band | Heat + cool overlap |
|---|---|---|---|---|
| Tomato greenhouse, 72 h | Legacy FIS | 5.27 K | 19.4 % | 72 h |
| Fuzzy-PI | 0.29 K | 98.3 % | 0 h | |
| MPC | 0.34 K | 98.5 % | 0 h | |
| Sensor and boiler faults | Fuzzy-PI, rules only | 1.71 K | 65.2 % | 0 h |
| Fuzzy-PI with AI monitor | 0.35 K | 97.6 % | 0 h |
Fuzzy-PI moves the actuators about 2.5 times less than a tuned PID for nearly the same tracking, which means less wear on valves, burners and compressors. These numbers come from the digital twin, not from a real site.