-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final_Code.ino
130 lines (111 loc) · 2.65 KB
/
Final_Code.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
//Flowrate
int FLInterrupt = 1;
int FLPin = 3;
float calibrationFactor = 4.5;
volatile byte pulseCount;
float flowRate;
long oldTime;
void pulseCounter()
{
pulseCount++;
}
//RPM
int RPMInterrupt = 0;
float rev=0;
int rpm;
int oldtime=0;
int time;
void revCounter()
{
rev++;
}
byte pin13 = 13;
byte pin12 = 12;
byte pin8 = 8;
void setup() {
BTserial.begin(9600);
//Flowrate
pinMode(FLPin, INPUT);
digitalWrite(FLPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
oldTime = 0;
attachInterrupt(FLInterrupt, pulseCounter, FALLING);
//RPM
attachInterrupt(RPMInterrupt, revCounter, RISING);
//LCD
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Welcome to Group");
lcd.setCursor(6,1);
lcd.print("334");
delay(5000);
//LEDs
pinMode(pin13, OUTPUT);
pinMode(pin12, OUTPUT);
//Buzzer
pinMode(pin8, OUTPUT);
digitalWrite(pin8, HIGH);
delay(300);
digitalWrite(pin8, LOW);
delay(300);
digitalWrite(pin8, HIGH);
delay(300);
digitalWrite(pin8, LOW);
delay(300);
digitalWrite(pin8, HIGH);
delay(300);
digitalWrite(pin8, LOW);
delay(300);
}
void loop() {
//Flowrate
if((millis() - oldTime) > 1000) // Only process counters once per second
{
detachInterrupt(FLInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
pulseCount = 0;
attachInterrupt(FLInterrupt, pulseCounter, FALLING);
}
//RPM
delay(1000);
detachInterrupt(RPMInterrupt); //detaches the interrupt
time=millis()-oldtime; //finds the time
rpm=(rev/time)*60000; //calculates rpm
oldtime=millis(); //saves the current time
rev=0;
attachInterrupt(RPMInterrupt,revCounter,RISING);
//LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Flowrate:");
lcd.setCursor(9, 0);
lcd.print(flowRate);
lcd.setCursor(13, 0);
lcd.print("L/M");
lcd.setCursor(0,1);
lcd.print("Speed: ");
lcd.setCursor(8,1);
lcd.print(rpm);
lcd.print(" RPM");
//Bluetooth
BTserial.print(float(flowRate));
BTserial.print(",");
BTserial.print(rpm);
BTserial.print(";");
//LEDs
char value = BTserial.read();
if (int(flowRate) < 15 || value == "0") {
digitalWrite(pin12, HIGH);
digitalWrite(pin13, LOW); }
else if (int(flowRate >= 15) || value == "1") {
digitalWrite(pin12, LOW);
digitalWrite(pin13, HIGH); }
}