LCD Displays Trash

Hi everyone new to arduino having program issuses I dont understand I know nothing about C++ coding
when I try to set pinmode it displays trash on LCD I have a arduino mega 2560 R3 and a 16X2 LCD my goal is to set timealarms and menus with 5 button analog input using 1 input please help what am I doing wrong banging my head on wall thanks

#include <Time.h>  
#include <Wire.h>
#include <dht11.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
#include <stdlib.h>
#include <Time.h>
#include <TimeAlarms.h>

/*-----( Declare objects )-----*/
dht11 DHT11;

/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 6
#define PH1 2
#define PH2 3
#define co2sens 4
const int light1pin = 22;
const int light2pin = 23;
const int pump1pin =  24;
const int pump2pin =  25;
const int foggerpin = 26;
const int exfanpin =  27;
const int fanpin =    28;
const int heaterpin = 29;
const int coolerpin = 30;
const int waterheater1pin = 31;
const int waterheater2pin = 32;
const int watercooler1pin =  33;
const int watercooler2pin =  34;
const int phdoser1pin = 35;
const int phdoser2pin = 36;
const int co2pin = 37;



 Variables will change:
int light1 = HIGH;
int light2 = LOW;
int pump1 = LOW;
int pump2 = LOW;
int fogger = LOW;
int exfan = LOW;
int fan = LOW;
int heater = LOW;
int cooler = LOW;
int waterheater1 = LOW;
int waterheater2 = LOW;
int watercooler1 = LOW;
int watercooler2 = LOW;
int phdoser1 = LOW;
int phdoser2 = LOW;
int co2 = LOW;

// define some values used by the panel and buttons
int key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in < 50)   return btnRIGHT; 
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 555)  return btnLEFT;
  if (adc_key_in < 790)  return btnSELECT;  
  return btnNONE;  // when all others fail, return this...
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()  {
  
  Serial.begin(9600);
  // set up the LCD's number of columns and rows 
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  // Print a message to the LCD.
  Serial.println("System Starting");
  lcd.print("     System     ");
  lcd.setCursor(0, 1);
  lcd.print("    Starting    ");
  delay(2000);
  Serial.println("Dyslexic's Hydroponic Controller Ver 0.1");
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   Dyslexic's   ");
  lcd.setCursor(0,1);
  lcd.print("   Hydroponic   ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   Controller   ");
  lcd.setCursor(0,1);
  lcd.print("    Ver 0.1     ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();

// set the digital pin as output:PROBLEM HERE THE PROBLEM STARTS WHEN ADD ANY OF THE PIN MODE LINES OUTPUT TRASH TO DISPLAY
  
  pinMode(PH1, INPUT);
  pinMode(PH2, INPUT);
  pinMode(light1, OUTPUT);
  pinMode(light2, OUTPUT);
  pinMode(pump1, OUTPUT);
  pinMode(pump2, OUTPUT);
  pinMode(fogger, OUTPUT);
  pinMode(exfan, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(heater, OUTPUT);
  pinMode(cooler, OUTPUT);
  pinMode(waterheater1, OUTPUT);
  pinMode(waterheater2, OUTPUT);
  pinMode(watercooler1, OUTPUT);
  pinMode(watercooler2, OUTPUT);
  pinMode(phdoser1, OUTPUT);
  pinMode(phdoser1, OUTPUT);
  
  //sync clock
  setSyncProvider(RTC.get); //function to get the time from the RTC
  if(timeStatus()!=timeSet){
    Serial.println("Unable to sync with the RTC");
    lcd.print("TIME NOT SET");
  }
  else{
    Serial.println("RTC has set the system time");
    lcd.print("    TIME SET    ");
  }      
}

void loop()
{
  int chk = DHT11.read(DHT11PIN);

  lcd.setCursor(0, 1);
  Serial.print("Read sensor:");
  lcd.print("Read sensor:");
  
  switch (chk)
  {
  case 0: 
    Serial.println("OK");
    lcd.print("OK");
    break;
  case -1: 
    Serial.println("Checksum error");
   lcd.print("Checksum error"); 
    break;
  case -2: 
    Serial.println("Time out error");
   lcd.print("Time out error"); 
    break;
  default: 
    Serial.println("Unknown error"); 
    lcd.print("Unknown error");
    break;
    lcd.clear();
  }

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);
  lcd.setCursor(0, 1);
  lcd.print(" ");
  lcd.print((float)DHT11.temperature, 0);
  lcd.print((char)223); // degree symbol 
  lcd.print("C ");

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);
  lcd.print(Fahrenheit(DHT11.temperature), 0);
  lcd.print((char)223); // degree symbol 
  lcd.print("F ");
  
  
  lcd.print((float)DHT11.humidity, 0);
  lcd.print("%");
  lcd.print("H");
  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);


  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

 
  digitalClockDisplay();  
  delay(1000);
}

void digitalClockDisplay(){
  lcd.setCursor(0, 0);
  // digital clock display of the time
  Serial.print(hour());
  lcd.print(hour());
  printDigits(minute());
  //printDigits(second());
  lcd.print(" ");
  Serial.print(" ");
  lcd.print(month());
  Serial.print(month());
  lcd.print("/");
  Serial.print("/");
  Serial.print(day());
  lcd.print(day());
  lcd.print("/");
  Serial.print("/");
  Serial.print(year());
  lcd.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  lcd.print(":");
  if(digits < 10)
    //Serial.print('0');
  lcd.print('0');
  Serial.print(digits);
  lcd.print(digits);




}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
  double A0= 373.15/(273.15 + celsius);
  double SUM = -7.90298 * (A0-1);
  SUM += 5.02808 * log10(A0);
  SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  SUM += log10(1013.246);
  double VP = pow(10, SUM-3) * humidity;
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  double Td = (b * temp) / (a - temp);
  return Td;
}

/* ( THE END ) */

I think that the first thing that you should do is to get a simple message on the LCD with none of the complications of buttons and sensors.

Have you looked at the example LiquidCrystal sketches in the IDE ? 'Hello World' would be a good one to start with. It will enable you to test your wiring assuming that you have a compatible LCD display.

There are a number of pinMode commands in your original code that set pins to output. Have you tried each one individually to see which of them cause the corruption ?

Which pins are you using for these outputs ?

  pinMode(light1, OUTPUT);
  pinMode(light2, OUTPUT);
  pinMode(pump1, OUTPUT);
  pinMode(pump2, OUTPUT);
  pinMode(fogger, OUTPUT);
  pinMode(exfan, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(heater, OUTPUT);
  pinMode(cooler, OUTPUT);
  pinMode(waterheater1, OUTPUT);
  pinMode(waterheater2, OUTPUT);
  pinMode(watercooler1, OUTPUT);
  pinMode(watercooler2, OUTPUT);
  pinMode(phdoser1, OUTPUT);
  pinMode(phdoser1, OUTPUT);

The variable names declared don't quite match those used in the pinMode statements. Have you copied and pasted from 2 slightly different versions of the sketch ?

const int light1pin = 22;
const int light2pin = 23;
const int pump1pin =  24;
const int pump2pin =  25;
const int foggerpin = 26;
const int exfanpin =  27;
const int fanpin =    28;
const int heaterpin = 29;
const int coolerpin = 30;
const int waterheater1pin = 31;
const int waterheater2pin = 32;
const int watercooler1pin =  33;
const int watercooler2pin =  34;
const int phdoser1pin = 35;
const int phdoser2pin = 36;
const int co2pin = 37;

Which Arduino board are you using ?

I Have the Arduino Mega 2560 R3 not sure if I copied from 2 sketch could have cause I started over when the display started showing trash please post what you see wrong thanks

by commenting this lines out I now can turn outputs on and off so I take it you dont need this lines // Variables will change:
//int light1 = HIGH;
//int light2 = LOW;
//int pump1 = LOW;
//int pump2 = LOW;
//int fogger = LOW;
//int exfan = LOW;
//int fan = LOW;
//int heater = LOW;
//int cooler = LOW;
//int waterheater1 = LOW;
//int waterheater2 = LOW;
//int watercooler1 = LOW;
//int watercooler2 = LOW;
//int phdoser1 = LOW;
//int phdoser2 = LOW;
//int co2 = LOW;

#include <Time.h>  
#include <Wire.h>
#include <dht11.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
#include <stdlib.h>
#include <Time.h>
#include <TimeAlarms.h>

/*-----( Declare objects )-----*/
dht11 DHT11;

/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 6

#define PH2 3
#define co2sens 4
const int light1 = 22;
const int light2 = 23;
const int pump1 =  24;
const int pump2 =  25;
const int fogger = 26;
const int exfan =  27;
const int fan =    28;
const int heater = 29;
const int cooler = 30;
const int waterheater1 = 31;
const int waterheater2 = 32;
const int watercooler1 =  33;
const int watercooler2 =  34;
const int phdoser1 = 35;
const int phdoser2 = 36;
const int co2 = 37;



// Variables will change:
//int light1 = HIGH;
//int light2 = LOW;
//int pump1 = LOW;
//int pump2 = LOW;
//int fogger = LOW;
//int exfan = LOW;
//int fan = LOW;
//int heater = LOW;
//int cooler = LOW;
//int waterheater1 = LOW;
//int waterheater2 = LOW;
//int watercooler1 = LOW;
//int watercooler2 = LOW;
//int phdoser1 = LOW;
//int phdoser2 = LOW;
//int co2 = LOW;

// define some values used by the panel and buttons
int key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in < 50)   return btnRIGHT; 
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 555)  return btnLEFT;
  if (adc_key_in < 790)  return btnSELECT;  
  return btnNONE;  // when all others fail, return this...
}

// change this to whatever pin you&#39;ve moved the jumper to 
int ph1_pin = 2; 
//int for the averaged reading
int reading; 
//int for conversion to millivolts 
int millivolts; 
//float for the ph value 
float ph_value; 
int i; 
// highly recommended that you hook everything up and check the arduino&#39;s voltage with a multimeter.
// It doesn&#39;t make that much of a difference, but 
// if you want it to be highly accurate than do this step
#define ARDUINO_VOLTAGE 5.0 
// PH_GAIN is (4000mv / (59.2 * 7)) // 4000mv is max output and 59.2 * 7 is the maximum range (in millivolts) for the ph probe. 
#define PH_GAIN 9.6525 

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()  {

  // set the digital pin as output:
  pinMode(light1, OUTPUT);
  pinMode(light2, OUTPUT);
  pinMode(pump1, OUTPUT);
  pinMode(pump2, OUTPUT);
  pinMode(fogger, OUTPUT);
  pinMode(exfan, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(heater, OUTPUT);
  pinMode(cooler, OUTPUT);
  pinMode(waterheater1, OUTPUT);
  pinMode(waterheater2, OUTPUT);
  pinMode(watercooler1, OUTPUT);
  pinMode(watercooler2, OUTPUT);
  pinMode(phdoser1, OUTPUT);
  pinMode(phdoser1, OUTPUT);
  pinMode(co2, OUTPUT);

  Serial.begin(9600);
  // set up the LCD's number of columns and rows 
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  // Print a message to the LCD.
  Serial.println("System Starting");
  lcd.print("     System     ");
  lcd.setCursor(0, 1);
  lcd.print("    Starting    ");
  delay(2000);
  Serial.println("Dyslexic's Hydroponic Controller Ver 0.1");
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   Dyslexic's   ");
  lcd.setCursor(0,1);
  lcd.print("   Hydroponic   ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   Controller   ");
  lcd.setCursor(0,1);
  lcd.print("    Ver 0.1     ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();

  //sync clock
  setSyncProvider(RTC.get); //function to get the time from the RTC
  if(timeStatus()!=timeSet){
    Serial.println("Unable to sync with the RTC");
    lcd.print("TIME NOT SET");
  }
  else{
    Serial.println("RTC has set the system time");
    lcd.print("    TIME SET    ");
  }      
}

void loop()
{ 
  //digitalWrite(light1, HIGH);
  //take a sample of 50 readings 
  reading = 0; 
  for(i = 1; i < 50; i++) { 
    reading += analogRead(ph1_pin); 
    delay(10); 
  } 
  //average it out 
  reading /= i; 
  //convert to millivolts. remember for higher accuracy measure your arduino&#39;s 
  //voltage with a multimeter and change ARDUINO_VOLTAGE 
  millivolts = ((reading * ARDUINO_VOLTAGE) / 1024) * 1000; 
  ph_value = ((millivolts / PH_GAIN) / 59.2) + 7; 
  Serial.print("pH= "); 
  Serial.println(ph_value); 
  delay(500); 

  int chk = DHT11.read(DHT11PIN);

  lcd.setCursor(0, 1);
  Serial.print("Read sensor:");
  lcd.print("Read sensor:");

  switch (chk)
  {
  case 0: 
    Serial.println("OK");
    lcd.print("OK");
    break;
  case -1: 
    Serial.println("Checksum error");
    lcd.print("Checksum error"); 
    break;
  case -2: 
    Serial.println("Time out error");
    lcd.print("Time out error"); 
    break;
  default: 
    Serial.println("Unknown error"); 
    lcd.print("Unknown error");
    break;
    lcd.clear();
  }

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);
  lcd.setCursor(0, 1);
  lcd.print(" ");
  lcd.print((float)DHT11.temperature, 0);
  lcd.print((char)223); // degree symbol 
  lcd.print("C ");

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);
  lcd.print(Fahrenheit(DHT11.temperature), 0);
  lcd.print((char)223); // degree symbol 
  lcd.print("F ");


  lcd.print((float)DHT11.humidity, 0);
  lcd.print("%");
  lcd.print("H");
  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);


  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));


  digitalClockDisplay();  
  delay(1000);
}

void digitalClockDisplay(){
  lcd.setCursor(0, 0);
  // digital clock display of the time
  Serial.print(hour());
  lcd.print(hour());
  printDigits(minute());
  //printDigits(second());
  lcd.print(" ");
  Serial.print(" ");
  lcd.print(month());
  Serial.print(month());
  lcd.print("/");
  Serial.print("/");
  Serial.print(day());
  lcd.print(day());
  lcd.print("/");
  Serial.print("/");
  Serial.print(year());
  lcd.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  lcd.print(":");
  if(digits < 10)
    //Serial.print('0');
    lcd.print('0');
  Serial.print(digits);
  lcd.print(digits);




}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
  double A0= 373.15/(273.15 + celsius);
  double SUM = -7.90298 * (A0-1);
  SUM += 5.02808 * log10(A0);
  SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  SUM += log10(1013.246);
  double VP = pow(10, SUM-3) * humidity;
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  double Td = (b * temp) / (a - temp);
  return Td;
}

/* ( THE END ) */