PH-4502 sensor help

Hi,

Try this code, there is a for statement that didn't look right.

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

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;
  Serial.print("sensor = ");
  Serial.println(phValue);
  delay(20);
}

If you move you mouse up to the top right hand corner of the code window you will see a "copy" icon appear, left click and that will copy it , then paste it into the IDE.

See if that runs.
Can you please post an image of your code please, so we can see your component layout.

Have you got a DMM to measure the voltage at A0?

Thanks Tom... :grinning: :+1: :coffee: :australia:

1 Like