Pages: [1]   Go Down
Author Topic: Temperature Sensor Woes (DHT22 + TMP36)  (Read 1476 times)
0 Members and 1 Guest are viewing this topic.
Flagstaff, AZ
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I'm relatively new to Arduino, but have been playing with my Uno for a while now and have made several successful small projects.

I have begun a project for my girlfriend to monitor some elements inside a terrarium.  The basic basis for the project is that the temperature and humidity will be read inside the tank using a DHT22.  The temperature outside the tank will also be measured, using a TMP36 (since we have no need to measure humidity outside the tank, I figured I would use a more basic sensor).  Eventually the readings will go to a 16x2 LCD display, and the readings will also determine the behavior of some simple fans.

I am taking some baby steps both with the temperature sensors and the LCD display, since both of these things are new to me.  Fans are running on a different unit (a Boarduino) right now on basic on-off-on-off with simple timing and relays, and are working great for now.

Sorry for the long intro, but here's the problem I'm having:

When I take readings from the sensors, which are right next to each other (within an inch or so? see photo below), there is more variance in the temperatures than I was hoping for (4+ degrees F at any given time, and have not seen less variance so far).  The TMP36 is giving a temperature that has been consistently around 4 deg F lower than what the DHT22 is telling me.  I've tried blowing a fan across them for a few minutes, no real difference.  I have a 5 second delay in between my readings, so as not to overload and confuse my DHT22.  I've tried both different analog and digital input pins on my Uno.  All of these things return the same readings on my serial output, so I am starting to feel like there's no problem with my code or setup, and the sensors just think they're really seeing different temps.

Note that I'm not complaining about any variance between the individual sensors themselves.  I can do some averaging, and from what I'm seeing so far, the variance on the individual sensors is great (even with my TMP36 hooked to the 5v line, as opposed to the 3.3v with aref method, which I tried and seemed to get very, very similar readings).  I am really trying to figure out if I can get the sensors more in tune with one another, since this matters for the control of the fans and if the baseline readings are off, it's not really worth it for my girlfriend to monitor them in the first place.

I've hooked up both the DHT22 and the TMP36 as per the directions in these tutorials:
http://www.ladyada.net/learn/sensors/tmp36.html
http://www.ladyada.net/learn/sensors/dht.html

I also modified my code so that the serial output displays readings from both sensors at the same time:
Code:
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// Modified to also test TMP36

#include "DHT.h"

#define DHTPIN 8     // what pin we're connected to
int tmpPin = 0; // analog input pin for TMP 36

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("Begin!");
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int reading = analogRead(tmpPin);
  float voltage = reading * 5.0;
  voltage /= 1024.0;
  float tmpTempC = (voltage - 0.5) * 100.0 ;
  float tmpTempF = (tmpTempC * 9.0 / 5.0) + 32.0;

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("DHT Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("DHT Temperature: ");
    t = (t * 9.0 / 5.0) + 32.0;
    Serial.print(t);
    Serial.println(" *F");
  }
  Serial.print("TMP Voltage: ");
  Serial.print(voltage, 3); Serial.print(" volts \t");
  Serial.print("TMP Temp: ");
  Serial.print(tmpTempF); Serial.println(" *F");
  Serial.println(" ");
 
  delay(5000);
}

Here's a photo of my setup (no fancy wires for me right now... just wires out of a cat5e cable  smiley-razz):
http://www.cbunch.com/temp/tmp36_and_dht22.jpg

And, in case it helps, here's some typical output from my serial monitor with a fan blowing across the sensors for a few minutes:
Code:
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.737 volts TMP Temp: 74.71 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.737 volts TMP Temp: 74.71 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.737 volts TMP Temp: 74.71 *F
 
DHT Humidity: 24.40 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F
 
DHT Humidity: 24.50 % DHT Temperature: 78.62 *F
TMP Voltage: 0.732 volts TMP Temp: 73.84 *F

Any help will be really appreciated, and thanks for reading!!
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

why not buy a ntc resistor and a resistor and built ur own sensor for 1$ which u can calibrate urself

depending how the values vary from temp to temp you just could maybe add a fixed value to one of them
« Last Edit: June 14, 2012, 01:04:26 pm by lax123 » Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10431
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The TMP36 should be decoupled ideally.

Which one is right though?  Does the DHT undergo some self-heating (strong forced ventilation should counteract this).  Also I don't trust its accuracy as much as I do the TMP36 given the quality of the datasheet(!)
Logged

[ I won't respond to messages, use the forum please ]

Flagstaff, AZ
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the responses!

As for buying my own ntc resistor, I figured for the convenience and great readings, the TMP was a good place to start for a newbie like me, and was a fine deal IMO for $2 even.  But I did consider the route you mentioned.

I did think about adding a fixed value to one of them for calibration.  I've also considered using a multiplicative coefficient to even them out the best I can with some algebra.

As for which one is right - according to the thermostat in the room where I'm in (which at the time I took these readings, had 2 fans circulating air throughout the room), the TMP36 is really close.  I am guessing that the DHT22 is reading high.

I think after work I'll play with some other temperatures and take some readings, and possibly try to get some algebraic stuff worked out to find a coefficient to multiply the DHT22 value by so that they get closer to one another.  I don't need them to be exactly the same (and realize that is likely not possible really), but maybe closer to 1 deg F variance rather than 4 deg F variance.

Thanks again for the responses!
Logged

Pages: [1]   Go Up
Jump to: