-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmart Irrigation & Plant Monitoring.txt
65 lines (64 loc) · 1.52 KB
/
Smart Irrigation & Plant Monitoring.txt
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
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
char auth[] = "Y1wPunpUXU8NPEiUFjzLb_PMkFIHrWO8";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "vivo 1818";
char pass[] = "purva1818";
//DHT11 for reading temperature and humidity value
#define Light D2
#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
float moisture;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V2, t);
Blynk.virtualWrite(V1, h);
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(Light,OUTPUT);
Blynk.begin(auth, ssid, pass);
digitalWrite(Light,HIGH);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.virtualWrite(V3,analogRead(A0));
moisture=analogRead(A0);
Serial.print("Moisture");
Serial.println(moisture);
if(analogRead(A0) <= 600)
{
digitalWrite(Light,HIGH);
Blynk.notify("Pump Stop, Water not Flowing");
Serial.println("Pump Stop, Water not Flowing");
delay(2000);
}
else if(analogRead(A0)>= 650)
{
Serial.println("Pump started, Water Flowing");
Blynk.notify("Pump Started, Water Flowing");
digitalWrite(Light,LOW);
delay(2000);
}
Blynk.run();
timer.run();
}