Skip to Content

← All functionalities

Hydraulic moving floor (BLE app)ESP32 PLC 38RGPIOAcquisition

Measuring hydraulic flow with a pulse sensor on an industrial ESP32 PLC

A turbine flow meter with a magnetic or inductive pickup is the cheapest way to know how much oil is actually moving through a hydraulic circuit. This ESP32 PLC flow meter example, taken from a real mobile hydraulic machine deployment, times each pulse with an interrupt, converts the period to liters per minute using the meter's K-factor, and accumulates total volume — all on an ESP32 PLC 38R, with no extra signal converter in between.

Interrupt timing beats pulse counting

Counting pulses over a fixed window gives a slow, quantized reading at low flow. Instead, the ISR stores micros() on every rising edge and the loop computes flow from the period between the last two pulses. The result reacts in one pulse instead of one second, which matters when an operator is watching a gauge on a phone while a valve opens.

Presence detection catches a missing meter

Zero flow and a disconnected flow meter look identical if you only count pulses, and on a machine that vibrates down the road every day, connectors do come loose. The example reads a separate presence signal and applies a no-pulse timeout, so the firmware can distinguish "machine idle" from "sensor unplugged" and report each case differently — the same validity-flag pattern used for the 4-20 mA transmitters elsewhere in this series.

From pulses to liters, persistently

Dividing the accumulated pulse count by the K-factor yields total volume, which in the real machine feeds an oil-consumption counter stored in NVS flash so it survives reboots and power cuts. Telemetry leaves the PLC once per second as a compact [F]12.3 frame over the BLE UART service, which means any generic Bluetooth terminal app can verify the reading during commissioning, long before the production mobile app is installed.

A snippet from the implementation

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

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

  pinMode(PIN_PULSES, INPUT);
  pinMode(PIN_PRESENCE, INPUT);

  attachInterrupt(digitalPinToInterrupt(PIN_PULSES), pulseIsr, RISING);

  Serial.println("Pulse flow meter ready (ESP32 PLC 38R)");
}

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

Frequently asked questions

How do I find the K-factor of my flow meter?

It is printed on the datasheet as pulses per liter. If unknown, run a known volume through the meter, read the accumulated pulse count and divide. Calibrating against a real fill is always worth doing once.

Why is my reading noisy at very low flow?

At low flow the period between pulses is long, so each new pulse causes a step change. Average the last few periods, or fall back to counting pulses over a longer window below a threshold.

Can I use a hall-effect flow sensor instead of an inductive one?

Yes. Any sensor that outputs clean digital pulses works with the same code; only the K-factor and the input wiring change. Check the sensor output voltage matches the PLC digital input range.

Related functionalities