Arduino Nano Flow Sensor: Industrial Water Meter
Perfect flow sensor wiring confirmed! D2=Signal, 5V VCC, GND. Professional 1-30L/min measurement, ±3% accuracy, 2.25mL/pulse calibration, real-time L/min + total liters, leak detection, auto valve control (D8), 1Hz-100Hz flow range.
Blow through sensor → Serial shows L/min + total volume accumulating! Food-grade plastic rotor.
How It Works
A flow sensor such as the YF-S201 contains a small pinwheel turbine in the water path with a magnet embedded in one blade, and a Hall-effect sensor in the dry housing beside it. Each rotation sweeps the magnet past the sensor, producing one pulse — so pulse frequency is proportional to flow rate.
The conversion is a single calibration constant. For the YF-S201 it is approximately 7.5 pulses per second per litre per minute, so flow in L/min equals frequency divided by 7.5. Different models have different constants, and the figure varies somewhat with flow rate and fluid viscosity.
Because the output is a pulse train, the measurement is really a frequency counting problem. Counting edges in an interrupt and sampling that count once per second is both simple and accurate, and it is why this sensor must be on an interrupt-capable pin — on the Arduino Nano that means D2 and D3 only.
Accumulating total volume is just integration: add flow rate multiplied by elapsed time on each update. That turns the sensor into a water meter.
Components Needed
- Arduino Nano
- Hall Effect Flow Sensor (1/2" BSP)
- 5V Solenoid Valve (D8)
- LCD 16x2 (optional)
- Jumper wires
Wiring to the Arduino Nano
Connect the signal wire to an interrupt-capable pin, VCC to 5 V and GND to ground. The output is open-collector on most units, so enable the internal pull-up or fit a 10 kΩ resistor to the supply rail.
The 5 V signal matches this board's logic directly.
Install the sensor with the arrow pointing in the direction of flow, and with straight pipe runs either side. Turbulence from an elbow immediately upstream disturbs the turbine and skews readings.
| Sensor wire | Arduino Nano pin | Function |
|---|---|---|
| Yellow (signal) | D2 | Pulse output — must be interrupt capable |
| Red (VCC) | 5V | Supply (5–18 V) |
| Black (GND) | GND | Common ground |
Build and Upload
Blow/suck → L/min updates + total liters accumulate! D8 valve auto-closes on leaks.
Example Code
Flow rate and cumulative volume from pulse counting. Upload it with the board set to Arduino Nano and open the Serial Monitor at 9600 baud.
const int FLOW_PIN = 2;
const float PULSES_PER_LPM = 7.5; // YF-S201; check your model
volatile unsigned long pulseCount = 0;
unsigned long lastSample = 0;
float totalLitres = 0;
void onPulse() { pulseCount++; }
void setup() {
Serial.begin(9600);
pinMode(FLOW_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(FLOW_PIN), onPulse, FALLING);
lastSample = millis();
}
void loop() {
if (millis() - lastSample < 1000) return;
noInterrupts();
unsigned long count = pulseCount;
pulseCount = 0;
interrupts();
float elapsed = (millis() - lastSample) / 1000.0;
lastSample = millis();
float hz = count / elapsed;
float lpm = hz / PULSES_PER_LPM;
totalLitres += lpm * elapsed / 60.0; // integrate to get volume
Serial.print("flow: "); Serial.print(lpm, 2);
Serial.print(" L/min total: "); Serial.print(totalLitres, 3);
Serial.println(" L");
}
Applications
A water flow sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:
- Water usage metering for homes and gardens
- Dosing and batching — dispensing a measured volume
- Leak detection by flagging flow when none is expected
- Irrigation control with volume-based rather than time-based watering
- Coolant and fuel flow monitoring on machinery
Working with the Arduino Nano
The Arduino Nano is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.
The Nano shares the Uno’s ATmega328P but adds A6 and A7, which are analog-input only and cannot be used as digital pins.
Its DIP footprint drops straight into a breadboard, which suits permanent sensor builds.
Older clones use the CH340 USB bridge and may need that driver plus the "ATmega328P (Old Bootloader)" processor option.
| Arduino Nano characteristic | Value | Why it matters here |
|---|---|---|
| Logic voltage | 5 V | Matches most hobby modules directly |
| ADC resolution | 10-bit (0–1023) | Sets how finely an analog reading can be resolved |
| Analog inputs | A0–A7 (eight channels, two more than the Uno) | Determines how many analog sensors can share the board |
| PWM outputs | D3, D5, D6, D9, D10 and D11 | Needed for brightness, speed and tone control |
| I²C pins | A4 (SDA) and A5 (SCL) | Fixed by hardware — wiring copied from another board may not match |
| Interrupt pins | D2 and D3 only | Required for counting fast or asynchronous events |
| Serial | a single hardware UART shared with USB | Monitor runs at 9600 baud by default |
Troubleshooting
Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:
- No pulses at all — the pull-up is missing, or the pin is not interrupt capable.
- Flow reads low at small rates — these turbines have a minimum useful flow, typically around 1 L/min, below which the rotor stalls.
- Readings are unstable — turbulence from fittings too close to the sensor. Add straight pipe before and after.
- The calibration constant does not match — it varies between models and somewhat with flow rate. Calibrate by measuring a known volume.
- Counts continue after flow stops — the rotor is coasting, or electrical noise is triggering the interrupt. Add a small capacitor on the signal line.
- Code written for an ESP board gives odd analog values — the Arduino Nano uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
- An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Nano I²C is on A4 (SDA) and A5 (SCL).
Taking It Further on the Arduino Nano
Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Nano specifically:
The Nano’s DIP footprint makes it the natural choice once a breadboard prototype becomes a soldered build. Mount it on female headers rather than soldering it down, so the board can be recovered if the project is retired.
With A6 and A7 available in addition to A0–A5, the Nano can read two more analog sensors than an Uno. Remember that those two pins are analog-input only — they cannot be used with digitalWrite or as digital inputs.
For battery-powered builds, the Nano’s regulator and USB bridge dominate idle current. Powering the 5V pin directly from a regulated supply and removing the power LED substantially extends runtime.
Notes and Practical Limits
Calibrate by collecting a measured volume — a 5 litre container is ideal — and comparing against the sensor's total. Adjusting the constant from that single measurement typically improves accuracy from ±10% to ±3%.
These sensors are not food-safe or potable-rated unless explicitly stated. For drinking water, use a sensor certified for the purpose.