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.