LCD Turns off after few seconds

Hi, my LCD back light will turn off after few seconds after reboot but only with a certain program.
here is the following program that is causing the problems.

const int critical = -3; //critcal plant freezing temp in degree C
const int led = 10; //soleniod relay
float wetbulb = 0;
#include "DHT.h"
#include <LiquidCrystal.h>

#define DHTPIN 2    // what digital pin we're connected to


#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
byte temp[8] =             //icon for thermometer
{
  B00100,
  B01011,
  B01010,
  B01111,
  B01110,
  B11111,
  B11111,
  B01110
};

byte drop[8] =             //icon for water droplet
{
  B00100,
  B00100,
  B01110,
  B01110,
  B11111,
  B11111,
  B11111,
  B01110,
};
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

byte bcdToDec(byte val)
{
  return ( (val / 16 * 10) + (val % 16) );
}






void setup() {
  Serial.begin(9600);
  Serial.println("DHT22 test!");
  pinMode(led, OUTPUT);
  dht.begin();
  lcd.createChar(1, temp);       // create a new character labeled 1
  lcd.createChar(2, drop);      // create a new character labeled 2
  lcd.begin(16, 2);         // set up the LCD's number of columns and rows
  lcd.display();
}

void loop() {

  // 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 t = dht.readTemperature();

  wetbulb = (t * atan(.151977 * pow(h + 8.313659, 0.5))) + atan(t + h) - atan(h - 1.676331) + (.391838 * pow(h, 2 / 3)) * atan(.023101 * h) - 4.686035;
  if (wetbulb <= critical) {
    digitalWrite (led, HIGH);   //wetbulb below critical trips led
  }
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(" ");
    Serial.print(t);
    Serial.println(" *C");
    Serial.print(" ");

    Serial.print("Wetbulb");
    Serial.print(" ");
    Serial.print(wetbulb);
    Serial.print("*C");
    Serial.print(" ");
    Serial.print("Freeze");
    Serial.print(" ");
    Serial.print(critical);
    Serial.print("*C");
    Serial.print(" ");

    lcd.setCursor (0, 0);
    lcd.print("Wetbulb");
    lcd.print(" ");
    lcd.print(wetbulb);
    lcd.print((char)223); // Prints degrees symbol
    lcd.print("C");


    delay (1000);
  }
}

The only thing I can suggest is to change your delay to 2 seconds. My DHT's require around 2 seconds between reads.

Only other suggestion is to start commenting out LCD writes until you find the problem.

The LCD backlight is completely independent of the rest of the setup, sharing only the power supply. If your program code is affecting the backlight it is probably doing so as a result of somehow affecting the current required by the supply.

I see that this comment ( [color=blue]const int led = 10; //soleniod relay[/color] ) mentions a solenoid and a relay. How much current does that solenoid and/or relay require?

Does your pc board include a series current limiting resistor for the backlight LED(s)? If not, have you added an external resistor?

Don

where it says solenoid relay thats just because i have used many scripts and modified to work. so there is nothing attached to pin 10

I asked two questions and got only one answer.

Don

50% strike rate - not too bad on this forum. :grinning:

it is going to be running a led. i would not have a clue its juts a uno board

It would be useful if you were to give us a perfectly zoomed and focussed, full daylight photo of the rear of your LCD board, not the UNO, to see whether it has the necessary current controlling resistor for the backlight LED.

I will however prognosticate that it has a resistor "R8" with the numbers "101" on it, indicating a 100 Ohm resistor. It may also have a resistor "R9" with "0" on it or just possibly, the two may be exchanged. In either case, if this resistor value is present, the answer as to whether it has the LED current control resistor is "yes".

As a matter of fact, a perfectly focussed, full daylight photo or photos of your whole assembly would be useful to assess if there is any other evident cause of your problem. This applies in all cases of questions here! :grinning: