DFRobot Gravity Analog pH sensor kit V2: Unable to calibrate

Hi,

I’m trying to calibrate my pH sensor with buffer solutions and use the exact same wiring and calibration code from DFRobot. I’m using Arduino Uno Board with sensor V2 module

[https://github.com/DFRobot/DFRobotMediaWikiMarkDown/wiki/Gravity__Analog_pH_Sensor_Meter_Kit_V2_SKU_SEN0161-V2]

However, the serial monitor prints pH: nan or sometimes pH: inf

Can anyone help me resolve this issue? Cheers

Are you able to post a photo of your setup and copy and paste your code here. Nan or inf usually mean that there is a maths error somewhere or a division by zero.

1 Like

This is my setup. I use Arduino 2560 for this one. My connection as below:

Arduino MEGA BNC Board
5v -> 5v
GND -> GND
A1 -> A

I use the code from github which provided by DFRobot:

/*
 * file DFRobot_PH.ino
 * @ https://github.com/DFRobot/DFRobot_PH
 *
 * This is the sample code for Gravity: Analog pH Sensor / Meter Kit V2, SKU:SEN0161-V2
 * In order to guarantee precision, a temperature sensor such as DS18B20 is needed, to execute automatic temperature compensation.
 * You can send commands in the serial monitor to execute the calibration.
 * Serial Commands:
 *   enter -> enter the calibration mode
 *   cal -> calibrate with the standard buffer solution, two buffer solutions(4.0 and 7.0) will be automaticlly recognized
 *   exit -> save the calibrated parameters and exit from calibration mode
 *
 * Copyright   [DFRobot](http://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-04
 */

#include "DFRobot_PH.h"
#include <EEPROM.h>

#define PH_PIN A1
float voltage,phValue,temperature = 25;
DFRobot_PH ph;

void setup()
{
  Serial.begin(115200);
  ph.begin();
}

void loop()
{
    static unsigned long timepoint = millis();
    if(millis()-timepoint>1000U)  //time interval: 1s
    {
      timepoint = millis();
      voltage = analogRead(PH_PIN)/1024.0*5000;  // read the voltage
      //temperature = readTemperature();  // read your temperature sensor to execute temperature compensation
      phValue = ph.readPH(voltage,temperature);  // convert voltage to pH with temperature compensation
      Serial.print("temperature:");
      Serial.print(temperature,1);
      Serial.print("^C  pH:");
      Serial.println(phValue,2);
    }
    ph.calibration(voltage,temperature);  // calibration process by Serail CMD
}

float readTemperature()
{
  //add your code here to get the temperature from your temperature sensor
}

Could you try changing the sensor to A2 and updating the Code so that PH_PIN A2, and see if this has any effect. Did you copy this code from your sketch or from DFR as if you did the latter we may have missed something.

I know this is an old thread, but I had exactly the same problem today. After looking at the library code, I changed the way the calibration values are stored in EEPROM. Here is the new code:

void DFRobot_PH::begin()
{
    if (EEPROM.get(PHVALUEADDR, this->_neutralVoltage) == 0) {
        this->_neutralVoltage = 1500.0;  // new EEPROM, write typical voltage
        EEPROM.put(PHVALUEADDR, this->_neutralVoltage);
    };

    Serial.print("_neutralVoltage:");
    Serial.println(this->_neutralVoltage);

    if (EEPROM.get(PHVALUEADDR+4, this->_acidVoltage) == 0) {
        this->_acidVoltage = 2032.44;  // new EEPROM, write typical voltage
        EEPROM.put(PHVALUEADDR+4, this->_acidVoltage);
    };
    
    Serial.print("_acidVoltage:");
    Serial.println(this->_acidVoltage);

}

If you want to try it, just comment out the existing function definition and paste this version into the file instead.

Enjoy!

1 Like

Hello Brian,
I too have this nan inf problem. And would like to try your solution,

Which part of existing function defniition should i replace with yours? Thanks

1 Like

Hi Tien

You should be able to comment out all of the function void DFRobot_PH::begin() and use the above code instead.

1 Like

Excellent!
Just did that and looking good. Thanks heaps mate.
image

1 Like

A post was merged into an existing topic: Gravity: Analog Electrical Conductivity Sensor /Meter V2 (K=1) (DFR0300)