36 lines
724 B
C++
36 lines
724 B
C++
#include <DHT11.h>
|
|
|
|
#define DHTPIN 2
|
|
|
|
DHT11 dht(DHTPIN);
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
Serial.begin(115200);
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
|
|
int h = 0;
|
|
int t = 0;
|
|
//int h = dht.getHumidity();
|
|
//int t = dht.readTemperature();
|
|
//float f = dht.getTemperature(true);
|
|
|
|
int res = dht.readTemperatureHumidity(t, h);
|
|
|
|
if (res == 0) {
|
|
Serial.print("{ \"tempC\" : ");
|
|
Serial.print(t);
|
|
Serial.print(", \"tempF\" : ");
|
|
Serial.print("0.00");
|
|
Serial.print(", \"tempH\" : ");
|
|
Serial.print(h);
|
|
Serial.println(" }");
|
|
} else {
|
|
Serial.println(DHT11::getErrorString(res));
|
|
}
|
|
delay(1000); // this speeds up the simulation
|
|
}
|