Measuring hydraulic flow with a pulse sensor on an industrial ESP32 PLC
Interrupt timing beats pulse counting
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
From pulses to liters, persistently
[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.