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);
}
}