Code:
boolean measure(int &temperature, int &humidity);// Return values must be divided by 10
boolean measure(float &temperature, float &humidity) {
The temperature and humidity is read with the same function, it will return true when it has read a value and false if the reading fails for some reason.
Code:
#include
#define DHT22_PIN 14
DHT22 dht(DHT22_PIN);
void setup() {
Serial.begin(9600);
}
void loop() {
if (dht.ready()) {
float temperature;
float humidity;
if (dht.measure(temperature, humidity)) {
Serial.print("Temperature: ");
Serial.print(temperature,1);
Serial.print("*C Humidity: ");
Serial.print(humidity,1);
Serial.println("%RH");
}
}
if (dht.isError()) {
Serial.println("Error in communication with DHT22 sensor");
delay(3000);
}
}
There is not needed much code to use the library.