A few years ago I made a flow sensor to warn if the water pump was working. The problem I had was I often forgot to turn the pump on and sometime even if I had it may not but working very well or not at all. The lasers have flow switch that stop the laser from working but there is no indication.
In the past I have managed to kill a few tubes due to failed or poor cooling pumps so I wanted to find a way to warn us if there is an issue with the water. Looking around the web for inspiration I found various articles on using a flow meter connected to an Arduino so I purchased a kit and started to experiment.
I have been using the sensors for the last few years and can say they work fine. Below is the code for the Arduino UNO PCB layout and a list of components. I am not a coder or trained in electronic so this may be an amateur solution to some but it works and for me that’s what counts! I do have a few circuit boards left if anyone is interested – please contact us for info.
To see the sensor working please see here https://youtu.be/T1xoqpOK4LM but turn your speakers down 🙂
The sensors use a Hall effect sensor YF-S201 and an ATMega328P-PU microprocessor programmed with the code below. You will need a 9v power supply.
Code
#include <SevenSeg.h>
SevenSeg disp(1,8,3,4,5,6,7);
const int numOfDigits=4;
int digitPins[numOfDigits]={12,11,10,9};
int buzzer=13; // initialize digital IO pin that controls the buzzer
int FlowPin = 2;
double flowRate;
int lastFlow = -1;
int currentFlow = 0;
volatile int count;
const char *flowStrings[3] = { “OFF”, “HIGH”, “LO” };
void setup() {
pinMode(buzzer,OUTPUT); // set pin mode as “output”
pinMode(FlowPin, INPUT); //Sets the pin as an input
attachInterrupt(0, Flow, RISING); //Configures interrupt 0 (pin 2 on the Arduino Uno) to run the function “Flow”
disp.setDigitPins(numOfDigits, digitPins);
disp.setTimer(2);
disp.startTimer();
}
void loop() {
count = 0; // Reset the counter so we start counting from 0 again
interrupts(); //Enables interrupts on the Arduino
delay (2000); //Wait 2 seconds
noInterrupts(); //Disable the interrupts on the Arduino
flowRate = (count * 2.25); //Take counted pulses in the last second and multiply by 2.25mL
flowRate = flowRate * 60; //Convert seconds to minutes, giving you mL / Minute
flowRate = flowRate / 1000; //Convert mL to Litres, giving you Litres / Minute
if (flowRate < 1) {
currentFlow = 0;
digitalWrite(buzzer, HIGH); // produce sound
} else if ((flowRate > 1) && (flowRate < 2)) {
currentFlow = 2;
digitalWrite(buzzer, LOW);
} else {
currentFlow = 1;
}
if (lastFlow != currentFlow) {
disp.write(flowStrings[currentFlow]);
lastFlow = currentFlow;
digitalWrite(buzzer, LOW);
}
}
void Flow()
{
count++; //Every time this function is called, increment “count” by 1
}
ISR(TIMER2_COMPA_vect){
disp.interruptAction();
}
Components Required
Component | RS Stock No. | ||
A | Cap | 10uF 50V | 7442136 |
B | Volt reg | 7805T | 7192768 |
C | Cap | 10uF 50V | 7442136 |
D | Resistor | 10k | 7077745 |
E | Resistor | 220k | 7077612 |
F | Resistor | 220k | 7077612 |
G | Resistor | 220k | 7077612 |
H | Resistor | 220k | 7077612 |
I | Resistor | 220k | 7077612 |
J | Resistor | 220k | 7077612 |
K | Resistor | 220k | 7077612 |
L | Resistor | 10k | 7077745 |
M | led | 4 Digit Seven Segment LED Display 0.36″ 3461BS | |
N | Crystal | Hc495 16.000MHz | 6720299 |
O | Ceramic Cap | 22pF | 8523324 |
P | Ceramic Cap | 22pF | 8523324 |
Q | Speaker | 3Vdc 85dB | 7716957 |
R | Microprocessor | AVR 32K FLASK 2K SRAM | 1310276 |
S | led | 25mA 5mm | 2285988 |
T | Resistor | 220k | |
flow meter YF-S201 | |||
28 pin socket | |||
Chassis mount power socket 2.1mm | 448370 |