-
Notifications
You must be signed in to change notification settings - Fork 0
/
WAVGAT_AWESOME_ESP8266_DHT22_temperature_sensor.ino
68 lines (57 loc) · 1.76 KB
/
WAVGAT_AWESOME_ESP8266_DHT22_temperature_sensor.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
#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>
#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
// Auth Token App via Mail of printscreen
char auth[] = "ADD CHAR AUTH HERE";
void setup() {
Serial.begin(115200);
Blynk.begin(auth, "AP", "Password");
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
// Serial Monitor
Serial.print("Humidity ");
Serial.print(humidity);
Serial.println(" %\t");
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" *C ");
Blynk.virtualWrite(V0, temp);
Blynk.virtualWrite(V1, humidity);
// 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();
}