-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemperature_sensor_code.ino
50 lines (39 loc) · 1.12 KB
/
Temperature_sensor_code.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
#define BLYNK_TEMPLATE_ID "TMPL3afXgVUwK"
#define BLYNK_TEMPLATE_NAME "DHT IoT Sensor"
#define BLYNK_AUTH_TOKEN "XLhkkQpBw4ltcC7GHNDYklXLVvTiZ5Kq"
#include <DHT.h>
#include <BlynkSimpleEsp8266.h>
#define DHTPIN 4 //data pin connected to d2 on ESP
#define DHTTYPE DHT11 // Name the sensor as an object
char auth[] = "XLhkkQpBw4ltcC7GHNDYklXLVvTiZ5Kq";
char ssid[] = "Sneh 1";
char pass[] = "spp@2005";
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("DHT Test Successful!");
Blynk.begin(auth, ssid, pass);
Serial.println("Blynk Connected Successfully");
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h)|| isnan(t)||isnan(f))
{
Serial.println("Something is not working as intended");
return;
}
Serial.print("Humidity");
Serial.print(h);
Serial.println("%");
Serial.print("Temperature");
Serial.print(t);
Serial.println("degreed celsius.");
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
delay(1000);
}