Development

Sensors / Smart Water:

» SW 01: pH Sensor Reading

Turn on the Smart Water Board and reads the pH sensor extracting the value from the calibration values and temperature compensation

Required Materials

1 x Waspmote
1 x Battery
1 x Smart Water Sensor Board
1 x pH Sensor
1 x pH Calibration Kit (for those sensors which require calibration)
1 x PT1000 temperature sensor (for temperature compensation)

Notes

The calibration values selected in the code are an example for a specific sensor, each unit will require its own calibration parameters.
If the sensor has been kept stored for long it may take longer to reach a steady output.
In case calibration or temperature compensation are considered unnecessary function pHConversion can be called without them. Take a look at section “API” of the Smart Water Technical Guide for more information.

Code

/*  
 *  ------ [SW_01] - pH sensor Reading for Smart Water-------- 
 *  
 *  Explanation: Turn on the Smart Water Board and reads the pH sensor
 *  extracting the value from the calibration values and temperature
 *  compensation
 *  
 *  Copyright (C) 2014 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           2.0
 *  Design:            David Gascón 
 *  Implementation:    Ahmad Saad
 */

#include <WaspSensorSW.h>

float value_pH;
float value_temp;
float value_pH_calculated;

// Calibration values
#define cal_point_10 1.985
#define cal_point_7 2.070
#define cal_point_4 2.227

// Temperature at which calibration was carried out
#define cal_temp 23.7

pHClass pHSensor;
pt1000Class temperatureSensor;

void setup()
{
  pHSensor.setCalibrationPoints(cal_point_10, cal_point_7, cal_point_4, cal_temp);
  
  // Turn ON the Smart Water sensor board and start the USB
  SensorSW.ON();  
  USB.ON();
}


void loop()
{
  // Read the ph sensor
  value_pH = pHSensor.readpH();

  // Read the temperature sensor
  value_temp = temperatureSensor.readTemperature();

  // Print the output values
  USB.print(F("pH value: "));
  USB.print(value_pH);
  USB.print(F("volts  | "));  
  USB.print(F(" temperature: "));
  USB.print(value_temp);
  USB.print(F("degrees  | "));  
  
  // Convert the value read with the information obtained in calibration
  value_pH_calculated = pHSensor.pHConversion(value_pH,value_temp);
  USB.print(F(" pH Estimated: "));
  USB.println(value_pH_calculated);
}


Output

D#
pH value: 2.2510616779volts | temperature: 20.3847656250degrees | pH Estimated: 3.8090739250
pH value: 2.2498335838volts | temperature: 20.4285888671degrees | pH Estimated: 3.8315755844
pH value: 2.2496614456volts | temperature: 20.4486083984degrees | pH Estimated: 3.8348851203
pH value: 2.2493996620volts | temperature: 20.4590148925degrees | pH Estimated: 3.8396921157
pH value: 2.2490675449volts | temperature: 20.4725646972degrees | pH Estimated: 3.8457942008
...

Quick Publish: