Uncategorized

ph-4502c ph meter calibration notes

0

I have a pH meter (DIY-4502C) hooked up with Raspberry Pi. However, the instructions to calibrate is in Chinese and seems outdated.

Does anybody know how to calibrate it for measuring pH4-7?

2 Answers

1

From How to use a pH sensor with Arduino

Calibrate the sensor

As we can see that there are two potentiometers in the circuit. Which it is closer to the BNC connector of the probe is the offset regulation, the other is the pH limit.

  • Offset: The average range of the probe oscillates between negative and positive values. The 0 represents a pH of 7.0. In order to be able to use it with Arduino this circuit adds an offset value to the value measured by the probe, so the ADC will only have to take samples of positive voltage values. Therefore we will force a pH of 7.0 by disconnecting the probe from the circuit and short-circuiting the inside of the BNC connector with the outside. With a multimeter measure the value of Po pin and adjust the potentiometer to be 2.5V.
  • PH Limit: This potentiometer is to set a limit value of the pH sensor circuit that causes the red LED to light up and the Do pin signal to turn ON.

In addition we have to calculate the voltage conversion that will give us the pH sensor so we will need two pH reference value and measure the voltage returned by the sensor on the pin Po. The best thing to do is to use a calibration solution in powders, there are also in liquid but it is easier to preserve the powders. These solutions are sold in different values but the most common are pH 4.01, pH 6.86 and pH 9.18.

Graph of the measured voltage and pH equation

Graph of the measured voltage and pH equation. y= -5.70 * x + 21.34

Using the powders with pH 4.01 and pH 6.86 we obtain the voltages on the pin Po 3.04V and 2.54V respectively. The sensor is linear so by taking two points we can deduce the equation to convert the measured voltage to pH. The general formula would be y = mx + b, so we have to calculate m and b since x would be the voltage and y the pH. The result is y = -5.70x + 21.34.

Connection with Arduino

To connect with Arduino we will need an analog input (A0), power (5V) and two GND that actually in the sensor circuit are separated but we can use the same.

Code

The code consists of taking 10 samples of the analogue input A0, ordering them and discarding the highest and the lowest and calculating the mean with the six remaining samples by converting this value to voltage in the variable pHVol, then using the equation that we have calculated with the pH reference values we convert pHVol to pHValue and send it to the serial port to see it in the serial monitor.

const int analogInPin = A0; 
int sensorValue = 0; 
unsigned long int avgValue; 
float b;
int buf[10],temp;
void setup() {
 Serial.begin(9600);
}

void loop() {
 for(int i=0;i<10;i++) 
 { 
  buf[i]=analogRead(analogInPin);
  delay(10);
 }
 for(int i=0;i<9;i++)
 {
  for(int j=i+1;j<10;j++)
  {
   if(buf[i]>buf[j])
   {
    temp=buf[i];
    buf[i]=buf[j];
    buf[j]=temp;
   }
  }
 }
 avgValue=0;
 for(int i=2;i<8;i++)
 avgValue+=buf[i];
 float pHVol=(float)avgValue*5.0/1024/6;
 float phValue = -5.70 * pHVol + 21.34;
 Serial.print("sensor = ");
 Serial.println(phValue);

 delay(20);
}

 

0

Part 1 – Calibration Procedure

1. Analog output offset procedure

Offsetting meter analog output of 0.0V to + 2.5V for compatibility with ADC such MCP3008, MCP3208 etc. Cheap pH meters are almost always designed for Arduino which has an analog pin A0 to convert analog signal to digital. Rpi, sadly does not have any analog pin, so must use an external ADC moduel. More about this later.)

ph meter

offset procedure

2. pH limit potentiometer adjustment procedure

Set 2.46V which corresponds to the pH value of tap water as threshold voltage, by adjusting the limit potentiometer so that the red LED just turns on.

ph limit setup

Self/Auto Calibration Procedure

So the US10 cheap meter gives 2.46V for water. That is amazing, considering that I was too lazy to clean the glass, which for sure has some faint whisky traces left. My offset to the pH meter ADC is +2.5V, implying that water should read +2.50V. Again I am only using home tap water. Perhaps whisky and heavy metal traces in the tap water balances out. 🙂

Now that I think I should test at the other extremes, very acid and very basic. I have googled the following pH value charat, and see if I can find some more things to test/calibrate.

ph values chart

I just finished lunch. Before eating the desert Chinese mandarin dessert, I toodk a photo, and checked it pH.

chinese madarin

And green tea pH again.

green test 2.58v

Now there is the pH of something that I really want to know, the body wash I am suing every day.

I found the analog voltage. Now I need to calcule the pH value.

jj 2 in 1 pH5.5

ph results table

Now soy sauce and vinegar

soy sauce and vinegar

And finally, very acidic bleach and drain pipe cleaner!

bleach and drian pipe cleaner

The time has come to write the python program

Now I have enough samples, from very acidic to very basic, to get the ph per volt ratio which is used to get from measure analog output in volts to the pH value.

I am making morning coffee with milk, and a selfie!

coffee with milk

I updated the Excel worksheet with coffee and tea. Now the average pH/V is recursively self calibrating, meaning that more measurements added, more “accurate” is the average pH/V.

What I found too good to be true is that the measured pH value of the JJ body wash claiming pH5.5 is 5.51!

ph worksheet update

Now I have drawn the graph to get the values for the Rpi python program to calculate the pH values.

ph worksheet

/ to continue, …


Part 2 – Chinese to English Manual Translation and Suggestion for Newbies

Well, give me the link of the Chinese manual, I can translate it into broken English. 🙂

ph4502c

Do you mean the AT instruction set? Or the hardware setup? I guess they are common to all the real and fake boards. I can do the translation if that is what you need.

The basic Hello test is universal. You say “AT\r\n”, and the Ph Board will return “OK”. The general commands are also universal:

Reset, Current Ph value, Temperature, Threshold, Factory default setting, Current operation mode, …

ph at code

If you wish to translate the names of the pins. Here is one for the J3, J4 pinouts.

ph_tester_pinout

You may have already found the location of DS18B20 temperature sensor pin. This is a standard device, so you don’t need to read their instruction.

One other thing is that the vendor recommends to use their CH340 cable. This is important, because other cables using PL23dxx might not work for their board.

You may also find other teething problems. I have a brief suggestion list for the newbies.

  1. Test Rpi 3V3 signals is OK
  2. Test Rpi 3V3 signals converted to 5V logcie is OK.
  3. Test Rpi 3V3/5V0 loopback hardware is OK.
  4. Test Rpi sending string such as “AT/r/n” is OK
  5. Test is CH340 cable is OK

One final reminder to USB CH340 newbies: Remember to disable Serial Console at the Rpi Config Menu:

serial cable disable

And the plug and play, no library required, minimal, complete, verifiable, UART self test/loopabck, repeat send AT/r/n python program.

UART Self Test Program

# uart_test06 tlfong01 2019apr08hkt1603 ***

# Computer = Rpi3B+
# Linux    = $ hostnamectl = raspberrypi Raspbian GNU/Linux 9 (stretch) Linux 4.14.34-v7+ arm 
# Python   = >>> sys.version = 3.5.3 Jan 19 2017

# Test 1   - repeatWriteBytes() - UART port repeatedly send out bytes.  
# Function - Repeat many times sending bytes, pause after each bytes.

# Test 2   - loopBackTest() - UART port send and receive bytes.
# Function - Send one bytes to TX, wait some time (Note 1), then read bytes back from RX. 
# Setup    - Connet Tx pin to Rx pin to form a loop.

# Note 1
# Bolutek BlueTooth BC04 needs at least 10mS to respond

from   time import sleep
import serial

serialPort0 = serial.Serial(port = '/dev/serial0',
        baudrate = 9600,
        parity = serial.PARITY_NONE,
        stopbits = serial.STOPBITS_ONE,
        bytesize = serial.EIGHTBITS,
        timeout= 1)

def setSerialPortBaudRate(serialPort, baudrate):
    serialPort.baudrate = baudrate
    return

def serialPortWriteBytes(serialPort, writeBytes):
    serialPort.write(writeBytes)
    return

def serialPortReadBytes(serialPort, maxBytesLength):
    readBytes = serialPort.read(maxBytesLength)
    return readBytes

def serialPortWriteWaitReadBytes(serialPort, writeBytes, maxBytesLength, waitTime):
    serialPort.flushInput()
    serialPort.flushOutput()
    serialPort.write(writeBytes)
    sleep(waitTime) 
    readBytes = serialPortReadBytes(serialPort, maxBytesLength)
    print('        bytes written = ', writeBytes) 
    print('        bytes read    = ', readBytes)
    return readBytes

def repeatWriteBytes(serialPort, writeBytes, pauseTimeBetweenBytes, repeatCount):
    print('       Begin repeatWriteOneByte(), ...')   
    for i in range(repeatCount):
        serialPortWriteBytes(serialPort, writeBytes)                
        sleep(pauseTimeBetweenBytes)
    print('       End   repeatWriteOneByte().')
    return

def serialPortLoopBack(serialPort, writeBytes, maxBytesLength, waitTime): 
    print('        Begin serialPortLoopBack() [Remember to connect Tx to Rx!] , ...')
    serialPortWriteWaitReadBytes(serialPort, writeBytes, maxBytesLength, waitTime)     
    print('        End   serialPortLoopBack(), ...')
    return

setSerialPortBaudRate(serialPort0, 9600)
#repeatWriteBytes(serialPort0, b'AT\r\n', 0.01, 200000000)
serialPortLoopBack(serialPort0, b'AT\r\n', 32, 0.030)

''' Sample output  tlfong01 2019apr0801
>>> 
=== RESTART: /home/pi/Python_Programs/test1193/uart_test02_2019apr0801.py ===
        Begin serialPortLoopBack() [Remember to connect Tx to Rx!] , ...
        bytes written =  b'AT\r\n'
        bytes read    =  b'AT\r\n'
        End   serialPortLoopBack(), ...
>>>
'''

# End 

Good luck to your project! 🙂

References

Ph Testing Theory, Ph board pinout translation

Mar 02, 2016, 07:59 pm Last Edit: Mar 02, 2016, 09:26 pm by LeCyb Reason, Arduino Forum

 

  • 4
    How is this an answer to the question? – Steve Robillard Apr 18 at 5:34
  • 1
    This is an interesting answer, but does not appear to mention calibration. If you update it to include calibration then it would be a good answer. – Greenonline Apr 18 at 7:31
  • Well, I am just a poor hobbyist. Long time ago, I studied in a trade middle school, focusing on metal work and mechanical drawing, hoping to become a car mechanic one day to earn a living. Actually I have never heard about the pH thing until some year ago when TV ads mention about it. I have never seen any pH equipment in school lab. All I know is from Google. So you see at the end of my answer, I added the pH general knowledge post. I read it a couple of times, memorized the strange names by heart, so I can pretend to know some chemistry, and get more respect than I deserve, … 🙂 – tlfong01 Apr 18 at 7:50
  • @Steve Robillard Ah, sorry, I did not understand your comment until I read Greenonline’s answer. Originally I thought what the OP wanted is a translation of the manual from Chinese to English, and my job is done. Now after browsing the Arduino forum posts I know even if the OP got the full manual in English, he might not be able to do the calibration which requires subject knowledge in chemistry and pH stuff. I am good in physics but hopeless in chemistry. Anyway, I will try to do some self learning in pH stuff and see if I can improve my answer. – tlfong01 Apr 19 at 9:10

Not the answer you’re looking for? Browse other questions tagged    or ask your own question.

Categories: Uncategorized

2 replies »

  1. Hope all is well, I wanted to talk to you about the PH4502C if you’re still messing with it. I’m doing some automation and wanted to see if I could ask you some questions about your results and methods.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.