Introduction
This experiment demonstrates how to use a water flow sensor to measure the flow of water in a pipe or container. This sensor can be used in applications such as irrigation systems or water usage monitoring.

Components Needed
- Water Flow Sensor
- Arduino (e.g., Uno, Nano)
- Jumper wires
Circuit Setup
- Connect the VCC pin of the water flow sensor to the 5V pin on the Arduino.
- Connect the GND pin to the GND pin on the Arduino.
- Connect the signal output pin to a digital input pin (e.g., D2) on the Arduino.
Ensure the sensor is properly connected for accurate flow measurements.

Code for Water Flow Sensor
Upload the following code to your Arduino to measure water flow:
const int flowPin = 2; // Pin connected to the flow sensor
volatile int flowCount = 0;
void setup() {
Serial.begin(9600);
pinMode(flowPin, INPUT);
attachInterrupt(digitalPinToInterrupt(flowPin), countFlow, FALLING);
}
void loop() {
delay(1000);
Serial.print("Flow Count: ");
Serial.println(flowCount);
flowCount = 0;
}
void countFlow() {
flowCount++;
}
Explanation
The code uses an interrupt to detect each pulse from the water flow sensor, and it counts how many pulses occur within a second. The flow count is printed to the serial monitor.
Troubleshooting
- If the flow count is not increasing, check the wiring and ensure that the sensor is positioned correctly in the water flow path.
- If there is no data, check the sensor's power supply and verify that the sensor is compatible with the voltage level.