Skip to Content

← All functionalities

Water pumping (sanitation)ESP32 PLC 14GPIOControl

Water pump control with an ESP32 PLC and float switches

Pumping stations are one of the most common PLC applications: fill or empty a tank between two levels, detect pump faults, and never burn a motor running dry. This tutorial implements a complete, field-proven pump controller on an ESP32 PLC 14 using three float switches, contactor feedback and a clean state machine — the exact pattern we use in real wastewater pumping stations.

Why a state machine instead of if/else spaghetti

Pump logic looks trivial until you add fault handling. Modelling it as three explicit states (OFF, ON, ERROR) keeps every transition auditable: the pump only starts when both minimum and maximum floats are active, only stops when the minimum float drops, and any thermal trip or missing contactor confirmation latches a manual-reset error. The same structure scales to dual-pump stations with alternation.

Fault detection with contactor feedback

The example monitors two digital inputs while the pump runs: the contactor auxiliary contact (did the pump really start?) and the thermal relay (is the motor overloaded?). A 2-second grace period avoids false alarms during contactor pull-in. On any fault the controller de-energises the pump, lights the alarm pilot and waits for a manual reset — the safe default for unattended stations.

Ready for telemetry

All signals are collected in a dades[] array, ready to be packed and sent by LoRaWAN, MQTT or Modbus. See the dual-pump LoRaWAN tutorial below for the full remote-monitoring version.

A snippet from the implementation

Straight from the example as deployed on the ESP32 PLC 14 — copy it freely:

void setup() {
  Serial.begin(115200);

  pinMode(I_FLOAT_MIN, INPUT);
  pinMode(I_FLOAT_MAX, INPUT);
  pinMode(I_FLOAT_OVERFLOW, INPUT);
  pinMode(I_CONFIRMATION, INPUT);
  pinMode(I_THERMAL, INPUT);
  pinMode(I_RESET, INPUT);
  pinMode(Q_PUMP, OUTPUT);
  pinMode(Q_PILOT, OUTPUT);

  digitalWrite(Q_PUMP, LOW);
  digitalWrite(Q_PILOT, LOW);
}

The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.

Frequently asked questions

Can I use this with only two float switches?

Yes — remove the overflow input and keep minimum and maximum. The state machine logic does not change.

How do I add remote monitoring?

Pack the dades[] array into a few bytes and send it with the protocol that fits your site: LoRaWAN for remote stations without network, MQTT if you have WiFi or Ethernet coverage.

Does this work on other Industrial Shields PLCs?

The sketch uses standard digitalRead/digitalWrite on I0_x/Q0_x pins, so it runs on any ESP32 PLC or M-Duino — only the pin map changes.

Related functionalities