DHT ERROR WHILE RUNNING

Hi,

I hope someone can help. I am new to Arduino and am having problems with the program while it is running. The circuit consists of two DHT 22 sensors. One sensor controls one relay controlling a humidifier and the other sensor controls two relays one for a heater and the other for a dehumidifier. The program runs perfectly for about an hour or two and then the LCD displays "ERROR" for both of the sensors and will not reset on its own. The only way to reset it is to turn it off and on again. I hope this makes sense and have copied the code in that I am using. Any feedback would be great.

Many Thanks

#include <Adafruit_Sensor.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <DHT.h>
#include <DHT_U.h>
#include "DHT.h"
#define DHTTYPE DHT22   
#define settemp 15
#define sethum 85
#define sethumm 90

int DHTPIN = 6;  
int DHTPIN1 = 18;

int relay = 7; 
int relay1 = 8;
int relay2 = 9;

float t;  
float h;
float tt;
float hh;





LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2
DHT dht(DHTPIN, DHTTYPE);
DHT dhtt(DHTPIN1, DHTTYPE);

void setup() 
{
 pinMode (relay, OUTPUT);  
 pinMode (relay1, OUTPUT);
 pinMode (relay2, OUTPUT);
 
 Serial.begin (9600); // set the serial monitor tx and rx speed
 lcd.begin(16, 2); // set up all the "blocks" on the display
 lcd.setCursor(0,0); // set the cursor to colum 0 row 0
 lcd.print("RESTARTING"); 
 delay(5000);
 lcd.clear(); // clear the lcd
 dht.begin();
 dhtt.begin();
 
 
}

void loop() 
{

 
 lcd.setCursor (0,0); // set the cursor to 0,0
 // 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 hh = dhtt.readHumidity();
 
 float t = dht.readTemperature();
 float tt = dhtt.readTemperature();

 // Read temperature as Fahrenheit (isFahrenheit = true)
 float f = dht.readTemperature(true);
 

 // Check if any reads failed and exit early (to try again).
 if (isnan(h) || isnan(t)) 
 {
   lcd.setCursor(10, 0);
   lcd.print("ERROR");
   return;}
   
 if (isnan(hh) || isnan(tt))
 { 
   lcd.print("ERROR");
   return;}

 
 lcd.setCursor(10, 0);
 lcd.print (t);  
 lcd.print ('C');
 lcd.setCursor(10,1);
 lcd.print (h);
 lcd.print ("%");
 lcd.setCursor(0, 0);
 lcd.print(tt);
 lcd.print("C");
 lcd.setCursor(0, 1);
 lcd.print(hh);
 lcd.print("%");
 
 
 
 if (t < settemp ) 
 {digitalWrite (relay, 1);}
 else{}
 if (t > settemp)
 {digitalWrite (relay , 0);}
 
 if (h > sethum ) 
 {digitalWrite (relay2, 1);}
 else{}
 if (h < sethum)
 {digitalWrite (relay2 , 0);}
 
 if (hh < sethumm)
 {digitalWrite (relay1, 1);}
 else{}
 if (hh > sethumm)
 {digitalWrite (relay1, 0);}
 

 delay (5000); 
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

You forgot the link to the libraries used as well as the code tags around your code. Please provide a wiring diagram of your complete setup.

Your problem seems to be either a power problem (p.e. missing free run diode on the relays) or a memory problem (maybe there's a leak in one of the libraries).

When the display shows "ERROR" does it show "RESTARTING" afterwards?

@Daniel2468, do not cross-post. Other thread removed.

Hi pylon

While the program is running it does display "restarting" several times then carries on reading the DHT's. After an hour or so it just displays ERROR on both sensors and does not self reset i have to do it manually.

The relays that I have used are 20a beefcake relays which have two diodes connected to them.

The DHT sensors are wired from left to right:
5v
Data with a 10k resistor Between 5v
N/C
Ground

It seems to work perfectly then just give up

Many thanks

I'm still missing the link to the libraries used (you know that there are more than a half a dozen DHT22 libraries?).

Please provide a diagram (you can draw it by hand) of the complete wiring. From the brief description of the sensor I don't see where the diodes on the relays are, just to give you an example.

How do you drive the relays? An Arduino doesn't provide enough current to drive these relays directly.

The frequent restarting is a bad sign, that shows that probably the power supply isn't accurate for your setup.

What type of Arduino are you using? (I guess an Mega2560)