ph sensor library

Dependents:   595_Project2_Hydro

phread.cpp

Committer:
thecreid1
Date:
2020-05-06
Revision:
0:973b5707f517

File content as of revision 0:973b5707f517:

#include "phread.h"

PHread::PHread (PinName data_pin) : 
    _datapin (data_pin)
{}

float PHread::get_pH(){
  float mv_voltage = 0;
  float ph_val=0;

    
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    mv_voltage += (_datapin.read() * 3.1); 
    wait_ms(10);
  }
  mv_voltage /= 10;
  
  //formuala to convert from voltage signal to ph
  //from atlasScientific
  ph_val = (-5.6548 * mv_voltage) + 15.509; 
  
  
  
    return ph_val;
}