i'm using a ph sensor (SKU__SEN0161 from dfrobot) and when the ph value should be raising, it is going down. i tried different methods for the voltage to ph conversion and they all gie the same
code:
#include "DFRobot_PH.h"
#include "DFRobot_EC.h"
#include <EEPROM.h>
#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();
//temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
voltage = analogRead(PH_PIN)/1024.0*5000; // read the voltage
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);
}
ph.calibration(voltage,temperature); // calibration process by Serail CMD
}
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
}
Try measuring the voltage directly with a voltmeter (e.g. DMM). This si to establish that the voltage going to your Arduino is doing the right thing (or not).
I'm unsure about the order in which this would be processed. Anyway its not clear.
voltage = (analogRead(PH_PIN)/1024.0) * 5000 - or -
voltage = analogRead(PH_PIN)/(1024.0 * 5000)
I'd suggest
voltage = analogRead(PH_PIN) * 5.0 / 1024.0;
voltage *= 1000; //to get millivolts
and serial print voltage to see what values you are actually reading.
Agree with @johnerrington on the calculation. It's not clear in what order the computation will be carried out. However, it looks like the code is from the DFRobot example for the pH sensor.
@gocaca , You don't say if you've carried out the calibration process. Looking at the library on github, there are values that are stored in EEPROM as part of the cal process.
The output from a conventional pH electrode has a negative slope when you measure millivolts out against pH value.
The output is roughly 60-mV per pH unit.
At pH 7 the output is zero millivolts.
So at pH 0, strong acid, you should get about +0.4 volts, and at pH 14, strong alkali, about -0.4 volts.
To get this into an analogue input, an operational amplifier for high impedance outputs is used.
Ideally, this will follow the electrode output.
Two thing you could do.
Use a DMM and some known acid and alkali solutions to check your modules outputs. Use something like sodium hydroxide and hydrochloric acid. The module should have offset built in to bring the bipolar raw pH electrode output into a range suitable for the board you are using.
Make up a simple voltage divider with a battery.
Check what your Arduino is reading.
I did follow the calibration process with two solution, it does calibrate for the 4 ph solution but when I put the probe in the 7 ph solution the values goes to 1 instead of 7