Garden hose water usage meter
Build it step by step
0 of 8 doneInstall the library
Search for LiquidCrystal I2C in the Library Manager.
Wire the sensor
Red to 5V, black to GND, yellow to D2.
Wire the LCD and button
SDA and SCL to A4 and A5, button D3 to GND.
Upload the sketch
Display shows This: 0.00 L.
Blow gently through the sensor
The pulse count rises a little.
Fill a 10 litre bucket through the sensor
Note the litres shown.
Adjust PULSES_PER_LITRE
Scale it by the true litres over the shown litres.
Fit it on the hose
Use hose adapters and check for leaks.
How do you build a garden hose water usage meter?
A flow sensor on a hose counts litres used each watering and shows the running total on an LCD. You need Arduino Nano, Water flow sensor YF-S201, 16x2 LCD with I2C backpack (PCF8574), Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 6
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Flow sensor red and black | Nano 5V and GND | Power for the sensor |
| Flow sensor yellow | Nano D2 | Pulse output, interrupt pin |
| LCD I2C SDA and SCL | Nano A4 and A5 | Display, address 0x27 |
| LCD I2C VCC and GND | Nano 5V and GND | Display power |
| Reset button | Nano D3 to GND | Short press clears this watering, hold clears the total |
Code
The YF-S201 has a small turbine with a magnet inside, and a Hall sensor makes one pulse for each turn. About 450 pulses mean one litre, or 7.5 pulses per second for each litre per minute of flow, but each sensor differs by several percent. Calibrate yours by filling a 10 litre bucket and adjusting PULSES_PER_LITRE until the display agrees. The pulse is counted by an interrupt so none are missed, and once a second the sketch turns the new pulses into litres and a flow rate in litres per minute. A short press clears the volume for this watering and a two-second hold clears the running total. The sensor is plastic with threaded ends, usually G1/2, so you need hose adapters, and it must not be used on mains-pressure lines over its rating, which is about 1.75 MPa for the body but best kept under 0.8 MPa in practice. Mount it with the arrow pointing in the flow direction and keep the electronics out of the wet. The total is not saved when power is lost.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // try 0x3F if the screen stays blank
const uint8_t PIN_FLOW = 2, BTN = 3;
const float PULSES_PER_LITRE = 450.0; // typical for YF-S201, calibrate with a bucket
volatile unsigned long pulses = 0;
unsigned long lastPulses = 0;
unsigned long lastCalc = 0;
float thisLitres = 0, totalLitres = 0, flowLpm = 0;
unsigned long btnDownAt = 0;
void onPulse() { pulses++; }
void draw() {
lcd.setCursor(0, 0);
lcd.print("This: ");
lcd.print(thisLitres, 2);
lcd.print(" L ");
lcd.setCursor(0, 1);
lcd.print("Tot ");
lcd.print(totalLitres, 1);
lcd.print(" ");
lcd.print(flowLpm, 1);
lcd.print("L/m ");
}
void setup() {
pinMode(PIN_FLOW, INPUT_PULLUP);
pinMode(BTN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN_FLOW), onPulse, RISING);
lcd.init(); lcd.backlight();
draw();
}
void loop() {
if (millis() - lastCalc >= 1000) {
unsigned long now = millis();
noInterrupts(); unsigned long p = pulses; interrupts();
unsigned long delta = p - lastPulses;
lastPulses = p;
float litres = delta / PULSES_PER_LITRE;
thisLitres += litres;
totalLitres += litres;
flowLpm = litres * 60.0 * 1000.0 / (now - lastCalc); // litres per minute
lastCalc = now;
draw();
}
if (digitalRead(BTN) == LOW) {
if (btnDownAt == 0) btnDownAt = millis();
if (millis() - btnDownAt > 2000) { totalLitres = 0; thisLitres = 0; btnDownAt = millis() + 100000UL; }
} else {
if (btnDownAt != 0 && millis() - btnDownAt < 2000) thisLitres = 0; // short press
btnDownAt = 0;
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| No flow | 0.00 L and 0.0 L/m |
| 10 litres into a bucket | About 10 L after calibration |
| Short press | This watering returns to zero |
| Two-second press | Total returns to zero |
| Higher flow | Larger L/m reading |
If it does not work
Nothing counts
Check the yellow wire is on D2 and the arrow matches the flow.
Reading is wrong by a fixed percent
Calibrate with a bucket.
LCD blank
Try address 0x3F, or turn the contrast screw.
Count jumps when the pump starts
Move the sensor wire away from the pump motor.
Leaks at the sensor
Use thread tape on the adapters and do not overtighten the plastic.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the garden hose water usage meter?
Arduino Nano, Water flow sensor YF-S201, 16x2 LCD with I2C backpack (PCF8574), Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the garden hose water usage meter take to build?
About 90 minutes for a beginner maker, in 8 steps.
How do I know the garden hose water usage meter works?
No flow: 0.00 L and 0.0 L/m. 10 litres into a bucket: About 10 L after calibration. Short press: This watering returns to zero.
Nothing counts: what should I check?
Check the yellow wire is on D2 and the arrow matches the flow.
Reading is wrong by a fixed percent: what should I check?
Calibrate with a bucket.
LCD blank: what should I check?
Try address 0x3F, or turn the contrast screw.
Count jumps when the pump starts: what should I check?
Move the sensor wire away from the pump motor.
