LCD goes blank but code keeps running.

Hi All,

I have made a setup to control my terrarium which has a humidifier and heater connected to replays & LCD to display the humidity and temperature. I also have programmed in the average humidity & temperature to be displayed.

After its been running overnight theLCD screen goes blank but everything else seems to be running fine - the code continues to run.

Can any one shed some light on why this might happen?

#include <LiquidCrystal.h>
#include "DHT.h"

#define DHTPIN 6    // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
#define heaterpin 8
#define fanpin 9
#define humpin 10
#define arrsize 40
DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  float h;
  float t;
  int avgTemp;
  int avgHum;
  int timespass = 360;
  int tempArr[arrsize];
  int humArr[arrsize];
  int arrFill;
  int hum;
  int temp;

void setup() {

  Serial.begin(9600); 
  dht.begin(); /// start temp sensor etc
  pinMode(heaterpin, OUTPUT);   
  pinMode(fanpin, OUTPUT);   
  pinMode(humpin, OUTPUT);
  lcd.begin(16, 2); 

}


void loop() {  
  
  
  h = dht.readHumidity();
  t = dht.readTemperature();
  
  hum = h;
  temp = t;
  
  checkHumidity(hum);
  checkTemp(temp);

  writeToArray();
  doAverages();
  
  writeToLCD();
  delay(5000);
  
}

void writeToArray(){
  
  timespass = timespass + 1;
  
  if(timespass > 360){   //720
    arrFill = arrFill + 1;
     if(arrFill = (arrsize)){
       arrFill = 1;
     }   
     

     humArr[arrFill] = hum;
     tempArr[arrFill] = temp;
     timespass = 0;
  } 
  
  
  
}

void doAverages(){

  avgTemp = 0;
  avgHum = 0;
  for(int x = 0; x <= arrFill; x = x + 1){
    
    avgTemp = avgTemp + tempArr[x];
    avgHum = avgHum + humArr[x];
    
  }
  
  avgTemp = avgTemp / arrFill;
  avgHum = avgHum / arrFill;
  
}

void writeToLCD(){
    
    lcd.setCursor(0, 1); 

    if(digitalRead(heaterpin) == LOW){
      lcd.print("T:On");
    }else{
      lcd.print("T:Off");
    }
    
    if(digitalRead(humpin) == LOW){
      lcd.print(" H:On");
    }else{
      lcd.print(" H:Off");
    }
      
    if(digitalRead(fanpin) ==LOW){
      lcd.print(" F:Off");
    }else{
      lcd.print(" F:On");
    }
  
  lcd.setCursor(0, 0);  
  lcd.print(temp);
  lcd.print("c");
  lcd.print(" ");
  lcd.print(hum);
  lcd.print("%  "); 
  lcd.print(avgTemp);
  lcd.print("c");
  lcd.print(" ");
  lcd.print(avgHum);
  lcd.print("%");
  
}

void checkHumidity(int hum1){
  
  if(hum1 < 92){
    digitalWrite(humpin,LOW); 
    digitalWrite(fanpin,LOW);  
  }else if(hum1 > 86){
    digitalWrite(humpin,HIGH);
    digitalWrite(fanpin,HIGH); 
  }
   
}

void checkTemp(int temp1){
  
  if(temp1 < 24){
    digitalWrite(heaterpin,LOW);  
  }else if(temp1 > 27){
    digitalWrite(heaterpin,HIGH);    
  }
  
}

I don’t have the hardware to really test this, but this statement:

     if(arrFill = (arrsize)){

is an assignment statement, not a logical test, so arrFill is set to 40. However, the next statement sets it equal to 1. This is because your assignment statement evaluates to logic True. I would put some print statements in, like:

void doAverages(){

  avgTemp = 0;
  avgHum = 0;
  for(int x = 0; x <= arrFill; x = x + 1){
    
    avgTemp = avgTemp + tempArr[x];
    avgHum = avgHum + humArr[x];
Serial.print)"i  = ");
Serial.print(i);    
Serial.print)"   avgTemp = ");
Serial.println(avgTemp );    
Serial.print)"   avgHum = ");
Serial.println(avgHum);    
  }
  
  avgTemp = avgTemp / arrFill;
  avgHum = avgHum / arrFill;
  
}

to make sure you are marching through all elements of the array.

How did i miss that! I will try it, thanks.

Any problems I have had with LCD screen are usually down to my wiring.

Its not the wiring because it works fine for a while and then goes kaput after a while

Lewisgmorris: it works fine for a while and then goes kaput after a while

From that you can not conclude

Its not the wiring because

Intermittent connections, or poor soldered joints could still cause you problems.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Tom..... :)