Shower timer for saving water
Build it step by step
0 of 6 doneWire the sensor and display
Flow sensor to 5V, GND and D2, display to D4 and D5, LED to D9 to D11.
Bench-test the flow sensor
Blow gently through it. The pulse count rises with a short Serial print.
Fit it inline
Use the correct threaded fittings and PTFE tape. Put the sensor between the tap and the shower hose, not inside the wet area.
Calibrate
Run the water into a 10 litre bucket and note the pulse count. Divide by 10 for pulses per litre.
Box and mount
Put the Nano and display in a sealed box fixed outside the splash zone.
Test a shower
Turn on the water. The display counts time and litres and turns red after five minutes.
How do you build a shower timer for saving water?
A waterproof box with a water flow sensor times your shower and shows litres used, flashing red after five minutes. You need Arduino Nano, Water flow sensor YF-S201, TM1637 4-digit display, RGB LED 5 mm common cathode, Resistor 220 Ω × 3, Battery holder 4 × AA with switch, AA alkaline battery × 4 and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- DisplaysBuy
- SemiconductorsBuy
- PassivesBuyResistor 220 Ω × 3
- PowerBuy
- BatteriesBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Flow sensor red | Nano 5V | Supply |
| Flow sensor black | Nano GND | Ground |
| Flow sensor yellow (signal) | Nano D2 | Pulse input on an interrupt |
| TM1637 CLK and DIO | Nano D4 and D5 | Display |
| TM1637 VCC and GND | Nano 5V and GND | Supply |
| RGB LED red, green, blue legs | Nano D9, D10, D11 through 220 Ω each | Status colour |
| RGB LED common cathode | Nano GND | Common cathode type |
| 4 AA pack | Nano VIN and GND | 6 V from batteries |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "TM1637" by Avishay Orpaz. The display alternates between minutes and seconds, and litres multiplied by ten. Calibrate PULSES_PER_LITRE by filling a 10 litre bucket and dividing the counted pulses by 10. Keep the electronics in a sealed box away from spray, and place only the flow sensor in the pipe.
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 <TM1637Display.h>
const byte FLOW = 2, R = 9, G = 10;
TM1637Display display(4, 5);
volatile unsigned long pulses = 0;
const float PULSES_PER_LITRE = 450.0; // YF-S201 typical, calibrate with a bucket
unsigned long startMs = 0, lastPulseMs = 0, lastCount = 0;
bool showering = false;
void onPulse() { pulses++; }
void setup() {
pinMode(FLOW, INPUT_PULLUP);
pinMode(R, OUTPUT); pinMode(G, OUTPUT);
display.setBrightness(5);
attachInterrupt(digitalPinToInterrupt(FLOW), onPulse, FALLING);
}
void loop() {
noInterrupts(); unsigned long p = pulses; interrupts();
if (p != lastCount) { // water is flowing
lastCount = p; lastPulseMs = millis();
if (!showering) { showering = true; startMs = millis(); noInterrupts(); pulses = 0; interrupts(); p = 0; lastCount = 0; }
}
if (showering && millis() - lastPulseMs > 60000UL) showering = false; // idle for a minute: ready for the next one
unsigned long secs = showering ? (lastPulseMs - startMs) / 1000 : 0;
float litres = p / PULSES_PER_LITRE;
if (millis() / 3000 % 2 == 0) display.showNumberDecEx((secs / 60) * 100 + secs % 60, 0b01000000, true); // mm:ss
else display.showNumberDec((int)(litres * 10)); // litres x 10
if (showering && secs > 300) { // over five minutes: flash red
bool on = (millis() / 400) % 2;
digitalWrite(R, on); digitalWrite(G, LOW);
} else {
digitalWrite(R, LOW); digitalWrite(G, showering);
}
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Water on | LED goes green and time counts |
| After 5 minutes | LED flashes red |
| 10 litres into a bucket | Display reads close to 10 litres |
| Water off for a minute | Ready for the next use |
If it does not work
Litres off by 10 to 20 percent
Calibrate with a bucket, because flow rate changes the count a little.
No pulses
Check the flow direction arrow on the sensor and the signal wire on D2.
Display not changing
CLK and DIO are swapped.
Leak at the fitting
Re-do the PTFE tape and tighten by hand plus a quarter turn.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the shower timer for saving water?
Arduino Nano, Water flow sensor YF-S201, TM1637 4-digit display, RGB LED 5 mm common cathode, Resistor 220 Ω × 3, Battery holder 4 × AA with switch, AA alkaline battery × 4 and Jumper wires male to male (40 pcs, 20 cm).
How long does the shower timer for saving water take to build?
About 90 minutes for a beginner maker, in 6 steps.
How do I know the shower timer for saving water works?
Water on: LED goes green and time counts. After 5 minutes: LED flashes red. 10 litres into a bucket: Display reads close to 10 litres.
Litres off by 10 to 20 percent: what should I check?
Calibrate with a bucket, because flow rate changes the count a little.
No pulses: what should I check?
Check the flow direction arrow on the sensor and the signal wire on D2.
Display not changing: what should I check?
CLK and DIO are swapped.
Leak at the fitting: what should I check?
Re-do the PTFE tape and tighten by hand plus a quarter turn.
