Average Value for pH sensor reading

Hi, I am doing my project but im having slight difficulties. When I put the code in Arduino the value becomes zero.
Im using a pH sesnor from Inesa Scientific Instrument (E-201-C) and a peristaltic pump from DFRobot. The board that im using is Arduino UNO.

This is the code that i use that was giving me zero as the pH value

#include <Servo.h>

Servo acid_solution;
Servo alkaline_solution;

#define acid_pump 9
#define alkaline_pump 10

float calibration_value = 10.97;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10], temp;

float value1,
      value2,
      value3,
      value4,
      value5,
      main_value;

float ph_value;

void setup()
{
  Serial.begin(9600);
  pinMode(A0, INPUT);
  acid_solution.attach(acid_pump);
  alkaline_solution.attach(alkaline_pump);
}
void loop() {


  Serial.println(ph_value);
  getting_value();
  value1 = ph_value;
  delay(300);
  getting_value();
  value2 = ph_value;
  delay(300);
  getting_value();
  value3 = ph_value;
  delay(300);
  getting_value();
  value4 = ph_value;
  delay(300);
  getting_value();
  value5 = ph_value;
  main_value = (value1 + value2 + value3 + value4 + value5) / 5;

  if (main_value > 6.5)
  {
    acid_solution.write(0); //Clockwise maximum speed rotation
  }
  else
  {
    acid_solution.write(90);
  }
  if (main_value < 5.5)
  {
    alkaline_solution.write(0);
  }
  else
  {
    alkaline_solution.write(90);
  }
}
void getting_value()
{
  for (int i = 0; i < 10; i++)
  {
    buffer_arr[i] = analogRead(A0);
    delay(30);
  }
  for (int i = 0; i < 9; i++)
  {
    for (int j = i + 1; j < 10; j++)
    {
      if (buffer_arr[i] > buffer_arr[j])
      {
        temp = buffer_arr[i];
        buffer_arr[i] = buffer_arr[j];
        buffer_arr[j] = temp;
      }
    }
  }
  avgval = 0;
  for (int i = 2; i < 8; i++)
    avgval += buffer_arr[i];
  float volt = (float)avgval * 5.0 / 1024 / 6;
  float ph_value = -5.70 * volt + calibration_value;
}

please help me in this. Thank you

How about putting some serial prints in the above function so you can 'see' what's going wrong?

Please edit your post and enclose your code in code tags.

Please type CTRL-T in the Arduino editor to format your code properly, and edit your post to add code tags.

At least one of your problems is the use of the keyword "float" in the line below, which defines a local variable named "ph_value", which is not visible outside of the function named getting_value().

  float ph_value = -5.70 * volt + calibration_value;

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.