GreenHouse P4
Climate, irrigation and grow-light controller for a greenhouse. Up to 8 independent zones, 16 relay channels and 16 sensor profiles are configured from a 1024×600 touch display; automation works locally without cloud or permanent internet.
Local greenhouse controller
The device runs climate and irrigation in each zone against target setpoints with hysteresis, driving loads through two RS-485 relay modules (Modbus RTU). All logic runs on-device: settings are stored in NVS, and on each boot the controller writes a safe state to every relay. The loop starts about once a second; individual sensor polls can take longer.
Control loop · nominally 1 Hz
Poll inputs → pulse sensors → DS18B20 → PZEM → SDI-12 → I²C, then apply automation. Enabled actuator channels are assigned a role and zone.
Safety first
Low tank, leak and dry run block the pump and valves; rain, wind and limit switches block the corresponding vent direction. Manual control cannot override these interlocks.
Board and compute
Compute
ESP32-P4 (rev 1.3) — main processor and UI. ESP32-C6 as an ESP-Hosted slave (SDIO) provides Wi-Fi 6. Board JC1060P470C.
Display
1024×600, MIPI-DSI, JD9165 controller, capacitive GT911 touch. LVGL v9 interface — 10 screens with a bottom navigation bar.
Supported I/O interfaces
Sensors and actuators connect to the controller through dedicated interfaces. Below is the peripheral map per bus with ESP32-P4 pins.
I²C SDA 7 · SCL 8
- SHT45 — air temp & humidity
- SCD41 — CO₂
- BH1750 — illuminance, lux
RS-485 / Modbus RTU UART3 · 26/27 · 9600
- Relay module 1 — address 1, channels 1–8
- Relay module 2 — address 2, channels 9–16
- 16 discrete inputs — from the same modules
SDI-12 UART2 · GPIO 1 · 1200
- Apogee SQ-500 — PAR
- TEROS 12 — soil moisture and temperature
- PHYTOS 31 — leaf wetness
1-Wire GPIO 20
- DS18B20 — digital thermometers
Modbus UART1 · 45/47 · 9600
- PZEM-004T — power and accumulated energy
Pulse inputs GPIO 46 / 2 / 3
- Flow meter — GPIO 46
- Anemometer Davis 6410 — GPIO 2
- Rain gauge Davis 7852 — GPIO 3
ADC / ADS1115 analog
- VH400 — soil moisture
4–20 mA current loop analog
- WIKA A10 — water pressure
ESP32-P4 pins
| GPIO | Function | Interface | Parameters |
|---|---|---|---|
| 7 | I²C SDA | I²C | sensors SHT45 / SCD41 / BH1750 |
| 8 | I²C SCL | I²C | bus clock |
| 26 | RS-485 TX | UART3 | 9600 · isolated connector |
| 27 | RS-485 RX | UART3 | Modbus RTU · relay modules |
| 1 | SDI-12 | UART2 | 1200 baud |
| 20 | 1-Wire | 1-Wire | DS18B20; a 4.7 kΩ external pull-up is required for cable runs |
| 45 | PZEM TX | UART1 | 9600 · Modbus |
| 47 | PZEM RX | UART1 | energy metering |
| 46 | Water flow | Pulse | flow-meter counter |
| 2 | Wind | Pulse | anemometer |
| 3 | Rain | Pulse | rain gauge |
16 relay channels
Two RS-485 relay modules (addresses 1 and 2, 8 channels each). Below is the default assignment; the role, zone, safe state and max on-time of each channel are configured on-screen. Channels 11–16 are free for expansion.
| Channel | Role | Type | Zone | Module | Max on-time |
|---|---|---|---|---|---|
| 01 | Pump | Irrigation | Zone 1 | 1 · addr 1 | 10 min |
| 02 | Valve | Irrigation | Zone 1 | 1 · addr 1 | 10 min |
| 03 | Exhaust fan | Climate | Zone 1 | 1 · addr 1 | — |
| 04 | Intake fan | Climate | Zone 1 | 1 · addr 1 | — |
| 05 | Heater | Climate | Zone 1 | 1 · addr 1 | — |
| 06 | Humidifier | Climate | Zone 1 | 1 · addr 1 | — |
| 07 | Light | Grow light | Zone 1 | 1 · addr 1 | — |
| 08 | Vent open | Venting | Zone 1 | 1 · addr 1 | 1 min |
| 09 | Vent close | Venting | Zone 1 | 2 · addr 2 | 1 min |
| 10 | Emergency cutoff | Safety | Zone 1 | 2 · addr 2 | — |
| 11–16 | Not set | — | — | 2 · addr 2 | — |
16 sensor profiles
Each profile sets the sensor type, bus, zone, address/channel and scale. All profiles are disabled by default and enabled as hardware is connected.
| # | Sensor | Measures | Default bus |
|---|---|---|---|
| 1 | SHT45 | Air temperature + humidity | I²C |
| 2 | SCD41 | CO₂ | I²C |
| 3 | Apogee SQ-500 | PAR | SDI-12 |
| 4 | BH1750 | Illuminance, lux | I²C |
| 5 | TEROS 12 | Soil moisture and temperature | SDI-12 |
| 6 | VH400 | Soil moisture | ADC |
| 7 | DS18B20 | Temperature | 1-Wire |
| 8 | Float switch | Tank water level | Discrete |
| 9 | Flow meter | Water flow | Pulse |
| 10 | Leak sensor | Leak | Discrete |
| 11 | Reed switch | Door / vent | Discrete |
| 12 | PHYTOS 31 | Leaf wetness | SDI-12 |
| 13 | WIKA A10 | Water pressure | 4–20 mA |
| 14 | PZEM-004T | Power and accumulated energy | Modbus |
| 15 | Davis 6410 | Wind speed | Pulse |
| 16 | Davis 7852 | Rainfall | Pulse |
Automation logic by role
Climate, irrigation and light roles compare their zone measurement against setpoints; the pump follows open valves, while vent actuators are operated manually with protective interlocks. Rules start about once a second.
T° < target − hysteresis, off at T° ≥ target + hysteresis.T° > target + hysteresis, off at T° ≤ target − hysteresis.humidity < target − hysteresis, off at humidity ≥ target + hysteresis.soil moisture < target threshold.hour ∈ [start, end) when illuminance < threshold; without time it remains off.Safety overrides everything
Fault conditions block their associated loads regardless of automation and manual mode. On boot the controller force-writes the configured safe state to all 16 channels, never trusting the cache.
Pump and valves
Switch off on low tank level, detected leak or a flow fault (dry run).
Vent opening
Blocked on rain or strong wind — limit switches and weather inputs prevent opening.
Dry-run protection
If the pump runs longer than 20 s with no flow detected, irrigation shuts off until the fault is cleared.
Ten screens on the touch display
Navigation is the bottom tab bar. Tap the tabs at the bottom of the display to switch screens — the mockup reproduces the firmware's real colours and layout.