This repository has been archived by the owner on Jul 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Electric Conductivity
131 lines (115 loc) · 3.19 KB
/
Electric Conductivity
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
int R1= 1000;
int EC_Read = A0;
int ECPower = A1;
int Temp_pin = A5;
float Temp_C;
float Temp_F;
float Temp1_Value = 0;
float Temp_Coef = 0.019;
////////Calibration/////////////
float Calibration_PPM = 1080; //Cehck with solution of knowm PPM//
float K = 1.77; //Value of K will be specific for your probe//
float PPM_Con = 0.5;
//////////////////////////////////
float CalibrationEC = (Calibration_PPM * 2)/1000;
float Temperature;
float EC;
float EC_at_25;
int ppm;
float A_to_D = 0;
float Vin = 5;
float Vdrop = 0;
float R_Water;
float Value=0;
///////////////////////////////////
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (EC_Read, INPUT);
pinMode (ECPower, OUTPUT);
/////////////////////////////////
//Calibrate (); // After calibration make it comment by adding two //
}
void loop() {
// put your main code here, to run repeatedly:
GetEC();
delay (1000);
}
//////////////////////////////////////
void GetEC()
{
int val;
double Temp;
val = analogRead(Temp_pin);
Temp = log(((10240000/val)-10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp);
Temp_C = Temp - 273.15;
Temp_F = (Temp_C * 9.0)/5.0 + 32.0;
Temp1_Value = Temp_C;
Temperature = Temp_C;
digitalWrite(ECPower, HIGH);
A_to_D = analogRead(EC_Read);
A_to_D = analogRead(EC_Read);
digitalWrite(ECPower, LOW);
Vdrop = (Vin*A_to_D) / 1024.0;
R_Water = (Vdrop*R1) / (Vin-Vdrop);
EC = 1000 / (R_Water*K);
EC_at_25 = EC / (1+ Temp_Coef*(Temperature-25.0));
ppm= (EC_at_25)*(PPM_Con*1000);
Serial.print(" EC: ");
Serial.print(EC_at_25);
Serial.print(" milliSiemens(mS/Cm) ");
Serial.print(ppm);
Serial.print(" ppm ");
Serial.print(Temperature);
Serial.println(" *C ");
}
///////////////////////////////////////
void Calibrate ()
{
Serial.println("Calibration routine started");
float Temperature_end=0;
float Temperature_begin=0;
int val;
double Temp;
val= analogRead(Temp_pin);
Temp = log(((10240000/val) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp);
Temp_C = Temp - 273.15;
Temp_F = (Temp_C * 9.0)/ 5.0 + 32.0;
Temp1_Value = Temp_C;
Temperature_begin=Temp_C;
Value = 0;
int i=1;
while(i<=10){
digitalWrite(ECPower,HIGH);
A_to_D= analogRead(EC_Read);
A_to_D= analogRead(EC_Read);
digitalWrite(ECPower,LOW);
Value=Value+A_to_D;
i++;
delay(6000);
};
A_to_D=(Value/10);
val=analogRead(Temp_pin);
Temp = log(((10240000/val) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp))* Temp);
Temp_C = Temp - 273.15;
Temp_F = (Temp_C * 9.0)/ 5.0 + 32.0;
Temp1_Value = Temp_C;
Temperature_end=Temp_C;
EC =CalibrationEC*(1+(Temp_Coef*(Temperature_end-25.0)));
Vdrop= (((Vin)*(A_to_D))/1024.0);
R_Water=(Vdrop*R1)/(Vin-Vdrop);
float K_cal= 1000/(R_Water*EC);
Serial.print("Replace K in line 11 of code with K = ");
Serial.println(K_cal);
Serial.print("Temperature difference start to end were = ");
Temp_C=Temperature_end-Temperature_begin;
Serial.print(Temp_C);
Serial.print("*C");
Serial.print("Temperature difference start to end must be smaller than 0.15*C");
Serial.println("");
Calibrate ();
}