-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinal.ino
More file actions
65 lines (59 loc) · 1.53 KB
/
Copy pathfinal.ino
File metadata and controls
65 lines (59 loc) · 1.53 KB
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 <SPI.h>;
#include <ESP8266WiFi.h>;
#include <BlynkSimpleEsp8266.h>;
#include <SimpleTimer.h>;
#include <DHT.h>;
char auth[] = "auth_name";
char ssid[] = "ssid";
char pass[] = "password";
#define DHTPIN 4
#define pirPin 6 // Input for HC-S501
int pirValue; // Place to store read PIR Value
int pinValue; //Variable to read virtual pin
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
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(V1, h); // Humidity for gauge
Blynk.virtualWrite(V0, t); // Temperature for gauge
}
BLYNK_WRITE(V2)
{
pinValue = param.asInt();
}
void setup()
{
Serial.begin(115200);
delay(10);// See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);
pinMode(pirPin, INPUT);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
if (pinValue == HIGH)
{
getPirValue();
}
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
void getPirValue(void) //Get PIR Data
{
pirValue = digitalRead(pirPin);
if (pirValue)
{
Serial.println("Motion detected");
Blynk.notify("Motion detected");
}
}