-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpHController.ino
154 lines (118 loc) · 3.51 KB
/
pHController.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <Event.h>
#include <Timer.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Timer t;
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
float sensorValue = 0; // value read from the pot
float sensorValueOld;
float voltage;
float pH;
float senSorValueSum;
const float pump_feed = 4.347826; // ml/sec
int time_min; // time_left
int time_sec; // time_left
int pHcount=0;
void sensor_Read()
{
senSorValueSum = 0;
for(int l=1;l<=500;l++)
{
sensorValue = analogRead(analogInPin);
senSorValueSum = senSorValueSum + sensorValue;
}
sensorValue =senSorValueSum/500;
pH = 1-((0.026315789473684210526315789473684*sensorValue)-23.647369);
//pH = ((sensorValue-745.375)/-25.625);
}
void setup() {
Serial.begin(9600);
int tickEvent = t.every(10800000, doSomething); // every 3 hours
//int tickEvent = t.every(3600000, doSomething); // every 1 hour
//int tickEvent = t.every(1000, doSomething); // every 10 seconds
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
lcd.begin(20, 4);
lcd.print(" pH Controller ");
}
void loop() {
t.update();
sensor_Read();
Serial.print("pH = " );
Serial.print(pH,1);
Serial.print(" ADC = " );
Serial.println(sensorValue);
delay(50);
lcd.setCursor(0, 1);
lcd.print("Monitoring Mode");
lcd.setCursor(0, 2);
lcd.print("pH = ");
lcd.print(pH,1);
lcd.print(" EC = --");
lcd.setCursor(0, 3);
lcd.print("Temp = --");
//lcd.setCursor(0, 3);
//lcd.print("ADC = ");
//lcd.print(sensorValue);
delay(500);
}
void doSomething() // do after tick
{
sensor_Read();
//while(sensorValue<=515) // pH = 6.2
while(pH>6.2) // pH = 6.2
{
float ml_feed=0;
float pump_time=0;
ml_feed = (pH - 6.0)/0.009;
pump_time = ml_feed/pump_feed;
Serial.print("pH = " );
Serial.print(pH,1);
Serial.print(" ADC = " );
Serial.println(sensorValue);
Serial.print("Feed water = ");
Serial.print(ml_feed);
Serial.print("\r\n");
Serial.print("Pump time = ");
Serial.print((int)pump_time);
Serial.print("\r\n");
digitalWrite(7, LOW);
lcd.setCursor(0, 1);
lcd.print(" Pump ON ");
for(int k=0;k<pump_time;k++)
{
lcd.setCursor(0, 2);
lcd.print("Time Left ");
lcd.print((int)pump_time-k);
lcd.print(" s ");
lcd.setCursor(0, 3);
lcd.print(" ");
// Serial.print("Pump left ");
// Serial.print(pump_time-k);
// Serial.print(" s\r\n");
delay(1000);
}
//delay((int)pump_time*1000);
digitalWrite(7, HIGH);
// wait for mixing time
Serial.print("Mixing....");
Serial.print("\r\n");
lcd.setCursor(0, 1);
lcd.print(" Mixing Mode ");
int time_sec=900;
for(int k=0;k<time_sec;k++)
{
lcd.setCursor(0, 2);
lcd.print("Time Left ");
lcd.print(time_sec-k);
lcd.print(" s ");
lcd.setCursor(0, 3);
lcd.print(" ");
delay(1000);
}
Serial.print("Finished Mixing");
sensor_Read();
}
Serial.print("pH Ready...");
}