Hey,
I am using a BNC shield to display the pH values from a pH probe; however, I keep getting a reading of 7 or 8 when I put the probe into a pH 10 solution. I used the config video on BNC shields but am still getting this reading of 7 or 8 rather than 10 for pH 10 solution. I think the problem is somewhere with the pH gain.
The code I am using is:
// change this to whatever pin you've moved the jumper to
int ph_pin = 5;
//int for the averaged reading
int reading;
//int for conversion to millivolts
int millivolts;
//float for the ph value
float ph_value;
int i;
// highly recommended that you hook everything up and check the arduino's voltage with a multimeter.
// It doesn't make that much of a difference, but
// if you want it to be highly accurate than do this step #define ARDUINO_VOLTAGE 5.0
// PH_GAIN is (4000mv / (59.2 * 7)) // 4000mv is max output and 59.2 * 7 is the maximum range (in millivolts) for the ph probe. #define PH_GAIN 9.6525
void setup() {
Serial.begin(9600);
}
void loop() {
//take a sample of 50 readings
reading = 0;
for(i = 0; i < 50; i++) {
reading += analogRead(ph_pin);
delay(10);
}
//average it out
reading /= i;
//convert to millivolts. remember for higher accuracy measure your arduino's
//voltage with a multimeter and change ARDUINO_VOLTAGE
millivolts = ((reading * ARDUINO_VOLTAGE) / 1024) * 1000;
ph_value = ((millivolts / PH_GAIN) / 59.2) + 7;
Serial.print("pH= ");
Serial.println(ph_value);
delay(500);
}
Please modify you post, select the code block and press the # button just a bove the smileys. Then it will be tagged as code and will be more readable.
There are some problems with the averaging because you use int. Overflow as you can have 50 samples of 1023 and truncating averaging.
try this
int ph_pin = 5;
float reading;
float millivolts;
float ph_value;
int i;
#define ARDUINO_VOLTAGE 5.0
// PH_GAIN == (4000mv / (59.2 * 7)) --> 4000mv is max output and 59.2 * 7 is the maximum range (in millivolts) for the ph probe.
#define PH_GAIN 9.6525
void setup()
{
Serial.begin(9600);
}
void loop()
{
reading = 0;
for(i = 0; i < 50; i++)
{
reading += analogRead(ph_pin);
delay(10);
}
reading /= i;
millivolts = reading * ARDUINO_VOLTAGE / 1.024;
ph_value = ((millivolts / PH_GAIN) / 59.2) + 7; // << fails?
// should the + be * ? or should it be ph_value = millivolts/PH_GAIN;
// the formula above looks too different
// or consider using the map function, if there is linear behaviour
// ph_value = map(millivolts, 0, 4000, 100, 1600) / 100.0;
Serial.print("pH= ");
Serial.println(ph_value, 2); // 2 decimals
delay(500);
}
I got it to work using the same code.
When I adjust the trim to pH 7 (0 mV) and switch to the pH 10 solution; my shield reads 9.79
When I adjust the trim to pH 10 (1.7 V) and switch to the pH 7 solution; my shield reads 7.38
How can I fix this?
int ph_pin = 5;
float reading;
float millivolts;
float ph_value;
int i;
#define ARDUINO_VOLTAGE 5.0
// PH_GAIN == (4000mv / (59.2 * 7)) --> 4000mv is max output and 59.2 * 7 is the maximum range (in millivolts) for the ph probe.
#define PH_GAIN 9.6525
void setup()
{
Serial.begin(9600);
}
void loop()
{
reading = 0;
for(i = 0; i < 50; i++)
{
reading += analogRead(ph_pin);
delay(10);
}
reading /= i;
millivolts = reading * ARDUINO_VOLTAGE / 1.024;
ph_value = ((millivolts / PH_GAIN) / 59.2) + 7; // << fails?
// should the + be * ? or should it be ph_value = millivolts/PH_GAIN;
// the formula above looks too different
// or consider using the map function, if there is linear behaviour
//ph_value = map(millivolts, 0, 4000, 100, 1600) / 100.0;
Serial.print("pH= ");
Serial.println(ph_value, 2); // 2 decimals
delay(500);
}