Water Flow Sensor

Z2M Part: EMS-017-A

Measure water flow rate with flow sensor.

Circuit Diagram
Circuit diagram for Water Flow Sensor
Wire Connections & Pin Configuration

Wire Color Connections:

Yellow → Digital Pin 3 to Water flow sensor pulse (code uses Pin 3)
Red → 5V to Water flow sensor VCC
Black → GND to Water flow sensor GND

Pin Configuration:

Arduino Digital Pin 2 → Water flow sensor pulse output
Arduino 5V → Water flow sensor VCC
Arduino GND → Water flow sensor GND
Arduino Code
Edit
int flowPin = 3;        // Sensor connected to digital pin 3
double flowRate;        // Calculated flow rate
volatile int count;     // Pulse count, must be volatile for interrupt accuracy

void setup() {
  pinMode(flowPin, INPUT);                     // Set pin as input
  attachInterrupt(digitalPinToInterrupt(3), Flow, RISING); // Attach interrupt on rising signal
  Serial.begin(9600);                          // Initialize Serial Monitor
  Serial.println(\"Water Flow Sensor Initialized...\");
}

void loop() {
  count = 0;              // Reset counter
  interrupts();           // Enable interrupts
  delay(1000);            // Count pulses for 1 second
  noInterrupts();         // Disable interrupts while calculating

  // Calculate flow rate
  flowRate = (count * 2.25);     // Each pulse = 2.25 mL/sec
  flowRate = flowRate * 60;      // Convert to mL/min
  flowRate = flowRate / 1000.0;  // Convert to L/min

  // Print flow rate
  Serial.print(\"Flow Rate: \");
  Serial.print(flowRate);
  Serial.println(\" L/min\");

  delay(500); // Wait half a second before next measurement
}

// Interrupt Service Routine (ISR) - increments count when pulse detected
void Flow() {
  count++;
}

Instruction Details

Wiring: Connect flow sensor VCC to 5V, GND to GND, pulse output to Digital Pin 3. Install in water line with correct flow direction.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Open Serial Monitor (Tools → Serial Monitor) at 9600 baud. Flow rate in L/min displays. Pass water through sensor to test.

How to Use

  1. Connect the required components as per the Pin Configuration above
  2. Open Arduino IDE and create a new sketch
  3. Copy and paste the code above
  4. Select your Arduino board and COM port from Tools menu
  5. Click the Upload button to upload the code to your Arduino
  6. Open Serial Monitor (if applicable) to see the output

Components Required

  • Arduino Uno
  • Water Flow Sensor (Hall Effect, e.g. YF-S201)
  • Breadboard
  • Jumper Wires

Category: Sensors