-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensDhtGsmMotor.ino
236 lines (221 loc) · 5.27 KB
/
SensDhtGsmMotor.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
#include<SoftwareSerial.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define DHTPIN D0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
char auth[] = "a81c7019948e4cb8a6fa1603c223e30c";
char ssid[] = "Narsimha";
char password[] = "Simhalp9";
SoftwareSerial gsm(D2,D3);
int sm=A0;
//const char* ssid = "Narsimha";
//uconst char* password = "Simhalp9";
WiFiClient client;
unsigned long myChannelNumber = 543197;
const char * myWriteAPIKey = "FCYOGGX6WKSZTOZN";
uint8_t temperature, humidity, k=0, l=0,m=0;
void setup()
{
Serial.begin(9600);
dht.begin();
delay(10);
Blynk.begin(auth, ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
pinMode(sm,INPUT);
gsm.begin(9600);
}
void loop()
{
Blynk.run();
int sensorvalue=analogRead(A0);
sensorvalue=constrain(sensorvalue,485,1023);
int soil=map(sensorvalue,485,1023,100,0);
Serial.println("moisture:");
Serial.println(soil);
Serial.println("%");
static boolean data_state = false;
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.print("Temperature Value is :");
Serial.print(temperature);
Serial.println("C");
Serial.print("Humidity Value is :");
Serial.print(humidity);
Serial.println("%");
while(1)
{
if(temperature < 255)
{
k=temperature;
ThingSpeak.writeField(myChannelNumber, 1, k, myWriteAPIKey);
}
if(humidity < 255)
{
l=humidity;
ThingSpeak.writeField(myChannelNumber, 2, l, myWriteAPIKey);
}
if(soil<101)
{
m=soil;
ThingSpeak.writeField(myChannelNumber, 3, m, myWriteAPIKey);
}
}
int count=1;
if(soil<50)
{
while(count>=1&&count<=3)
{
if(count==1)
{
if(soil<=50)
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println ("1 stplant moisture % is:");
Serial.println ("1 stplant moisture % is:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
delay(10000);
int sensorvalue=analogRead(A0);
sensorvalue=constrain(sensorvalue,485,1023);
int soil=map(sensorvalue,485,1023,100,0);
if(soil>50)
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println (" now 1 stplant moisture % is:");
Serial.println (" now 1 stplant moisture % is:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
break;
}
}
}
else if(count==2)
{
if(soil<=50)
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println ("2nd stplant moisture % is:");
Serial.println ("2nd plant moisture % is:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
delay(10000);
int sensorvalue=analogRead(A0);
sensorvalue=constrain(sensorvalue,485,1023);
int soil=map(sensorvalue,485,1023,100,0);
if(soil>50)
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println (" now 2 stplant moisture % is:");
Serial.println (" now 2 ndstplant moisture % is:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
break;
}
}
}
else if(count==3)
{
if(soil<=50)
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println ("3 stplant moisture % is:");
Serial.println ("3 rdtplant moisture % is:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
delay(10000);
int sensorvalue=analogRead(A0);
sensorvalue=constrain(sensorvalue,485,1023);
int soil=map(sensorvalue,485,1023,100,0);
if(soil>50)
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println (" now 3 stplant moisture % is:");
Serial.println ("now 3rd stplant moisture % is:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
break;
}
}
}
count++;
delay(10000);
}
}
else
{
gsm.println("ATCMGF=1");
gsm.println("AT+CMGS=\"+918499008525\"\r"); //Mobile phone number to send message
delay(1000);
gsm.println ("your plant is safe:");
Serial.println ("your plant is safe:");
gsm.println(soil);
gsm.println("%");
delay(100);
gsm.println("ATD8309483023;");
delay(100);
gsm.println("ATH");
gsm.println((char)26);
}
delay(10000);
}