-
Notifications
You must be signed in to change notification settings - Fork 0
/
Water_Notify_Blynk.ino
49 lines (40 loc) Β· 1018 Bytes
/
Water_Notify_Blynk.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
//Viral Science www.youtube.com/c/viralscience
//Water Plants Notification Blynk
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "90f6fbee96074a519729796ee8673186"; //code sent via email
const int sensorPin = 4;
int sensorState = 0;
int lastState = 0;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "Hacked", "0123456789"); //wifi name and password
pinMode(sensorPin, INPUT);
}
void loop()
{
Blynk.run();
sensorState = digitalRead(sensorPin);
Serial.println(sensorState);
if (sensorState == 1 && lastState == 0) {
Serial.println("needs water, send notification");
Blynk.notify("Water your plants");
lastState = 1;
delay(1000);
//send notification
}
else if (sensorState == 1 && lastState == 1) {
//do nothing, has not been watered yet
Serial.println("has not been watered yet");
delay(1000);
}
else {
//st
Serial.println("does not need water");
lastState = 0;
delay(1000);
}
delay(100);
}