Go Down

### Topic: Interfacing pH probe (Read 1 time)previous topic - next topic

#### wick

##### Dec 02, 2009, 03:01 pm
I am working on a project where I am trying to measure PH then, activate one of two pumps based on that reading for hydroponic gardening.

Thus far, I have managed to locate a an old pHmeter and amplifier that uses a 5 in din connector. I also located the pinouts for the sensor and its spec sheet:
Pinouts:
http://www.vernier.com/probes/specs/pinout.html
Data Sheet:
http://www2.vernier.com/booklets/ph-bta.pdf

I have also wired it up to the Arduino Duemilanove using the example a combination of two of the example codes.

Code: [Select]
`// include the library code:#include <LiquidCrystal.h>// initialize the library with the numbers of the interface pinsLiquidCrystal lcd(12, 11, 5, 4, 3, 2);int sensorPin = 0;    // select the input pin for the potentiometerint sensorValue = 0;  // variable to store the value coming from the sensorvoid setup() {  // set up the LCD's number of rows and columns:  lcd.begin(16, 2);  // Print a message to the LCD.  lcd.print("pH Value");}void loop() {  // set the cursor to column 0, line 1  // (note: line 1 is the second row, since counting begins with 0):  lcd.setCursor(0, 1);  // read the value from the sensor:  sensorValue = analogRead(sensorPin);      // print the number of seconds since reset:  lcd.print(sensorValue);  }`

The results are:
In a PH Buffer Solution of 10.00 -

150

In a PH Buffer Solution of 7.00

300

In a PH Buffer Solution of 4.00

450

What are these numbers???

Also, I have multiplied the values by adding in *7/3 after the pirnt sensor value so that line looks like:  lcd.print(sensorValue*7/3);
This results in displaying the pH using a three or four digit number where the first is the ph followed by the two decimal places, unless the ph is above 9.  However, it displays these numbers counting the wrong way.  If the ph is 4, it reads 10. If the ph is 10, it reads 4.

My goal would be to display the ph with the decimal in the correct place and read in the standard format. Any ideas?

#### PaulS

#1
##### Dec 02, 2009, 03:19 pmLast Edit: Dec 02, 2009, 03:19 pm by PaulS Reason: 1
Quote
What are these numbers???

The sensor converted the pH value to a voltage. The Arduino compared that voltage to VRef (usually +5V), and scaled it to a range of 0 to 1023. It is that scaled value that analogRead returns.

Quote
lcd.print(sensorValue*7/3);

The sensorValue is an int, so sensorValue*7/3 is performing all integer arithmetic. The value is multiplied by 7, then divided by 3, returning the integer amount, that lcd.print then prints.

If you want to use floating point arithmetic, you need to do this:

lcd.print((float)sensorValue*7.0/3.0);

However, sensorValue is not pH, so scaling it up is not going to give you a meaningful result. The sensorValue reading is a function of pH. If you want actual pH values displayed, you'll need to create a function that reverses how the sensor converts pH to voltage, and apply that function.

#### wick

#2
##### Dec 02, 2009, 03:24 pm
Quote
However, sensorValue is not pH, so scaling it up is not going to give you a meaningful result. The sensorValue reading is a function of pH. If you want actual pH values displayed, you'll need to create a function that reverses how the sensor converts pH to voltage, and apply that function.

As I am very new to all things electronic, what would be the steps involved in accomplishing this task?

#### MikMo

#3
##### Dec 02, 2009, 07:51 pm
From the datasheet it looks like the probe is putting out 59.2 mV/pH at 25°C.

So you should never get more than 828,8 mV at pH 14.

Each of the "steps" returned from analogread represents 4,88 mV (5V/1024)  if your Arduino is running at 5V

So you can make a function that translates the analogRead value to pH.

To get a better measuring you could change the reference voltage for Arduinos ADC to a lover voltage. you can google for info.

#### jpgr87

#4
##### Dec 03, 2009, 04:03 pm
According to the "How the pH sensor works" section of the datasheet, the meter should return about 1.75 volts at pH 7, and every time the pH increases by 1, the output decreases by 0.25 volts (inversely proportional.)  That means that the readings should be

pH 10: 1.75V - (0.25V * 3) = 1.0V; (1.0V/5.0V) * 1024 = 204.8
pH 7: (1.75V / 5.0V)  * 1024 = 358.4
pH 4: 1.75V + (0.25V * 3) = 2.5V; (2.5V/5.0V) * 1024 = 512

Your observed readings are pretty close to these theoretical readings, which means your sensor is probably working correctly.  The observed readings may be off due to factors like old age, sensor deterioration, and calibration.  If you're confident in your measurements and your calibration solutions, you can use those to scale your pH readings.

It seems like your pH readings are changing by 50 for each pH increment, and following the trend, the reading at pH 0 will probably be 650.  Also, every time your pH increases, your value decreases, which we'd like to change.

Code: [Select]
`float sensorValue = analogRead(sensorPin);float pH = (650.0 - sensorValue) / 50.0;`

First you find how far your value is from 650 (which we're taking to be 0 pH).  Then you divide by the scaling factor (50 units per pH increment).  This pH value is stored in a float now, so lcd.print should work properly.  If not then you can do something like

Code: [Select]
`lcd.print( (int)pH);lcd.print(".");lcd.print(  (int) ((pH - (int)pH) * 100));`

This prints out the integer value of your value, a decimal point, and then subtracts the integer value from the decimal value leaving only the decimal places, scales the decimal by 100 (two decimal places), and prints those decimal places after your decimal point.

Go Up

Please enter a valid email to subscribe