Go Down

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

pinkfreak

I'm currently working on a project that involves outputting the pH reading in the serial monitor.

Here's the code:
Code: [Select]

int potPin = 0;
float phSense = 0;

void setup()
{
  Serial.begin(9600);
  Serial.println("PH sensor ");
  analogReference(INTERNAL);
}

void printTenths(int value) {
// prints a value of 123 as 12.3
  Serial.print(value / 10);
  Serial.print(".");
  Serial.println(value % 10);
}

void loop() {
  int span = 20;
  int aRead = 0;

  for (int i = 0; i < span; i++) {
    aRead = aRead+analogRead(potPin);
  }

  aRead = aRead / 20;
  phSense = ((0.0592*1.1*aRead)/1024)*10;
  // convert voltage to pH
  Serial.print("Analog in reading: ");
  Serial.print(long(aRead));
  // print pH value on serial monitor
  Serial.print(" - Calculated pH Level: ");
  printTenths(long(phSense));
  delay(500);
}

btw, I got this code from a book and modified it a little

As for the pins connection to arduino, I've directly connected pin 2 to GND, pin 5 to 5V, and pin 6 to A0.

Here's the output from the serial monitor:



As you can see, there is no output. I've checked my connections and nothing's loose or anything. As for the code, it was previously used for displaying temp on the serial monitor but I've modified it for my pH sensor. I'm wondering what's wrong here. Is it the connections or is it the code? Do I need to use other pins of the pH sensor (seeing that I've only used three of them).


For further reference on the probe that I'm using:

  • output: 59.2 mV/pH at 25°C


  • Sensor pinouts (Read BTA-right hand):
    http://www.vernier.com/support/sensor-pinouts/


wildbill

#1
Mar 11, 2012, 01:31 pm Last Edit: Mar 11, 2012, 01:33 pm by wildbill Reason: 1
You have two problems: when you divide by 1024, the compiler will (I think) perform integer division and drop the fractional part. Since the result has only a fractional part, it'll become zero. Use 1024.0 instead. It looks like your cast to long in the print will do the same thing - get rid of it.

johnwasser

You have chosen the INTERNAL (1.1v) reference.  The pH=7 output of the probe is 1.75v so unless you are measuring a high pH you will always get 1023 counts.

According to the user manual (http://www.vernier.com/files/manuals/ph-bta.pdf): "The pH Sensor will produce a voltage of 1.75 volts in a pH 7 buffer. The voltage will increase by about 0.25 volts for every pH number decrease. The voltage will decrease by about 0.25 volts/pH number as the pH increases.

That means that the range of your probe outputs should be 0V (pH 14) to 3.5V (pH 0).  To cover that range you will want a reference voltage of at least 3.5V.  Try setting analogRefrence() to DEFAULT (5V).
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

robtillaart


You must divide by 1023 as that is the max value of the analog read. (effect using 1024 = -0.1%)

Furthermore refactored some code including printing the floating point value as that can be done simpler

including the tips of John wasser

(not tested)
Code: [Select]

int potPin = 0;
float phSense = 0;
float refvoltage = 1.1;

void setup()
{
  Serial.begin(9600);
  Serial.println("PH sensor ");
  analogReference(INTERNAL);
}

void loop()
{
  int samples = 20;
  int aRead = 0; 

  for (int i = 0; i < samples ; i++)
  {
    aRead += analogRead(potPin);
  }
  float voltage = 5.0 * aRead/ (1023 * samples);  // assuming 5V reference
 
  phSense = 14 - voltage/0.25;
 
  // convert voltage to pH
  Serial.print("Analog in reading: ");
  Serial.print(aRead);
 
  // print pH value on serial monitor
  Serial.print(" - Calculated pH Level: ");
  Serial.println(phSense, 1); // 1 = one decimal, 2 = two decimals (default),etc   // removed the /10
  delay(500);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

pinkfreak

Thanks johnwasser and robtillaart. It works perfectly now.

@johnwasser: I was confused which output to use. Thanks for pointing that out.
@robtillaart: thanks for the refactoring! :D although it took me a while to understand it since I'm not well versed with programming but your modification really helped a lot.

Go Up