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:
// 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 :P):
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:
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!!