Analog.Read and scaling help needed.

Hi Guys,

Im having trouble trying to work out how to scale my input to read correctly.

I have a PH probe circuit which im reading on an analog input.

When the probe is PH7 the voltage from the circuit is 2.00V, when the probe is PH10 the voltage reads 2.50 volts. So i can deduce that the circuit outputs 167mV/PH.

But how do i adjust my code to read from 0PH to 14PH using these 2.00v and 2.50v as my reference???

Here is the code im trying to modify:

int pin = 3;  
int tempc = 0,tempf=0; 
int samples[8]; 
int i;

void setup()
{
Serial.begin(9600); 
}

void loop()
{

    for(i = 0;i<=7;i++)                                             
    {
      samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
      tempc = tempc + samples[i];
    }

    tempc = tempc/8.0;                                  
    tempf = (tempc * 9)/ 5 + 32;                              

   Serial.print("{TEMP:");
   Serial.print(tempf,DEC);
   Serial.print("}");
   


    tempc = 0;

    delay(1000); 
}

Any help rewriting this code would be of great help!!

VR.

Would this help?

Thanks Jezuz,

But im already using the AREF pin on other circuits and the 2 cant be connected. It also doesnt look like the kind of thing i need unfortunately.

Im reading the input from a OP-amp circuit like this:

Thanks for your input though.

VR

It looks like this will be the formula to convert from volts to pH:

volts(pH) = 0.83 + ( 0.167 * pH )

thus

pH(volts) = ( volts - 0.83 ) / 0.167

voltage from analogRead :

volt = (analogRead(pin) / 204)

extend the ph(volts) to
ph(pin) = ( ( analogRead(pin) / 204 ) - 0.83 ) / 0.167

now simply store the results in an array.

[UNTESTED CODE]

int pin = 3;  

int samples[8];
int avg;

void setup()
{
      Serial.begin(9600);
}

void loop()
{

      for(int i=0; i<=7 ;i++)                                            
      {
            samples[i] =  ( ( analogRead(pin) / 204 ) - 0.83 ) / 0.167;
            avg += samples[i];
      }                        

      Serial.print("{TEMP:");
      Serial.print((avg/8),DEC);
      Serial.print("}");

      avg = 0;

      delay(1000);
}