-
Notifications
You must be signed in to change notification settings - Fork 5
/
15_Smart_Drip_irrigation.ino
60 lines (60 loc) · 1.96 KB
/
15_Smart_Drip_irrigation.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
/*************************************************************
SMART DRIP IRRIGATION
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
#define BLYNK_TEMPLATE_ID " "//Template ID
#define BLYNK_DEVICE_NAME " "//Device name
#define BLYNK_AUTH_TOKEN " "//Auth token
#define BLYNK_PRINT Serial
#define BLYNK_PRINT Serial
#define Motor D2
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = " ";//WIFI ID(case sensitive)
char pass[] = " ";//WIFI PASSWORD(case sensitive)
BlynkTimer timer;
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
void moisture()
{
int value = analogRead(A0);
value = map(value, 0, 1023, 0, 100);
Serial.println(value);
}
void setup()
{
pinMode(Motor,OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
float moisture_percentage;
moisture_percentage = ( 100.00 - ( (analogRead(A0)/1024.00)*100));
Serial.print("Soil Moisture(in Percentage) = ");
Serial.print(moisture_percentage);
Serial.println("%");
if(moisture_percentage<=30)
{
Serial.println("ON");
digitalWrite(Motor,HIGH);
}
else
{
Serial.println("OFF");
digitalWrite(Motor,LOW);
}
Blynk.virtualWrite(V0,moisture_percentage);
delay(1000);
Blynk.run();
timer.run();
}