DHT22 Reading Delays

Hi All,

This is my first time using an Arduino Uno, so please bear with me. I'm using a DHT22 sensor to measure temperature and output 5v to D3 which will trigger a relay to turn on a fan. I've just adapted the DHT22 test code for this project. I want the fan to run for 1 minute, turn off, then wait for 10 minutes before it can be triggered again. The issue I'm running into is that after the 10 minutes, the next couple of temp readings appear to be from before the fan was triggered (10+ minutes ago), causing the fan to cycle again erroneously. Am I missing something obvious or is there a way to "dump" these old temp values it appears to be holding onto before it starts the next loop?

Here's my code:

#include "DHT.h"

#define DHTPIN 2 // what pin we're connected to

#define DHTTYPE DHT22 // DHT 22 (AM2302)

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
pinMode(3, OUTPUT); // sets the digital pin3 as output
dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(10000);

float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Outside Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(f);
Serial.println(" *F");

if (f > 80) {
Serial.print("It's warm enough to run exhaust fan. Outside temp is ");
Serial.print(f);
Serial.println(" Degrees F");
digitalWrite(3,HIGH);
delay(60000); // Runs fan for 1 minute
digitalWrite(3,LOW);
delay(600000); // Waits 10 minutes before it will cycle fan again
}

}

Thanks

You don't read the temp until 10 minutes after the fan turns off, don't you think the temp has time to get back to where it was?
Why not read the temp every 15 seconds or so, then you could see what's happening. How much temp drop are you expecting just running fan for 1 min?

Serial.print("It's warm enough to run exhaust fan. Outside temp is ");

Where is the temp sensor located in relation to the fan?
Surely you don't expect the fan to change the OUTDOOR temperature, do you?

@ JCA34F,

I fully expect the temperature probe to be back at ambient air temp (~70F) after 10 minutes. For this test I'm just holding the probe in my hand to cause it to get over 80F and trigger the cycle. What I've observed is that the next reading is sometimes even higher than the temp that triggered the 10 minute cycle. This is why I'm thinking the program is reading "old values" because theres no way the temperature probe is still that warm, or warmer!?

Here's an example of what I'm talking about:

22:44:51.943 -> Outside Humidity: 58.00 % Temperature: 73.40 *F
22:45:16.840 -> Outside Humidity: 57.50 % Temperature: 73.76 *F
22:45:26.827 -> Outside Humidity: 99.90 % Temperature: 75.92 *F
22:45:36.828 -> Outside Humidity: 99.90 % Temperature: 79.70 *F
22:45:46.835 -> Outside Humidity: 99.90 % Temperature: 82.58 *F
22:45:46.871 -> It's warm enough to run exhaust fan. Outside temp is 82.58 Degrees F
22:46:58.780 -> Outside Humidity: 63.60 % Temperature: 84.02 *F
22:46:58.849 -> It's warm enough to run exhaust fan. Outside temp is 84.02 Degrees F
22:48:10.775 -> Outside Humidity: 53.10 % Temperature: 81.86 *F
22:48:10.809 -> It's warm enough to run exhaust fan. Outside temp is 81.86 Degrees F
22:49:22.749 -> Outside Humidity: 52.10 % Temperature: 78.98 *F
22:49:32.727 -> Outside Humidity: 52.40 % Temperature: 76.46 *F
22:49:42.717 -> Outside Humidity: 52.90 % Temperature: 76.28 *F
22:49:52.744 -> Outside Humidity: 53.20 % Temperature: 76.10 *F
22:50:02.728 -> Outside Humidity: 53.50 % Temperature: 75.74 *F

Even after the third trigger, and the temp reads below 80, I think the values are still inaccurate for a few readings. Air temp is closer to 73 with the probe just sitting on the table. I'm not in the actual service location and don't have a fan hooked up to the relay yet.

I don't expect to change outside air temp, haha. There's more happening with this once I figure out this part of the code.

The temperature sensor is mounted on a small circuit board and enclosed in plastic, both of which are poor heat conductors, causing the sensor to change slower than it would hanging out in free air. Lay the sensor on the table and wait 10 minutes for it to stabilize. Set a tall glass of ice water 3 mm from it (NOT touching) and you will see. The cold air streaming down the side of the glass will immediately drop the temp several degrees, but the sensor may take 10 or 15 seconds to follow.