-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_ss.ino
239 lines (215 loc) · 4.44 KB
/
node_ss.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <SPI.h>
#include<Ethernet.h>
#include<SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include<ESP8266WiFi.h>
#include<BlynkSimpleEsp8266.h>
#include<Servo.h>
Servo servo;
SoftwareSerial S1(D2, D3);
SoftwareSerial S2(D4, D5);//D4 pin=A0;
SoftwareSerial S3(D6, D7);
SoftwareSerial S5(D0, D1);
int pump=D8;
int pinValue, pinValue2, pinValue3, pinValue4;
float val1, val2, val3;
char auth[] = "enter your authentication code from blynk";
char ssid[] = "yyy";
char pass[] = "pahar123";
BlynkTimer timer;
void myTimerEvent()
{
Blynk.virtualWrite(V8, val1);
Blynk.virtualWrite(V6, val2);
Blynk.virtualWrite(V7, val3);
}
void setup()
{
Serial.begin(9600);
S1.begin(4800);
S2.begin(4800);
S3.begin(4800);
S5.begin(4800);
//S4.begin(4800);
pinMode(D2, INPUT);
pinMode(D3, OUTPUT);
pinMode(D4, INPUT);//D4 connection to be changed
pinMode(D5, OUTPUT);
pinMode(D6, INPUT);
pinMode(D7, OUTPUT);
pinMode(D8, INPUT);
pinMode(D9, OUTPUT);
pinMode(D0, INPUT);
pinMode(D1, OUTPUT);
pinMode(pump,OUTPUT);
servo.attach(D0);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
}
void sensor()
{
while (S1.available() > 0)
{
val1 = S1.parseFloat();
if (S1.read() == '\n')
{
Serial.print("moisture1:");
Serial.println(val1);
}
delay(30);
val2 = S1.parseFloat();
if (S1.read() == '\n')
{
Serial.print("moisture2:");
Serial.println(val2);
}
val3 = S1.parseFloat();
if (S1.read() == '\n')
{
Serial.print("moisture3:");
Serial.println(val3);
}
delay(30);
}}
BLYNK_WRITE(V1)
{
pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
}
BLYNK_WRITE(V2)
{
pinValue2 = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
}
BLYNK_WRITE(V3)
{
pinValue3 = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
}
BLYNK_WRITE(V0)
{
pinValue4 = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
}
/*BLYNK_READ(V5)
{
Blynk.virtualWrite(V8,val1);
}
BLYNK_READ(V6)
{
Blynk.virtualWrite(V6,val2);
}
BLYNK_READ(V7)
{
Blynk.virtualWrite(V7,val3);
}*/
void loop()
{
//delay(30);
sensor();
timer.run();
/*while (S4.available() > 0)
{
float val4 = S4.parseFloat();
if (S4.read() == '\n')
{
Serial.print("water_level:");
Serial.println(val4);
}*/
/*delay(30);
//delay(500);
if (pinValue > 0)
{
int i = 45;
S4.print(i);
S4.println('\n');
Serial.println("pin1on");
delay(30);
}
if (pinValue2 > 0)
{
int i = 90;
S4.print(i);
S4.println('\n');
Serial.println("pin2on");
delay(30);
}
if (pinValue3 > 0)
{
int i = 135;
S4.print(i);
S4.println('\n');
Serial.println("pin3on");
delay(30);
}*/
if (pinValue4 > 0)
{
if (pinValue > 0)
{
servo.write(135);
Serial.println("man1");
digitalWrite(pump,HIGH);
delay(2000);
digitalWrite(pump,LOW);
}
if (pinValue2 > 0)
{
servo.write(90);
Serial.println("man2");
digitalWrite(pump,HIGH);
delay(2000);
digitalWrite(pump,LOW);
}
if (pinValue3 > 0)
{
servo.write(45);
Serial.println("man3");
digitalWrite(pump,HIGH);
delay(2000);
digitalWrite(pump,LOW);
}
Serial.println("hhh");
int modee=1;
S5.println(modee);
S5.println('\n');
delay(30);
}
else
{
int modee=0;
S5.println(modee);
S5.println('\n');
delay(30);
servo.write(90);
if (val1 > 500)
{
servo.write(135);
Serial.println("water1");
digitalWrite(pump,HIGH);
delay(2000);
servo.write(90);
digitalWrite(pump,LOW);
}
if (val2 > 500)
{
servo.write(0);
Serial.println("water2");
digitalWrite(pump,HIGH);
delay(2000);
servo.write(90);
digitalWrite(pump,LOW);
}
if (val3 > 500)
{
servo.write(45);
Serial.println("water3");
digitalWrite(pump,LOW);
delay(2000);
servo.write(90);
digitalWrite(pump,LOW);
}
}
Blynk.run();
}