-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelayDHT22.ino
93 lines (66 loc) · 2.16 KB
/
RelayDHT22.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266HTTPClient.h>
#include <SimpleTimer.h>
#define heatFan D1 // RELAY ADD
#define TURN_ON HIGH // RELAY ADD
#define TURN_OFF LOW // RELAY ADD
#include <Phant.h>
#include <DHT.h>
#define DHTTYPE DHT22
#define DHTPIN D4
DHT dht(DHTPIN, DHTTYPE, D4);
float humidity, temp; // Values read from sensor
unsigned long previousMillis = 0;
const long interval = 15000; // interval at which to read sensor / Update values
byte hiHumidity = 30; // relay ADD
byte lowHumidity = 35; // relay ADD
// Auth Token App via Mail of printscreen
char auth[] = "##########";
void setup() {
Serial.begin(115200);
Blynk.begin(auth, "#######", "##########");
dht.begin();}
void gettemperature() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you read the sensor
previousMillis = currentMillis;
// Reading temperature for humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
humidity = dht.readHumidity(); // Read humidity (percent)
temp = dht.readTemperature(false); // Read temperature as Fahrenheit
Blynk.virtualWrite(V0, temp);
Blynk.virtualWrite(V1, humidity);
if (humidity >= hiHumidity)
{
digitalWrite(heatFan, TURN_ON); // TURN ON heatFan (Relay1).
Serial.print("\t");
Serial.println(F("Exhausting the Humidity from A")); // Text printed to serial monitor
Serial.print("\t");
Serial.println();
}
if (humidity <= hiHumidity)
{
digitalWrite(heatFan, TURN_OFF); // TURN OFF heatFan (Relay1)
}
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp)) {
Serial.println("Failed to read from DHT sensor!");
return;}
}
}
bool isFirstConnect = true;
BLYNK_CONNECTED() {
if (isFirstConnect)
{
Blynk.syncAll();
isFirstConnect = false;
}
}
void loop()
{
Blynk.run();
gettemperature();
}