LCD fails when loop function does for loops and uses buffers

I;ve worked with LCDs before (16x2) and i have been able to get many things written onto the lcd but when using this particular code for a pH meter, the top line shows up sort of dark but I can see the data being printed on the first row and re-written constantly. But its barely visible. Why is this particular code causing this problem (Im using pin 13 as a contrast rather than using a pot). The wiring is correct because I can load many other sketches and the LCD works perfectly:

#include <LiquidCrystal.h> // includes the LiquidCrystal Library

int Contrast = 20;

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

const int analogInPin = A0; 
int sensorValue = 0; 
unsigned long int avgValue; 
float b;
int buf[10],temp;
void setup() {
 Serial.begin(9600);
 Serial.println("Hi");

 analogWrite(13,Contrast);
 lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
}
 
void loop() {
 for(int i=0;i<10;i++) { 
  buf[i]=analogRead(analogInPin);
  delay(10);
 }

 for(int i=0;i<9;i++){
  for(int j=i+1;j<10;j++){
   if(buf[i]>buf[j]){
    temp=buf[i];
    buf[i]=buf[j];
    buf[j]=temp;
   }
  }
 }
 
 avgValue=0;
 for(int i=2;i<8;i++)
 avgValue+=buf[i];
 float pHVol=(float)avgValue*5.0/1024/6;
 float phValue = -5.70 * pHVol + 21.34;
   printToLCD();

 delay(200);
}

void printToLCD() {
 lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
 lcd.print("Kombucha pH "); // Prints string "Distance" on the LCD
 lcd.print(3.33); // Prints string "Distance" on the LCD
 //lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
 //lcd.print("IPA Beer pH:"); // Prints string "Distance" on the LCD
 //lcd.print(phValue+2); // Prints string "Distance" on the LCD

}

Marciokoko:
(Im using pin 13 as a contrast rather than using a pot).

How exactly is that supposed to work?

Not sure but it works. I've used it in many of my sketches so I know that's not the issue.

Marciokoko:
. . .

. . .

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

. . .




. . .

You are using Arduino pin 1 for your LCD but the IDE uses this pin for the Serial Monitor connection. You should select a different pin for RS in order to avoid this conflict.

Don

True but so do all my other sketches. But I'll disable any serial. commands

You may disable the serial commands in your program but the boot loader is also using the serial connections.

If you insist on using pin 1 (or pin 0) for your LCD or anything else then you really should disconnect those devices while downloading your program code.

Don

Got it working don. Thanks. I commented out the serial lines.

Marciokoko:
Not sure but it works. I've used it in many of my sketches so I know that's not the issue.

Actually, you could get the same effect with a 120 Ohm resistor connected from pin 3 to ground and don't waste the Arduino pin.