Community project
Smart Irrigation Gateway

The Smart Irrigation Gateway is a multi-protocol control hub built around an ESP32 that manages up to 16 irrigation zones through dual relay modules. It combines local scheduling with remote connectivity via GSM/GPRS and LoRa radio, allowing operators to monitor and control water distribution from anywhere. The gateway communicates with an STM8S controller to safely switch high-current irrigation loads while maintaining isolated low-voltage logic circuits.
This guide provides a complete wiring diagram, detailed parts list, and step-by-step assembly instructions for integrating the relay boards, GSM modem, LoRa transceiver, and logic-level shifters. You'll also get the Arduino firmware framework that handles serial communication with the STM8 controller, relay switching, radio messaging, and local scheduling logic—ready to customize for your irrigation zones and remote notification needs.
Wiring diagram
Interactive · read-only
Pan and zoom to explore the wiring. Remix the project to edit it in your own workspace.
Parts list
Bill of materials| Component | Qty | Notes |
|---|---|---|
| STM8S 8-Relay Controller Board8-channel, 3.3V-UART interface | 1 | The low-voltage controller board that reads eight local buttons, drives relay inputs and LEDs, and reports relay states to the gateway. |
| SunFounder TS0012 8-Channel Relay Module8-channel 5V relay module | 1 | Eight-channel 5V relay module with logic inputs IN1-IN8 for switching external loads through relay contacts. IN1-IN8 are MCU-facing control pins; relay contact/load terminals are external wiring. |
| SIM800L GSM/GPRS ModuleSIM800L with antenna and active SIM | 1 | Compact GSM/GPRS module based on SIMCom SIM800L chip. Features a built-in SIM card slot and antenna connector. Communicates via UART using AT commands. Operates at 3.4V–4.4V supply (must NOT be powered from 3.3V LDO; use a boost converter such as MT3608). Peak current draw up to 2A during GSM TX bursts — requires external dedicated power supply with bulk decoupling capacitor (100–470uF). UART logic is nominally 2.8V; when driven by ESP32 (3.3V), a resistor voltage divider on the ESP32 TX → SIM800L RX line is required to shift 3.3V down to ~2.8V. Built-in SIM card slot and antenna port are physical features of the module PCB. |
| Protected 5V 5A DC power supply5V, 5A minimum, fused enclosure | 1 | An enclosed protected low-voltage supply that powers the touchscreen board, STM8 controller, relay coils, and converters. |
| 4.0V 2A GSM buck regulator4.0V, 2A continuous minimum | 1 | A dedicated buck regulator that turns the 5 volt supply into a stable 4.0 volt supply for SIM800L transmit bursts. |
| SC16IS752 dual UART bridge breakoutI2C, channel A used for GSM | 1 | An I2C-connected serial bridge that gives the SIM800 modem its own UART channel without using the STM8 UART. |
| SX1262 LoRa transceiver moduleSelect 868 MHz / 915 MHz variant for local regulations | 1 | A low-power long-range radio module for communicating with remote irrigation sensor and valve nodes. |
| BSS138 Logic Level ShifterBSS138, channels 1 and 2 used | 1 | Common BSS138 MOSFET-based 4-channel bidirectional logic level converter module. Good for I2C, UART, and slow digital signals between 3.3V and 5V domains; not a strong high-speed SPI/LED data buffer. |
Assembly
6 stepsMount the low-voltage boards
Mount the JC2432W328C gateway board, STM8 relay controller, LoRa module, GSM module, UART bridge, regulator, and relay board in a non-conductive enclosure. Keep the radio antenna and GSM antenna clear of the display and relay wiring.
- Tip: Leave access to the JC2432W328C programming USB connector.
- Tip: Use short twisted low-voltage wires for the UART connections.
- ⚠ Do not connect mains wiring while any board is powered. Relay contact terminals can carry dangerous voltage.
Make the shared low-voltage power wiring
Connect the protected supply 5V OUT to the STM8 5V pin, relay board VCC, and GSM regulator VIN. Connect the protected supply GND OUT to every board GND pin, including the display board ground, STM8, relay board, LoRa radio, UART bridge, GSM regulator, and GSM module (power and shared ground). Connect the GSM regulator VOUT to the SIM800L VCC pin (4.0 V modem power).
- Tip: Use wiring rated for the relay board and GSM modem current.
- Tip: Place a 100–470 µF low-ESR capacitor close to SIM800L VCC and GND to handle transmit bursts.
- ⚠ Do not connect 5 V to the LoRa module or UART bridge 3.3 V pins — that can permanently damage them.
- ⚠ Do not power the SIM800L directly from the display board; its short current bursts can reset the gateway.
Wire the STM8 command link
Connect JC2432W328C GPIO16 to STM8 RX (command data), STM8 TX to JC2432W328C GPIO17 (state data), and keep their grounds connected. The STM8 board controls all eight relay inputs and its own local buttons and LEDs; do not wire relay inputs to ESP32 GPIO pins.
- Tip: Cross the two serial data wires: transmitter goes to receiver.
- Tip: Use a 3.3 V-compatible STM8 UART interface; add a level shifter if your STM8 board drives TX at 5 V.
- ⚠ A 5 V STM8 TX signal connected directly to the ESP32 RX pin can damage the ESP32; confirm the STM8 board UART voltage first.
Wire the LoRa radio
Connect LoRa VCC to 3V3, GND to GND, SCK to GPIO18, MISO to GPIO19, MOSI to GPIO23, NSS to GPIO26, NRST to GPIO25, and BUSY to GPIO32 (radio power, ground, data, select, reset, and ready signals). Leave DIO1 unconnected for the supplied polling starter firmware.
- Tip: Fit the correct approved antenna before transmitting.
- Tip: Keep SPI wires short and away from relay contact wiring.
- ⚠ Use only the radio frequency variant allowed in your country.
- ⚠ Do not transmit without a suitable antenna connected; that can damage the radio transmitter.
Wire the GSM bridge and modem
Connect UART bridge VCC to 3V3, GND to GND, SDA to GPIO21, and SCL to GPIO22 (bridge power, ground, and control data). Connect bridge TXA to SIM800L RX through a 3.3 V-to-2.8 V level shifter or divider, and SIM800L TX to bridge RXA (modem data).
- Tip: Insert an activated SIM and attach the GSM antenna before testing the modem.
- Tip: Keep modem power wires short and thick enough for its current bursts.
- ⚠ Do not feed the SIM800L RX pin directly from a 3.3 V transmitter unless your exact SIM800L carrier documentation permits it; use the level reduction described above.
Connect irrigation loads safely
Have a qualified person connect each irrigation valve or pump control circuit to the appropriate relay COM and NO/NC terminals, with a suitable fuse, enclosure, isolation, and load-rated cable. Label channels R1 through R8 to match the zones in the touchscreen.
- Tip: Test each relay with a low-voltage lamp or meter before connecting irrigation equipment.
- Tip: Keep mains/load wires physically separated from all low-voltage signal wiring.
- ⚠ Relay contact wiring may be mains voltage and can cause fatal shock or fire. Only a qualified person should install it.
Pin assignments
Board wiring reference| Pin | Connection | Type |
|---|---|---|
| 5V | power_supply 5V OUT | power |
| GND | power_supply GND OUT | ground |
| EXT | power_supply AC INPUT → Qualified-person-installed fused mains input | power |
| 5V | stm8_relay_controller 5V | power |
| GND | stm8_relay_controller GND | ground |
| EXT | stm8_relay_controller RELAY1_OUT → SunFounder TS0012 8-Channel Relay Module IN1 | digital |
| EXT | stm8_relay_controller RELAY2_OUT → SunFounder TS0012 8-Channel Relay Module IN2 | digital |
| EXT | stm8_relay_controller RELAY3_OUT → SunFounder TS0012 8-Channel Relay Module IN3 | digital |
| EXT | stm8_relay_controller RELAY4_OUT → SunFounder TS0012 8-Channel Relay Module IN4 | digital |
| EXT | stm8_relay_controller RELAY5_OUT → SunFounder TS0012 8-Channel Relay Module IN5 | digital |
| EXT | stm8_relay_controller RELAY6_OUT → SunFounder TS0012 8-Channel Relay Module IN6 | digital |
| EXT | stm8_relay_controller RELAY7_OUT → SunFounder TS0012 8-Channel Relay Module IN7 | digital |
| EXT | stm8_relay_controller RELAY8_OUT → SunFounder TS0012 8-Channel Relay Module IN8 | digital |
| 5V | relay_bank VCC | power |
| GND | relay_bank GND | ground |
| 5V | gsm_regulator VIN | power |
| GND | gsm_regulator GND | ground |
| EXT | gsm_regulator VOUT → SIM800L GSM/GPRS Module VCC | power |
| GND | gsm GND | ground |
| 3V3 | uart_bridge VCC | power |
| GND | uart_bridge GND | ground |
| GPIO 21 | uart_bridge SDA | i2c |
| GPIO 22 | uart_bridge SCL | i2c |
| EXT | gsm TX → SC16IS752 dual UART bridge breakout RXA | uart |
| EXT | gsm RX → SC16IS752 dual UART bridge breakout TXA | uart |
| 3V3 | lora VCC | power |
| GND | lora GND | ground |
| GPIO 18 | lora SCK | spi |
| GPIO 19 | lora MISO | spi |
| GPIO 23 | lora MOSI | spi |
| GPIO 25 | lora NRST | digital |
| GPIO 32 | lora BUSY | digital |
| GPIO 26 | lora NSS | digital |
| 3V3 | stm8_level_shifter LV | power |
| 5V | stm8_level_shifter HV | power |
| GND | stm8_level_shifter GND | ground |
| GPIO 17 | stm8_level_shifter LV1 | digital |
| GPIO 16 | stm8_level_shifter LV2 | digital |
| EXT | stm8_relay_controller RX → BSS138 Logic Level Shifter HV1-HV4 | uart |
| EXT | stm8_relay_controller TX → BSS138 Logic Level Shifter HV1-HV4 | uart |
Firmware
ESP32#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <lvgl.h>
#include "config/pins.h"
#include "services/stm8_link.h"
#include "services/relay_service.h"
#include "services/radio_service.h"
#include "services/gsm_service.h"
#include "storage/config_store.h"
#include "ui/gateway_ui.h"
#define STM8_RX 17
#define STM8_TX 16
#define I2C_SDA 21
#define I2C_SCL 22
// JC2432W328C display and capacitive-touch initialization is board-revision-specific.
// Keep it in the display adapter when the verified vendor pin map is available.
// lv_init() is safe here; GatewayUi owns only widgets, never the hardware driver.
// Forward declarations
static bool localClock(uint8_t& weekday, uint16_t& minuteOfDay);
HardwareSerial stm8Serial(2);
Stm8Link stm8;
RelayService relays;
RadioService lora;
GsmService gsm;
ConfigStore store;
GatewayUi ui;
GatewayStatus gateway{};
uint32_t lastSchedulerMinute = UINT32_MAX;
uint32_t lastUiRefresh = 0;
static bool localClock(uint8_t& weekday, uint16_t& minuteOfDay) {
// Replace with SNTP or RTC adapter. The scheduler remains inhibited until time is trusted.
time_t now = time(nullptr);
if (now < 1700000000) return false;
tm local{};
localtime_r(&now, &local);
weekday = local.tm_wday;
minuteOfDay = local.tm_hour * 60 + local.tm_min;
return true;
}
void setup() {
Serial.begin(115200);
Wire.begin(Pins::I2C_SDA, Pins::I2C_SCL);
stm8Serial.begin(115200, SERIAL_8N1, Pins::STM8_RX, Pins::STM8_TX);
stm8.begin(stm8Serial);
store.begin();
relays.begin(stm8);
lora.begin();
gsm.begin();
lv_init();
// TODO (board verified): initialize ST7789 flush callback and capacitive-touch read callback.
ui.begin();
WiFi.mode(WIFI_STA); // credentials are intentionally stored/configured outside source code
}
void loop() {
stm8.tick();
lora.tick();
gsm.tick();
const uint32_t now = millis();
uint8_t weekday = 0;
uint16_t minute = 0;
const bool clockValid = localClock(weekday, minute);
if (clockValid && minute != lastSchedulerMinute) {
lastSchedulerMinute = minute;
relays.tick(weekday, minute, true);
} else if (!clockValid) {
relays.tick(0, 0, false); // applies STM8 button reports and fail-safe timeouts only
}
gateway.stm8Online = stm8.online();
gateway.loraOnline = lora.online();
gateway.gsmOnline = gsm.online();
gateway.wifiOnline = WiFi.status() == WL_CONNECTED;
gateway.rssi = gateway.wifiOnline ? WiFi.RSSI() : 0;
if (now - lastUiRefresh >= 250) {
lastUiRefresh = now;
RelayModel view[8];
for (uint8_t i = 0; i < 8; ++i) view[i] = relays.at(i);
ui.update(view, gateway);
}
ui.tick();
delay(2); // yields to Wi-Fi/LVGL without blocking communication state machines
}“Deploy to device” opens this project in Schematik, where you can flash it to your board over USB.
Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace — diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.