PH sensor coding

Hi guys, I recently bought a PH sensor from there:
Gravity: Analog pH Sensor / Meter Kit for Arduino - DFRobot.

But the problem is that I am using esp8266 nodeMCU instead of arduino. So I am wondering does anyone here know how do I convert the code the website has given me to be compatible with esp8266 nodeMCU?

the code the website has provided:

/*
 # This sample code is used to test the pH meter V1.0.
 # Editor : YouYou
 # Ver    : 1.0
 # Product: analog pH meter
 # SKU    : SEN0161
*/
#define SensorPin A0            //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00            //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth  40    //times of collection
int pHArray[ArrayLenth];   //Store the average value of the sensor feedback
int pHArrayIndex=0;
void setup(void)
{
  pinMode(LED,OUTPUT);
  Serial.begin(9600);
  Serial.println("pH meter experiment!");    //Test the serial monitor
}
void loop(void)
{
  static unsigned long samplingTime = millis();
  static unsigned long printTime = millis();
  static float pHValue,voltage;
  if(millis()-samplingTime > samplingInterval)
  {
      pHArray[pHArrayIndex++]=analogRead(SensorPin);
      if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
      voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
      pHValue = 3.5*voltage+Offset;
      samplingTime=millis();
  }
  if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
  {
    Serial.print("Voltage:");
        Serial.print(voltage,2);
        Serial.print("    pH value: ");
    Serial.println(pHValue,2);
        digitalWrite(LED,digitalRead(LED)^1);
        printTime=millis();
  }
}
double avergearray(int* arr, int number){
  int i;
  int max,min;
  double avg;
  long amount=0;
  if(number<=0){
    Serial.println("Error number for the array to avraging!/n");
    return 0;
  }
  if(number<5){   //less than 5, calculated directly statistics
    for(i=0;i<number;i++){
      amount+=arr[i];
    }
    avg = amount/number;
    return avg;
  }else{
    if(arr[0]<arr[1]){
      min = arr[0];max=arr[1];
    }
    else{
      min=arr[1];max=arr[0];
    }
    for(i=2;i<number;i++){
      if(arr[i]<min){
        amount+=min;        //arr<min
        min=arr[i];
      }else {
        if(arr[i]>max){
          amount+=max;    //arr>max
          max=arr[i];
        }else{
          amount+=arr[i]; //min<=arr<=max
        }
      }//if
    }//for
    avg = (double)amount/(number-2);
  }//if
  return avg;
}

some extra info:

  1. the "+" of the small board as shown in the website is connected to +5Vdc
  2. the "-" of the small board as shown in the website is connected to ground
  3. the "A" or the output pin of the small board as shown in the website is connected to a voltage divider to achieve 3.0Vdc to 3.3Vdc where is then connected to the "D7" input pin of the esp8266 nodeMCU. "A" means analogue if i am not mistaken

Many thanks in advance ^^

Check what actual readings you get from the sensor in pH=4 and pH=7 buffers, and if you have it also a pH=10 would be great. These numbers should be on one line.

Mind that the analog input is about 0-3.3V for the NodeMCU, I can't find the actual output range of the sensor. You may need a voltage divider here, but mind the voltage divider the NodeMCU has already on the analog input (the ESP8266's analog input has a 0-1V range).

sorry for not replying for so long i was busy with other stuff but anyway is my PH sensor faulty or is the coding issue or could it be using a voltage divider at the output pin of the PH sensor before connecting to the A0 pin of the esp or any other possible reasons as the readings i get is not within an accept range even when i change the offset value.

offset = 2.35
example:

vinegar (ph 2.4) gives me like ph 5.1 to 5.9

water (ph7) gives me Ph 7 to 7.9

soap (ph 9) gives me me like Ph 6 to ph 7

What actual analog readings do you get when measuring buffer solutions? No calculations, just the raw analog input value, with the probe in a buffer.

Plain tap water is typically somewhere around pH 8-10. Can't be used for calibration purposes. Vinegar and soap solutions are likewise unreliable.

I get 729 and 728 when dipping in tap water and 716 and 717 when dipping in the water in a cap that comes with the Ph sensor. Also i dont have any buffer solution with me except the water in a cap that comes with the Ph Sensor with i dont know does that count

Almost certainly not a buffer.

You can probably find buffer solutions at your local aquarium supplies shop.

hmm okay but is my coding look correct?

Calculation looks weird but it's the sample code so should be correct.

The raw analog readings are at this stage the most interesting: what do you really read for a certain known pH value? The probe's response should be linear so when you have two points you can calculate the rest.