Problem with calibration of pH sensor
alucard0987654321 2020-08-16 19:52:23 5161 Views7 Replies I followed the instructions here exactly. https://wiki.dfrobot.com/Gravity__Analo ... 2#target_4
But when I hit enter in the serial monitor NOTHING at all happens. Can I get some help?
But when I hit enter in the serial monitor NOTHING at all happens. Can I get some help?
2021-04-07 16:42:08 I am having the same issue. I copied the code exactly. When I enter "enterph" it responds appropriately, but when I enter "calph" it says Buffer solution error. Before I run the calibration, the pH for the 7.0 solution is shown as 2.55. Not between 6.7 and 7.3. Maybe this is why it cannot automatically detect which buffer solution I am using. How can I correct this?
mmeldefo
mmeldefo 2020-09-07 18:50:16 Did you use the correct ph buffer solution? The 4.0 or 7.0 buffer solution are correct.
Please use the 7.0 buffer solution first. Before the calibration, the ph value on the serial monitor should be between 6.7~7.3.
How is your ph value before the calibration?
Youyou
Please use the 7.0 buffer solution first. Before the calibration, the ph value on the serial monitor should be between 6.7~7.3.
How is your ph value before the calibration?
Youyou 2020-09-04 20:01:52 I try enterph, it works, but when I enter calph, it says Buffer solution error
lehoang96
lehoang96 2020-08-24 22:58:41 The correct commads are show as below:
1.enterph;
2.calph;
3.exitph;
Please try them again.
Youyou
1.enterph;
2.calph;
3.exitph;
Please try them again.
Youyou 2020-08-19 08:57:02 The blue wire of the pH sensor is attached to pin A0 on the Arduino.
The red wire of the pH sensor is attached to pin 5V on the Arduino.
The black wire of the pH sensor is attached to pin Ground on the Arduino.
I have copy and pasted my code below. My code also includes a DFRobot TDS sensor.
/*
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](https://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 A0
float voltage, phValue, temperature = 25;
DFRobot_PH ph;
#define TdsSensorPin A1
#define VREF 5.0 // analog reference voltage(Volt) of the ADC
#define SCOUNT 30 // sum of sample point
int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0, copyIndex = 0;
float averageVoltage = 0, tdsValue = 0, temperature1 = 25;
void setup()
{
Serial.begin(115200);
ph.begin();
pinMode(TdsSensorPin, INPUT);
}
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
static unsigned long analogSampleTimepoint = millis();
if (millis() - analogSampleTimepoint > 40U) //every 40 milliseconds,read the analog value from the ADC
{
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); //read the analog value and store into the buffer
analogBufferIndex++;
if (analogBufferIndex == SCOUNT)
analogBufferIndex = 0;
}
static unsigned long printTimepoint = millis();
if (millis() - printTimepoint > 800U)
{
printTimepoint = millis();
for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++)
analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
averageVoltage = getMedianNum(analogBufferTemp, SCOUNT) * (float)VREF / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
float compensationCoefficient = 1.0 + 0.02 * (temperature1 - 25.0); //temperature1 compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
float compensationVolatge = averageVoltage / compensationCoefficient; //temperature1 compensation
tdsValue = (133.42 * compensationVolatge * compensationVolatge * compensationVolatge - 255.86 * compensationVolatge * compensationVolatge + 857.39 * compensationVolatge) * 0.5; //convert voltage value to tds value
//Serial.print("voltage:");
//Serial.print(averageVoltage,2);
//Serial.print("V ");
Serial.print("TDS Value:");
Serial.print(tdsValue, 0);
Serial.println("ppm");
}
}
int getMedianNum(int bArray[], int iFilterLen)
{
int bTab[iFilterLen];
for (byte i = 0; i < iFilterLen; i++)
bTab = bArray;
int i, j, bTemp;
for (j = 0; j < iFilterLen - 1; j++)
{
for (i = 0; i < iFilterLen - j - 1; i++)
{
if (bTab > bTab[i + 1])
{
bTemp = bTab;
bTab = bTab[i + 1];
bTab[i + 1] = bTemp;
}
}
}
if ((iFilterLen & 1) > 0)
bTemp = bTab[(iFilterLen - 1) / 2];
else
bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
return bTemp;
}
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
}
/***************************************************
DFRobot Gravity: Analog TDS Sensor / Meter For Arduino
<https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0244>
Created 2017-8-22
By Jason <[email protected]@dfrobot.com>
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
/***********Notice and Trouble shooting***************
1. This code is tested on Arduino Uno and Leonardo with Arduino IDE 1.0.5 r2 and 1.8.2.
2. More details, please click this link: <https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0244>
****************************************************/
alucard0987654321
The red wire of the pH sensor is attached to pin 5V on the Arduino.
The black wire of the pH sensor is attached to pin Ground on the Arduino.
I have copy and pasted my code below. My code also includes a DFRobot TDS sensor.
/*
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](https://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 A0
float voltage, phValue, temperature = 25;
DFRobot_PH ph;
#define TdsSensorPin A1
#define VREF 5.0 // analog reference voltage(Volt) of the ADC
#define SCOUNT 30 // sum of sample point
int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0, copyIndex = 0;
float averageVoltage = 0, tdsValue = 0, temperature1 = 25;
void setup()
{
Serial.begin(115200);
ph.begin();
pinMode(TdsSensorPin, INPUT);
}
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
static unsigned long analogSampleTimepoint = millis();
if (millis() - analogSampleTimepoint > 40U) //every 40 milliseconds,read the analog value from the ADC
{
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); //read the analog value and store into the buffer
analogBufferIndex++;
if (analogBufferIndex == SCOUNT)
analogBufferIndex = 0;
}
static unsigned long printTimepoint = millis();
if (millis() - printTimepoint > 800U)
{
printTimepoint = millis();
for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++)
analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
averageVoltage = getMedianNum(analogBufferTemp, SCOUNT) * (float)VREF / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
float compensationCoefficient = 1.0 + 0.02 * (temperature1 - 25.0); //temperature1 compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
float compensationVolatge = averageVoltage / compensationCoefficient; //temperature1 compensation
tdsValue = (133.42 * compensationVolatge * compensationVolatge * compensationVolatge - 255.86 * compensationVolatge * compensationVolatge + 857.39 * compensationVolatge) * 0.5; //convert voltage value to tds value
//Serial.print("voltage:");
//Serial.print(averageVoltage,2);
//Serial.print("V ");
Serial.print("TDS Value:");
Serial.print(tdsValue, 0);
Serial.println("ppm");
}
}
int getMedianNum(int bArray[], int iFilterLen)
{
int bTab[iFilterLen];
for (byte i = 0; i < iFilterLen; i++)
bTab = bArray;
int i, j, bTemp;
for (j = 0; j < iFilterLen - 1; j++)
{
for (i = 0; i < iFilterLen - j - 1; i++)
{
if (bTab > bTab[i + 1])
{
bTemp = bTab;
bTab = bTab[i + 1];
bTab[i + 1] = bTemp;
}
}
}
if ((iFilterLen & 1) > 0)
bTemp = bTab[(iFilterLen - 1) / 2];
else
bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
return bTemp;
}
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
}
/***************************************************
DFRobot Gravity: Analog TDS Sensor / Meter For Arduino
<https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0244>
Created 2017-8-22
By Jason <[email protected]@dfrobot.com>
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
/***********Notice and Trouble shooting***************
1. This code is tested on Arduino Uno and Leonardo with Arduino IDE 1.0.5 r2 and 1.8.2.
2. More details, please click this link: <https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0244>
****************************************************/
alucard0987654321 
