int timeSinceLastRead = 0; void loop() { // Report every 2 seconds. if(timeSinceLastRead > 2000) { // Reading temperature or humidity takes about 250 milliseconds! // Read temperature as Celsius (the default) float t12 = dht12.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f12 = dht12.readTemperature(true); // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h12 = dht12.readHumidity();
bool dht12Read = true; // Check if any reads failed and exit early (to try again). if (isnan(h12) || isnan(t12) || isnan(f12)) { Serial.println("Failed to read from DHT12 sensor!");
dht12Read = false; }
if (dht12Read){ // Compute heat index in Fahrenheit (the default) float hif12 = dht12.computeHeatIndex(f12, h12); // Compute heat index in Celsius (isFahreheit = false) float hic12 = dht12.computeHeatIndex(t12, h12, false); // Compute dew point in Fahrenheit (the default) float dpf12 = dht12.dewPoint(f12, h12); // Compute dew point in Celsius (isFahreheit = false) float dpc12 = dht12.dewPoint(t12, h12, false);