Saturday, July 12, 2014

Measuring PH with Dormant Labs PH Module V2 Using 10 & 7 calibration solutions

Here is another setup guide that shows how to measure PH using the Dormant Labs PH Module V2, except this time we will calibrate using 10 & 7 ph calibration solutions.

You will need

  • 10 ph calibration solution
  • 7 ph calibration solution
  • Dormant Labs PH Module V2
  • A PH probe
  • 4 dupont female to male cables
  • An Arduino
  • Containers to hold the PH calibration solutions, and a container to rinse the ph probe with water.

Fill one cup with 10 PH calibration solution, one cup with 7 ph calibration solution, and one cup with water.



Connect the ph probe to the module.



Connect the module SDA,SCL pins to the Arduino SCL and SDA pins, here because we are using a mega, the SCL is pin 21, and SDA is pin 20. Then connect VCC to 5v on the arduino mega, and then connect GND to the GND pin on the arduino mega.

Then connect the arduino mega to your computer.

Now we will upload the source code. Get the source code from here:

and upload it using the Arduino IDE, if you do not have the arduino IDE then get it from the arduino site.


After uploading the code, open the serial monitor and you should see something like this:



It will output the wrong reading until we calibrate it, so lets do that.

First rinse off the ph probe in the tap water.


Now dip it in the PH 7 calibration solution, and write down the value for avgPhVolts that comes up in the serial monitor.




Now rinse it again.




Now dip it in the PH 10 calibration solution and write down the value for avgPhVolts in the serial monitor.



Also write down the avgRoomTempC value that appears in the serial monitor.

Here are the values that I got:




Now enter them for the values of volt7, volt10, and calibrationTempC and upload.



You now have calibrated your ph sensor! Edit the program to do whatever you want now.

46 comments:

  1. What is the advantage of calibrating at 7 and 10 vs 4 and 7? If it just the likely test solution range?

    Anthony

    ReplyDelete
  2. Hello there is no advantage of calibrating with 7&10 vs 4&7. This is because the ph probe response is very very linear. However some people are still losing sleep over it and emailing me about it so I made this tut.

    ReplyDelete
  3. Do you have a sketch for use after calibration? I would just like to print to my lcd/serial the measured PH of water.
    Carl

    ReplyDelete
    Replies
    1. When you calibrate, you are hardcoding the voltages that you calibrated with, so you can use the 'calibrated sketch' for further use.

      Delete
  4. Hi if I need to have 2 ph meters on 1 arduino mega is it possible?

    ReplyDelete
    Replies
    1. It is, but you will have to use an i2c multiplexer and then modify the code to use it.

      Delete
    2. Where i can find an i2c multiplexer? Can you help me? Thank you

      Delete
    3. Right now you probably have to assemble one.
      Here are some ideas:
      http://bf-arduinolab.wikidot.com/blog:8
      http://www.kerrywong.com/2012/10/08/i2c-multiplexer-shield-testing/
      http://forum.arduino.cc/index.php/topic,110115.0.html

      You might be able to do it in software:
      http://www.reddit.com/r/arduino/comments/1ewi10/how_can_you_connect_two_hmc5883l_magnetometers_to/


      Delete
  5. hello / salam,

    1) Please post a comparision between yours and others (milwakee, atlas scientific, phidget 1130 sensor, hanna instrument, cheaply available ph meter) and post the result here

    2) Please do the test as per
    A) Out of the Box
    B) After calibration

    3) What are major difference between yours and phidget 1130 sensor / atlas scientific (leaving cost)

    4) Does this device work out of the box (no calibration needed)

    5) How often do we need to calibrate this thing

    6) Mostly people calibrate their devices with 3 solutions namely 4.xx 7.xx and 10.xx but yours only 2 so ca we add functionalty for 3 calibration storage ? do you have the arduino code for that ? if not can you make and upload one ?

    7) Don't you think it will be better to add this commanly used thing to the device

    a) Water temp
    b) Room temp (i think you already have that)
    c) Humdity
    d) TDS / EC meter (Yah baby)
    e) orp / DO etc ETC

    this will be so so awesome than...
    Please release a seprate version and name is Hydro Controller or water ever you prefer
    There is so much market for this

    A) Aquarium
    B) POND
    C) hydroponics
    d) aquaponis
    e) any ponics
    f) water analysis and many more

    I am very impressed by what you did

    ReplyDelete
    Replies
    1. Hello, thanks for the compliments!

      1) I do not have the resources to do this, but if someone volunteers I could provide them with a ph module.
      2) The ph module needs to always be calibrated before use, so these tests arent really relevant.
      3) The phidgets from what I see only works with a phidgets board, and I do not know about the atlas scientific, besides that it doesnt have galvanic isolation last I checked.
      4) It will work but the readings it puts out will most likely be wrong if you do not calibrate.
      5) If you are working with water, then probably once a year. It depends on what your ph probe is exposed to.
      6) You can add it, but it makes such an insignificant improvement vs two point calibration.
      7)
      a)No, because people take this module and use it as a piece in their system, and since they are all using it for a different purpose, there isnt an one size fits all approach unfortunately.

      Delete
    2. Thank you for the answers.

      More questions

      1) Do you think if we use it 24/7 than in that case when should we calibrate ?
      2) Why the Documentation page (on tindie) diverts to 2014/4 blog entry rather than redirecting to this (2014/07) page ?
      3) On which basis the Ph is compensated ? water temp or room temp ? and i also heared that sometime water temp is important ? can you please elaborate because it is so confusing suppose my temp is 30 deg c (room) and my water temp is 28deg c (reserviour) than what should be used as calculation or the Anrduino automatically does that for you ?

      4) I have 4.xxx and 6.xxx (calibration solution) will it work for calibration this device?
      5) There is an ic which does the Multiplexing of I2C on UNO so you can attach multiple i2c connection over it. Have to got any other idea for doing it (simple one)?
      6) Can you suggest pH probe (CHEAP ONE)...

      Delete
    3. Sorry so many mistake in the post here is the correction ...
      1) Can we use this device 24/7 if yes than how often should we need to calibrate it?
      2) Why the Documentation page (on tindie) diverts to 2014/4 blog entry rather than redirecting to this (2014/07) page ?
      3) I heared that sometime water temp is important (i know you use room temp for compensate) ? can you please elaborate because it is so confusing suppose my temp is 30 deg c (room) and my water temp is 28deg c (reserviour) than what should be used as calculation or does the Anrduino automatically does that for you (due to source code)?

      4) I have 4.xxx and 6.xxx (calibration solution) will it work for calibrating this device?
      5) There is an ic which does the Multiplexing of I2C on UNO so you can attach multiple i2c connection over it. Do you got any other idea for doing it (simple way maybe)?
      6) Can you suggest pH probe (CHEAP ONE)...

      One more question i can't help it

      7)Is it necessary to provide Precise Voltage to arduino so that this device give perfect reading ? if suppose it is on battery and giving 4.5v will it output wrong pH reading ?

      Delete
    4. Hello,

      1) It depends on the solution you are measuring, something closer to tap water you would have to calibrate maybe once a year, but if you are measuring say sewage then you would calibrate maybe once a week.

      2)The documentation page on tindie I checked, it goes to this documentation page, https://www.tindie.com/products/rezahussain/dormant-labs-ph-module-v2/

      3) In that case you would hardcode the temp compensation to 28c. If you knew your water temp was constant

      4) It will work but you will have to alter the code, you should use 4 & 7 or 7&10 because I have tested and verified that code.

      5) I plan to address this issue in v3 of the module if I end up making it, but in v2 this is all you can do.

      6) Any of the ones off of ebay are good, they should be around 30$.

      7) No, the ph module works internally off of 3.3v, and communicates with the arduino via i2c so no signal will be lost but your arduino may function erratically from 4.5v

      Delete
  6. Just purchased your product from tindie Order #18267.. I hope it will be as it is projected.

    Important note : on tindie the documention link leads to the v1 post of your blog... it didn;t lead me here...Please correct it..

    ReplyDelete
  7. Any update on below questions ?

    1) Can we use this device 24/7 if yes than how often should we need to calibrate it?
    2) Why the Documentation page (on tindie) diverts to 2014/4 blog entry rather than redirecting to this (2014/07) page ?
    3) I heared that sometime water temp is important (i know you use room temp for compensate) ? can you please elaborate because it is so confusing suppose my temp is 30 deg c (room) and my water temp is 28deg c (reserviour) than what should be used as calculation or does the Anrduino automatically does that for you (due to source code)?

    4) I have 4.xxx and 6.xxx (calibration solution) will it work for calibrating this device?
    5) There is an ic which does the Multiplexing of I2C on UNO so you can attach multiple i2c connection over it. Do you got any other idea for doing it (simple way maybe)?
    6) Can you suggest pH probe (CHEAP ONE)...

    One more question i can't help it

    7)Is it necessary to provide Precise Voltage to arduino so that this device give perfect reading ? if suppose it is on battery and giving 4.5v will it output wrong pH reading ?

    ReplyDelete
  8. Hello BilluBhai - I purchased a board a few months ago. I am measuring PH of pool water and adding acid when needed. I started with a PH probe siliconed in with a thermistor with it. I did not do a good job of this and it leaked. I now went with a ph probe holder screwed into the pool pvc. and changed the temperatire to just be adjusted by reading voltage drop across a variable resistor. In my case this works fine for a couple of reasons, the pool does not move that fast for a pool with thousands of gallons and for most of the season the temp in the pool is between 20 and 32 degrees C and PH nead 7. At these temps, ph error is not much because I am near 25 deg C.

    Anthony

    ReplyDelete
    Replies
    1. I didn't get what you want to explain here ?
      Are you saying that you use water temp in place of air temp ? am i right ?
      sorry my mistake please explain the point..

      Delete
  9. Good morning from Barcelona (Spain).
     
    First sorry for my English
     
    I bought two PH V2 MODULE; sending to Spain was fast and arrived in perfect condition.
     
    I have two probes ph an Atlas Scientific (expensive) and a Ebay probe(very cheap, € 10) , and to calibrate the module, the values of volt7, volt10 and volt4 are always the same as your example, volt7 = 0.6700 , volt10 = 0.3500 and volt4 = 0.9500.
     
    Is it normal ?.

    ReplyDelete
    Replies
    1. En el monitor serial debes mirar la cifra que varia cuando metes y sacas la sonda del liquido, no las cifras que permanecen estáticas y coinciden con lo que el autor prefijo en el codigo, (0,6700 para ph7), esta cifra debes sustituirla en la variable vol7 por la que lees en el monitor donde pone avgPHVolts, que es la medida real de voltaje, lo mismo para ph4 y 10, metes la sonda en los distintos buffers y anotas la medida de avgPHVolts, esas medidas las sustituyes en el código por las que vienen asignadas a las variables, estas son unas referencias iniciales que se deben cambiar tras la calibración

      Delete
  10. Te contesto en castellano porque mi ingles es muy malo y seguro que me entiendes mejor.
    Compré el mismo modulo y funciona de maravilla.

    ReplyDelete
  11. Gracias compañero.

    Vaya fallo tan tonto.

    El sensor funciona de lujo.

    Saludos

    ReplyDelete
  12. Hello Reza - I hope this is still an active blog. I have a a question about the code you liked above. Specifically around temp compensation. I see the following and do not understand why you are sending the value 10 to the subroutine?

    tempAdjusted10 = adjustPHBasedOnTemp(10,calibrationTempC);

    That will always give you the same number since the sub formula is:

    float adjustPHBasedOnTemp(float PH, float temp)
    float phDifference = abs(PH-7);

    Shouldn't the ph difference be from what I measure, not what I calibrated to? In this case the phDifference is always 3.

    What am I missing?

    Anthony

    ReplyDelete
  13. Hello Anthony,

    No problem, I can explain, yes this is intentional.

    In the linked code temp compensation is done in both the calibration step and the measuring step.

    You can see the temp compensation on the measuring step on lines 42,and 43:

    double roomTempC = getRoomTemperatureC();
    double roomTempCompensatedMeasuredPH = adjustPHBasedOnTemp(measuredPH,roomTempC);

    Now I'll explain why temp compensation has to be done at the calibration step. In the calibration step we are establishing how many volts the ph probe puts out per ph unit. In this case we are using 7 and 10 calibration solutions.

    Now, temperature doesn't affect the ph when the ph is 7. But temperature does affect every ph measurement that has an absolute distance away from 7 that isn't zero.

    For every measurement that is not ph 7, temp compensation needs to be done to find out what the actual ph is.
    10PH at 25C is 10PH, but step away from 25C, lets say 15C.

    from line 91:
    float phAdjust = (0.03*phDifference)*(tempDifferenceC/10);
    = 0.03*3*(10/10)
    = 0.09

    So at 25C your 10PH calibration solution is 10, but at 15C your 10PH calibration solution is actually 10.09PH.

    This directly affects the slope of the ph per volts calculation. Obviously this will affect the measurements.

    Does that make it clear? I can elaborate.

    Thanks,
    Reza





    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Does this code make sense to you? I run your code above for calibration and then this is a subset of code I am using to an acid pump.

    Thank you,

    Anthony

    int x;
    for(x=0;x< sampleSize;x++)
    {
    double phVolt = getPHVolts();
    tempAdjusted10 = adjustPHBasedOnTemp(10,calibrationTempC);
    double voltsPerPH = abs((volt10-volt7) / (tempAdjusted10-7));
    double realPHVolt = (volt7 - phVolt);
    double phUnits = realPHVolt / voltsPerPH;
    double measuredPH = 7 + phUnits;

    // read the input on analog pin 2 from potentiometer for temperature calc:
    int sensorValue = analogRead(A2);
    // tempdial ranges 0 to 1023 and convert to temperature range 0 to 16.5 deg cel;
    float tempdial = sensorValue * (16.5 / 1023.0);

    // Add base temp to potentiometer temp
    double roomTempC = (tempdial)+16.5;
    double roomTempCompensatedMeasuredPH = adjustPHBasedOnTemp(measuredPH,roomTempC);
    avgMeasuredPH+=measuredPH;
    avgRoomTemperatureCompensatedMeasuredPH+=roomTempCompensatedMeasuredPH;
    avgRoomTempC+=roomTempC;
    avgPHVolts += phVolt;
    }

    avgMeasuredPH/=sampleSize;
    avgRoomTemperatureCompensatedMeasuredPH/=sampleSize;
    avgRoomTempC/=sampleSize;
    avgPHVolts/=sampleSize;
    avgRoomTempF = (avgRoomTempC * 9 / 5) + 32;

    ReplyDelete
  16. Hello Anthony,

    Yes it makes sense except for the part where you do your calculations for roomTempC, but if that evaluates to the temperature of your solution, then this program is correct.

    ReplyDelete
  17. Thank you for the info. Yes, I use a pot to adjust for the temp. The temp is pool water and it is almost always different than the ambient air and since it takes a lot to move it I can adjust it once a week or so. I can go a min of about 60 deg f and a max of 90 deg f with it set like i have it now. I tried a thermister but had problems with it leaking.

    Thanks again.

    Anthony

    ReplyDelete
  18. Hello Reza - I recently replaced my ph probe and recalibrated using 10 and 7 solution. It is measuring a swimming pool's ph. this pool has a salt water chlorine generator. With this system, the ph can only go up without the addition of acid. we do not have acid rain and really not much rain period. over the last week the probe shows me lower and lower readings. the calibration voltages are as follows: volt 7=1.0964 volt10= 0.8208 calibration temp = 26. operating solution temp = 32. I was thinking this weekend titrating the pool water and seeing water the voltage is on the meter and then adding acid and do it again and maybe again and then graph this to extrpolate to 7 and 10 ph and put those numbers in the system. my titrating will not be real accurate because it is just color shades. The range I need to operate in is only 7.5 to 7.8. I am also thinking I have a bad probe. any thoughts? Here is my full code:

    https://plus.google.com/116899926187170667783/posts/GhA9Tm6joGz

    Thanks for any thoughts,

    Anthony

    ReplyDelete
  19. Hello Reza - Any thoughts? Anthony

    ReplyDelete
    Replies
    1. Sorry for the late reply, I was moving this weekend.

      1) do a test with the pool water in a glass, and let me know what happens.

      The drift in voltage is very likely caused by a shift in the power supply of the unisolated portion of the measuring circuit. If the drift happens in the pool but not in the glass, then the second test is to test the pool with the chlorine generator turned off or disconnected.

      It's my suspicion that the chlorine generator is leaking current into the pool which is disturbing the unisolated power supply through the ph probe. But lets see if I am correct first.

      Best Regards,

      Delete
  20. Wow, I would never have gone there. I am out of town all week. I will do this when I am back. Thank you, Anthony

    ReplyDelete
  21. okay, ran the tests this morning. here are the results. i think the avePHVolts are changing in the right direction

    Probe and System Status aveMeasuredPH avgPhVolts
    no pump, no swg, probe in plumbing 6.49
    std 10, probe in hand, no pump, no swq 8.96 0.9166
    std 7, probe in hand, no pump, no swq 5.97 1.19
    std 4.03, probe in hand, no pump, no swq 2.61 1.5
    probe in hand, pool water 6.74 1.12
    probe in plumbing, pump on, no swg 6.63 1.1312
    probe in plumbing, pump on, swg on 6.62 1.1318
    probe in plumbing, no pump, no swg 6.6808 1.1258


    any thoughts would not be appreciated.

    anthony

    ReplyDelete
    Replies
    1. Hello Anthony,

      Those numbers suggest a bad probe.

      probe in plumbing, no pump, no swg 6.6808 1.1258
      no pump, no swg, probe in plumbing 6.49
      >>this is the same measurement with diff values, unless the temp/ph changed the probe values are drifting through this whole range.

      probe in plumbing, pump on, no swg 6.63 1.1312
      probe in plumbing, pump on, swg on 6.62 1.1318
      >>this suggests that the swg has no effect

      If you had two similar values for probe in plumbing, no pump, no swg, then we could conclude that the pump is causing the issue, but we don't. My theory is that the pump was leaking current that damaged the first probe, then the second probe too.


      Let me know what you think

      Delete
  22. Thank you. The first probe got wet and that is why I got the new probe. The system is grounded. I think i will try another probe and see what happens. If the pump is creating a voltage in the system are there any options you could suggest or maybe a way to test for the voltage?

    ReplyDelete
  23. Hello Anthony,

    I have been searching google but haven't found anything yet. Can you share your pump name and model number so I can see if any issues have been reported for it?

    Thanks, Reza

    ReplyDelete
  24. Great article. Learn lot things for my new invention. Thank you !!!

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. hi raza i want one of i2c ph board iam from iraq can you help me and i want presuer meter its connect to ardoinu where i get it pleas and thank you .

    ReplyDelete
  27. Hi Reza

    Very interesting post. I'm working on a automated titrator, using (I think) exact same pH probe, but a different amplifier. I have written my own code, and now I have to calibrate. The pH measurment code is somewhat like this https://www.sgbotic.com/index.php?dispatch=products.view&product_id=1454 (far down in the page you will find it under documents). So I want to use this code to calibrate, but what values do I take from this and put in my code? How can I utilize your code for the pH measurment code that I'm using?
    thank you

    ReplyDelete