-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomemonitor.ino
More file actions
63 lines (44 loc) · 1.27 KB
/
Copy pathhomemonitor.ino
File metadata and controls
63 lines (44 loc) · 1.27 KB
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
// This #include statement was automatically added by the Spark IDE.
#include "HTU21D/HTU21D.h"
// This #include statement was automatically added by the Spark IDE.
#include "MCP9808/MCP9808.h"
/*
Spark Core MCP9808 Temperature Sensor Library
By: Romain MP
Licence: GPL v3
*/
double tempf, tempc, humidity, alttemp;
MCP9808 mcp = MCP9808();
HTU21D htu = HTU21D();
void setup()
{
Serial.begin(9600);
delay(5000);
Serial.println("MCP9808 test");
while(! mcp.begin()){
Serial.println("MCP9808 not found");
delay(500);
}
while(! htu.begin()){
Serial.println("HTU21D not found");
delay(1000);
}
mcp.setResolution(MCP9808_SLOWEST);
Serial.println("MCP9808 OK");
Serial.println("HTU21D OK");
Spark.variable("tempf", &tempf, DOUBLE);
Spark.variable("humidity", &humidity, DOUBLE);
}
void loop()
{
tempc = mcp.getTemperature();
tempf = (9.0/5) * tempc + 32;
humidity = htu.readHumidity();
alttemp = htu.readTemperature();
Serial.println("===================");
Serial.print("Temp in F: "); Serial.println(tempf, 2);
Serial.print("Temp in C: "); Serial.println(mcp.getTemperature(), 2);
Serial.print("Hum: "); Serial.println(humidity);
Serial.print("Alternative Temp: "); Serial.println(alttemp, 2);
delay(5000);
}