-
Notifications
You must be signed in to change notification settings - Fork 0
/
whaterCounter.ino
95 lines (91 loc) · 2.53 KB
/
whaterCounter.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
// Calculated litres/hour
int pontetionmeter = A0;
int price;
int ledPin = 9;
float vol = 0.0,l_minute;
unsigned char flowsensor = 3; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
analogRead(pontetionmeter);
pinMode(ledPin, OUTPUT);
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
lcd.begin(16, 2);
attachInterrupt(digitalPinToInterrupt(flowsensor), flow, RISING); // Setup Interrupt
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Water Flow Meter");
delay(500);
lcd.setCursor(0,1);
lcd.print("By Janvier");
delay(500);
currentTime = millis();
cloopTime = currentTime;
}
void loop (){
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000)){
cloopTime = currentTime; // Updates cloopTime
if(flow_frequency != 0){
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_minute = (flow_frequency / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Rate: ");
lcd.print(l_minute);
lcd.print(" L/M");
l_minute = l_minute/60;
lcd.setCursor(0,1);
vol = vol +l_minute;
lcd.print("Vol:");
lcd.print(vol);
lcd.print(" Mc");
lcd.print(" P:");
price = vol*0.7;
lcd.print(price);
lcd.print("$");
flow_frequency = 0; // Reset Counter
Serial.print(l_minute, DEC); // Print litres/hour
Serial.println(" L/Sec");
}
else {
Serial.println(" flow rate = 0 ");
lcd.clear();
if (price >=10){
digitalWrite(ledPin, HIGH);
if(analogRead(pontetionmeter) >= 1000){
vol = 0;
price = 0;
Serial.println(analogRead(pontetionmeter));
}
}
lcd.setCursor(0,0);
lcd.print("Rate: ");
lcd.print( flow_frequency );
lcd.print(" L/M");
lcd.setCursor(0,7);
lcd.print("Vol:");
lcd.print(vol);
lcd.print("Mc");
lcd.print(" P:");
lcd.print(price);
lcd.print("$");
}
}
}