1#define BLYNK_PRINT Serial
2#include <ESP8266WiFi.h>
3#include <BlynkSimpleEsp8266.h>
4
5#include <OneWire.h>
6#include <DallasTemperature.h>
7#define ONE_WIRE_BUS 2
8OneWire oneWire(ONE_WIRE_BUS);
9DallasTemperature sensors(&oneWire);
10
11#include "DHTesp.h"
12
13DHTesp dht;
14
15
16char auth[] = "uGDn56XGhJS7TkEb0D_gAzkFL66czQDs";
17char ssid[] = "y-home";
18char pass[] = "Yurdakul9988!";
19BlynkTimer timer;
20
21
22float temp;
23int lowTemp;
24int hiTemp;
25float ambTemp;
26float ambHum;
27
28byte notifState = 0;
29
30bool isFirstConnect = true;
31BLYNK_CONNECTED() {
32 if (isFirstConnect) {
33 Blynk.syncAll();
34 isFirstConnect = false;
35 }
36}
37
38void setup()
39{
40
41 Blynk.begin(auth, ssid, pass);
42 timer.setInterval(10000L, tempSend);
43 timer.setInterval(5000L, probeSend);
44 timer.setInterval(10000L, notifSend);
45 sensors.begin();
46 dht.setup(14, DHTesp::DHT11);
47}
48
49BLYNK_WRITE(V1) {
50 byte value = param.asInt();
51 lowTemp = value;
52}
53
54BLYNK_WRITE(V2) {
55 byte value = param.asInt();
56 hiTemp = value;
57}
58
59BLYNK_WRITE(V3) {
60 byte value = param.asInt();
61 notifState = value;
62}
63
64void tempSend() {
65
66 float humidity = dht.getHumidity();
67 float temperature = dht.getTemperature();
68
69 ambTemp = temperature;
70 ambHum = humidity;
71 Blynk.virtualWrite(V11, ambTemp);
72 Blynk.virtualWrite(V12, ambHum);
73
74
75
76}
77
78void probeSend() {
79 sensors.requestTemperatures();
80 temp = sensors.getTempCByIndex(0);
81 Blynk.virtualWrite(V10, temp);
82}
83
84void notifSend() {
85 if (notifState == 1 && ambTemp >= hiTemp) {
86 Blynk.notify("Oda sicakligi cok yusek!");
87 delay(300);
88 Blynk.virtualWrite(V3, 0);
89 notifState = 0;
90 }
91 if (notifState == 1 && ambTemp <= lowTemp) {
92 Blynk.notify("Oda sicakligi cok dusuk!");
93 delay(300);
94 Blynk.virtualWrite(V3, 0);
95 notifState = 0;
96 }
97}
98
99
100void loop()
101{
102 Blynk.run();
103 timer.run();
104}