-
Notifications
You must be signed in to change notification settings - Fork 0
/
waterQfuzzy.ino
142 lines (113 loc) · 2.24 KB
/
waterQfuzzy.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
//fuzzy logic
#include "fuzz.h"
//gsm
#include "gsm.h"
//temperature
#include <OneWire.h>
#include <DallasTemperature.h>
int ONE_WIRE_BUS =4; //D4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float get_temp()
{
sensors.requestTemperatures();
delay(100);
float temp=sensors.getTempCByIndex(0);
temp=24.0;
return temp;
}
//turbidity sensor
#define tubPin A0
float get_tub(){
int analogValue = analogRead(tubPin);
float tub = map(analogValue, 0, 1023, 0, 100);
return tub;
}
// EC sensor
#include "DFRobot_EC.h"
#include <EEPROM.h>
#define EC_PIN A1
DFRobot_EC ec;
float get_ec ()
{
float voltage = analogRead(EC_PIN)/1024.0*5000;
float temp=get_temp();
ec.calibration(voltage,temp);
float ecValue = ec.readEC(voltage,temp);
return ecValue ;
}
//lcd
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //sda A4, scl A5
#define relay 9
void stop_pump()
{
digitalWrite(relay,HIGH);
}
void pump()
{
digitalWrite(relay,LOW);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//initiating fuzzy logic
fuzzy_logic_init();
//initializing temperature sensor
sensors.begin();
//ec sensor
ec.begin();
delay(100);
//lcd
lcd.init(); //initialize the lcd
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Water Quality");
lcd.setCursor(0,1);
lcd.print("GROUP 3");
gsm_init();
delay(500);
lcd.clear();
//pins
pinMode(EC_PIN,INPUT);
pinMode(relay,OUTPUT);
digitalWrite(relay,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
float Temp=get_temp();
float Tub =get_tub();
delayMicroseconds(500);
float Ec = get_ec();
Serial.print("Temp: ");
Serial.println(Temp);
Serial.print("Tub: ");
Serial.println(Tub);
Serial.print("EC: ");
Serial.println(Ec);
float output= fuzzy_result(Tub,Ec,Temp);// tub ,ec respectively
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Fuzzy T Ec");
lcd.setCursor(0,1);
lcd.print(output);
lcd.setCursor(5,1);
lcd.print(Tub);
lcd.setCursor(10,1);
lcd.print(Ec);
if (output >50)
{
pump();
send_gsm(1);
}
else if(output>30 && output <50){
pump();
send_gsm(2);
}
else if (output<30)
{
stop_pump();
send_gsm(3);
}
}