-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemperature_monitor.ino
53 lines (47 loc) · 1.15 KB
/
temperature_monitor.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
#include <DHT_U.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int incomingByte = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
dht.begin();
}
//void loop() {
// // put your main code here, to run repeatedly:
// float h = dht.readHumidity();
// float t = dht.readTemperature();
// float hi = dht.computeHeatIndex(t, h, false);
// if (isnan(h) || isnan(t)){
// Serial.println("Failed to read from DHT");
// }else{
// Serial.print(t);Serial.print(",");Serial.print(h);
// Serial.println();
// //Serial.print("Feels like: ");
// //Serial.print(hi);
// }
// delay(5000);
//}
void sendData(){
float h = dht.readHumidity();
float t = dht.readTemperature();
float hi = dht.computeHeatIndex(t, h, false);
if (isnan(h) || isnan(t)){
Serial.println("Failed to read from DHT");
}else{
Serial.print(t);Serial.print(",");Serial.print(h);
Serial.println();
//Serial.print("Feels like: ");
//Serial.print(hi);
}
}
void loop(){
if (Serial.available() > 0){
incomingByte = Serial.read();
if (incomingByte == 'a' ){
sendData();
}
}
}