PH probe

From Reef Projects

Jump to: navigation, search

PH Probe

  • I got a PH Probe from BRS and used the schematic from PH wiki powered by two 9V batteries like the schematic at this site.
  • Basically, the PH probe creates a very small voltage. The circuit is used to amplify that voltage to something useful. The Arduino reads the voltage and converts it to an integer between 0 and 1023. That then can be converted into the apropriate PH.
  • With a PH of 7 set to 2V and a PH of 10 set to 1V, this yield the equation "PH = -3 * Voltage + 13
  • For the Arduino we find that the product of integer read from the analog pin and .0049 gives the voltage read.
  • Combining these, and writing the equations so they will work with integer math and still be accurate we get "ph_val = (-1.47 * analogRead(pin) + 1300);
  • I added some analog smoothing found on the Arduino forum.

Code:


#define NUMREADINGS 10
int readings[NUMREADINGS];		    // the readings from the analog input
int index = 0;				    // the index of the current reading
int total = 0;				    // the running total
int average = 0;				  // the average

void setup(void) {
  for (int i = 0; i < NUMREADINGS; i++)
    readings[i] = 0;  
}

void loop(void){

int ph_read, ph_val;

  // To calibrate ph probe set 7ph to 2V and 10PH to 1V
  
  total -= readings[index];		   // subtract the last reading
  readings[index] = analogRead(ph_probe); // read from the sensor
  total += readings[index];		   // add the reading to the total
  index = (index + 1);			  // advance to the next index

  if (index >= NUMREADINGS)		   // if we're at the end of the array...
    index = 0;				    // ...wrap around to the beginning

  average = total / NUMREADINGS;	    // calculate the average
  
    ph_val = (-1.47 * average + 1300);  //ph is stored 100 times value
  
    Whole = (ph_val / 100);  // separate off the whole and fractional portions
    Fract = (ph_val % 100);
    
    lcd.position(3,12);
    lcd.println("PH ");
     if (Whole < 10){
     lcd.println(" ");
     }
    lcd.println(itoa(Whole, buf, 10));
    lcd.println(".");
    if (Fract < 10){
     lcd.println("0");
     }
    lcd.println(itoa(Fract, buf, 10));

}

Personal tools