pH Meter problem

I have a temperature and pH sensor connected to my Arduino Uno Wifi with a Base Shield 2.0. On the Base Shield, there is a switch for 3.3v and 5v. If the switch is towards 3.3v, i will have a normal pH value(Water: about 7.0) but my temperature value will be low as 17Degrees(Suppose to be around 32).
If i switch to 5V on my Base Shield, My pH value will increase up to around 9-10 pH value while my Temperature will be correct. How can i adjust so that i will have both value correct?

This is my Sketch for pH and Temperature:
/*

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;

//Temperature
int a;
float temperature;
int B=3975; // B value of the thermistor
float resistance;

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();
}
//Temperature
a=analogRead(1); // get analog value
resistance=(float)(1023-a)10000/a; // get resistance
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; // calc temperature
delay(1000); // delay 1s
Serial.print("Current Temperature is ");
Serial.println(temperature);
}
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*;*

  • }*
  • 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*<min){_
    _
    amount+=min; //arr<min*_
    _ min=arr*;
    }else {
    if(arr>max){
    amount+=max; //arr>max*

    max=arr*;
    }else{
    amount+=arr; //min<=arr<=max*

    * }
    }//if*

    * }//for*
    * avg = (double)amount/(number-2);
    }//if*

    * return avg;
    }*_

Please edit your post to add code tags ("</>" button).

This line assumes that the voltage reference value is 5V. Is it at all times?

voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;

What is a 'base shield'? what are it's specifications?

without this we can't help.

Allan

/*

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 co
***2mpensate
#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;
const int buzzer = 9;
void setup(void)
{
pinMode(LED,OUTPUT);
pinMode(buzzer, 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);
if(pHValue <=4.0){
digitalWrite(buzzer,HIGH);
delay(1000);
}
if(pHValue >4.0){
digitalWrite(buzzer,LOW);
}
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
;

  • }*
  • 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*<min){_
    _
    amount+=min; //arr<min*_
    _ min=arr*;
    }else {
    if(arr>max){
    amount+=max; //arr>max*

    max=arr*;*_

* }else{*
_ amount+=arr*; //min<=arr<=max*
* }
}//if*

* }//for*
* avg = (double)amount/(number-2);
}//if*

* return avg;
}*_