-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32.ino
47 lines (39 loc) · 880 Bytes
/
esp32.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
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "YourAuthToken";
const int sensorPin = 4;
int sensorState = 0;
int lastState = 0;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "SSID", "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);
}