I have the dht22 wired sensor from adafruit conected to digital pin 2. I haven't played with arduino in over a year so any help or guidance from a couple things:
1:
I'm using this sensor so I can activate a relay going to a crock pot. This is where it'll turn on or off at a certain temperature.
2:
I'm using the humidty part to know when I need to open a valve controlled by a servo to control the humidty at a certain percentage.
3:
I have got it working on a LCD 16x2 display temp (f) and humidty. This will be just an extra add on and later I made add a min/max feature.
Also out of question (may need to be in hardware) has any interfaced this small relay off eBay that's already on a pcb? 
Can hardly see the pinout on silkscreen (I bought one).
Check - Arduino Playground - DHTLib - it supports a DHT22
Make the switchON and switchOFF temperatures two variables, to get some degree of freedom and to prevent fast ON/OFF iterations. Same for humidity
Here a sketch to get started, Temperature is almost coded, DHT.humidity is left as an exercise
just as some other parts...
Succes,
Rob
(not compiled or tested)
#include <dht.h>
dht DHT;
#define DHT22_PIN 2
#define CROCKPOTPIN 8
#define TEMP_HIGH 22
#define TEMP_LOW 20
#define HUMID_HIGH 60
#define HUMID_LOW 20
float minTemp = 100;
float maxTemp = 0;
float minHumid = 100;
float maxHumid = 0;
int crockValue = 0;
void setup()
{
Serial.begin(115200);
Serial.println("TEST PROGRAM ");
pinMode(CROCKPOTPIN, OUTPUT);
}
void loop()
{
// READ DATA
int chk = DHT.read22(DHT22_PIN);
// DO THE MIN/MAX
minTemp = min(minTemp, DHT.temperature);
maxTemp = max(maxTemp , DHT.temperature);
// DISPLAT DATA
Serial.println(DHT.temperature, 1);
// CROCKPOT
if (DHT.temperature > TEMP_HIGH) crockValue = 1;
else if (DHT.temperature < TEMP_LOW) crockValue = 0;
digitalWrite(CROCKPOTPIN, crockValue);
delay(2000); // DHT's need a delay between readings ...
}
Didn't compile correctly... But this does:
#include "DHT.h"
#define DHTTYPE DHT22
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE);
#define CROCKPOTPIN 4
#define TEMP_HIGH 22
#define TEMP_LOW 20
#define HUMID_HIGH 60
#define HUMID_LOW 20
float minTemp = 100;
float maxTemp = 0;
float minHumid = 100;
float maxHumid = 0;
int crockValue = 0;
void setup()
{
Serial.begin(115200);
Serial.println("TEST PROGRAM ");
pinMode(CROCKPOTPIN, OUTPUT);
}
void loop()
{
// READ DATA
int t = dht.readTemperature();
int temperatureF = (t * 9 / 5) +32.5;
// DO THE MIN/MAX
minTemp = min(minTemp, t);
maxTemp = max(maxTemp , t);
// DISPLAT DATA
Serial.println(temperatureF);
// CROCKPOT
if (t > TEMP_HIGH) crockValue = 1;
else if (t < TEMP_LOW) crockValue = 0;
digitalWrite(CROCKPOTPIN, crockValue);
delay(2000); // DHT's need a delay between readings ...
}
OK!,
If you work in Fahrenheit you might need to initialize the minTemp also in Fahrenheit : 212 iso 100 ![]()
How so? I believe standard the library is in Celcius not fahrenheit which I had to calculate to display F
Edit:
Basically the relay which is connected to say pin 4 its HIGH (relay closed) crock pot will be on till about 120ish degrees F. If it goes higher than 120 then the relay will be LOW (relay open).
How so? I believe standard the library is in Celcius not fahrenheit which I had to calculate to display F
OK you do the internal math in Celsius and display it ion Fahrenheit. That makes my remark obsolete. I was under the assumption that you would do the math in F My mistake.
If it is only for the displaying part you could move these lines together, combine them in a logical block or better a separate function. That would make it more explicit that only for displaying F is used ..
void displayTemp(int C)
{
int F = (C * 9 / 5) +32;
Serial.println(F);
}
I was meaning by reading the value of c (hence it's in celcius when on or off). Couldn't I use #define 120 in f not in c by using some math or am I just going to have to calculate it only for displaying ane figure the temp I'd have to set at in c for the relay?
You could do the whole sketch in Fahrenheit except the sensorreading. But even for that you could do
int f = (sensor.getTemperature() * 9 / 5) + 32;
#define 120 ==> #define ((120 * 9 /5) + 32) ![]()