-
Notifications
You must be signed in to change notification settings - Fork 1
/
flowsensor.ino
62 lines (54 loc) · 1.14 KB
/
flowsensor.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
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
int A;
int B;
float Time=0;
float frequency=0;
float water=0;
float rate=0;
float Total=0;
const int input=A0;
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("WATER FLOW METER");
lcd.setCursor(0,1);
lcd.print("**by MUCHIRA JUNIOR **");
delay(200);
pinMode(input,INPUT);
}
void loop (){
A=pulseIn(input,HIGH);
B=pulseIn(input,LOW);
Time=A+B;
frequency=1000000/Time;
water=frequency/0.75;
rate=water/3600;
if (frequency>=0){
if (isinf(frequency)){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("rate : 0.00");
lcd.setCursor(0,1);
lcd.print("TOTAL :");
lcd.print(Total);
lcd.print(" L");
}
else{
Total=Total+rate;
Serial.println(frequency);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("rate : ");
lcd.print(water);
lcd.print("L/min");
lcd.setCursor(0,1);
lcd.print("TOTAL :");
lcd.print(Total);
lcd.print(" L");
}
}
delay(1000);
}