-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino Code.txt
144 lines (125 loc) · 3.22 KB
/
Arduino Code.txt
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int PhPin = A0;
int TurbidityPin = A1;
int FlowPin = A2;
float PhVolt;
float PhAct;
float PhAvg = 0.0;
float TempValue;
float TurbidityVolt;
float ntu;
int Button = 0;
int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
void setup() {
pinMode(10, INPUT); //Button Pin
pinMode(PhPin, INPUT);
pinMode(FlowPin, INPUT);
pinMode(TurbidityPin, INPUT);
Serial.begin(115200);
while (!Serial);
// Start up the library
sensors.begin();
}
void loop() {
Button = 0;
while (Button == 0)
Button = digitalRead(10);
//PH code
for (int i = 0; i < 20; i++)
{
PhVolt = analogRead(PhPin);
PhVolt = (PhVolt * 5) / 1024;
PhAct = -5.7 * PhVolt + (21.34 - 0.7);
PhAvg += PhAct;
// delay(200);
}
PhAvg /= 20;
Serial.println(PhAvg);
//Temperature Code
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
// Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
// Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
// Serial.print("Temperature for the device 1 (index 0) is: ");
TempValue = sensors.getTempCByIndex(0);
Serial.println(TempValue);
//delay(200);
//Turbidity Code
TurbidityVolt = 0;
for (int i = 0; i < 800; i++)
{
TurbidityVolt += ((float)(analogRead(TurbidityPin)) * 5) / 1024;
}
TurbidityVolt = TurbidityVolt / 800;
TurbidityVolt = round_to_dp(TurbidityVolt, 2);
if (TurbidityVolt < 2.5)
{
ntu = 3000;
}
else
{
TurbidityVolt *= (4.2 / 3.7);
ntu = -1120.4 * square(TurbidityVolt) + 5742.3 * TurbidityVolt - 4353.8;
}
//Serial.println(TurbidityVolt);
Serial.println(ntu);
// delay(200);
//Water Flow Code
X = pulseIn(FlowPin, HIGH);
Y = pulseIn(FlowPin, LOW);
TIME = X + Y;
FREQUENCY = 1000000 / TIME;
WATER = FREQUENCY / 7.5;
LS = WATER / 60;
if (FREQUENCY >= 0)
{
if (isinf(FREQUENCY))
{
//Serial.println();
//Serial.println("VOL. : 0.00");
Serial.println(0);
//Serial.print("TOTAL: ");
Serial.println(TOTAL);
//Serial.print(" L");
//Serial.println();
}
else
{
TOTAL = TOTAL + LS;
//Serial.println();
//Serial.println(FREQUENCY);
//Serial.print("VOL. : ");
Serial.println(WATER);
//Serial.print(" L/M");
//Serial.println();
//Serial.print("TOTAL: ");
Serial.println(TOTAL);
//Serial.print(" L");
//Serial.println();
}
}
// delay(200);
}
float round_to_dp( float in_value, int decimal_place )
{
float multiplier = powf( 10.0f, decimal_place );
in_value = roundf( in_value * multiplier ) / multiplier;
return in_value;
}