DFRobot pH meter with LCD Shield Code problem

Hey everyone,

I have been working on making a hydroponic controller and i’m just starting out simple, mainly because i’m new to coding in general.

I have added the sample code from DFRobots pH sensor, and have tried to make it so that the pH code is in its own function so that its easier to call the function when ever i need to use it.

I have a LCD keypad shield connected to it at the moment and have some of the code it, but i have commented it out at the moment to just run on the serial port.

The problem i’m getting is that the code is complying and uploading to my UNO, but it comes up as reading the pH value as 0.00 and the delay isn’t even working. so i’m missing something in my code somewhere. Hope someone can help. i’m sure its just a small problem.

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 

#define SensorPin A1           	//pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00            	//deviation compensate
#define samplingInterval 20
#define printInterval 1000
#define ArrayLength  40    		//times of collection

int pHArray[ArrayLength];   	//Store the average value of the sensor feedback
int pHArrayIndex = 0;

unsigned long samplingTime;
unsigned long printTime;   
void setup()
	samplingTime = millis();
	printTime = millis();

void loop()
  double Calcph;
	//int input = getKeyPress();
    if((millis() - samplingTime) > samplingInterval)
		Calcph = Calcph;
		samplingTime = millis();
	if((millis() - printTime) > printInterval);   //Every 1000 milliseconds, print a numerical, convert the state of the LED indicator
		/*switch (input) {
			case (0):
			case (1):
		Serial.print("    pH value: ");
		printTime = millis();
	//if this overloads the ardunio add a pause equal to the highest frequency sample

double Calcph()
  double result;
	static float pHValue, voltage;

	pHArray[pHArrayIndex++] = analogRead(SensorPin); //adds new value to the pH array
		pHArrayIndex=0;	//if this is the first value, index is 0.
	voltage = avergearray(pHArray, ArrayLength)*5.0/1024;
	pHValue = 3.5*voltage+Offset;

double avergearray(int* arr, int number){
  int i;
  int max,min;
  double avg;
  long amount=0;
		Serial.println("Error number for the array to avraging!/n");
		return 0;
  if(number<5){   //less than 5, calculated directly statistics
	avg = amount/number;
    return avg;
  } else {
		min = arr[0];max=arr[1];
			amount+=min;        //arr<min
		}else {
				amount+=max;    //arr>max
			amount+=arr[i]; //min<=arr<=max
	avg = (double)amount/(number-2);
  return avg;

Calcph = Calcph;

Now that's what I call a useless line of code. What are you trying to accomplish with this? Set the value to what it already was?

Or were you meaning to put some parenthesis behind that second one and call the function you named the same as your variable? Could you really not think of two unique names for these? You shouldn't give the same name to two different things.

Awesome thanks for your help, it was so helpful.