Simple Arduino Thermostat

Im using an

Arduino Uno

DHT22 sensor (pin 8)

1 relay (pin 2)

thats all this is my code it compiles but I dont think its working. Ive spent a lot of time on this already and it should be simple please help.

#include “DHT.h”

#define DHTTYPE DHT22

#define DHTPIN 8

DHT dht(DHTPIN, DHTTYPE);

#define CROCKPOTPIN 2

#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 = 0;

else if (t < TEMP_LOW) crockValue = 1;

digitalWrite(CROCKPOTPIN, crockValue);

delay(2000); // DHT's need a delay between readings ...

}

Why do you think it’s not working ? What is it doing, or not doing, that strikes you as wrong ?

I note that this line is bad.

int temperatureF = (t * 9 / 5) +32.5;

To do that type of math you need the variable to be a floating point type. It also helps to make it clear that FP math is to be done, like this.

float temperatureF = (t * 9.0 / 5.0) + 32.5;