I spent a chunk of time understanding the design of SparkysWidgets minipH breakout board. I posted what I learned here. My conclusion is – at least at this stage – nice design! I’ll use SparkysWidgets minipH in my current prototype.
The goal of this post is to get the pH readings of the miniPH as accurate as possible.
The pieces in the picture include:
- the minipH breakout board
- an Arduino Uno
- a breadboard
- jumper wires
- pH probe and calibration solution from Atlas Scientific. I had purchased the pH kit earlier and used it to run tests which I documented in this post.
While I consider the price on the high side, I am using the probe and calibration solutions from the kit because Atlas Scientific is known for quality products and I have familiarity and confidence in them based on my prior use.
The process to reach the goal will include:
- Understand results from running Sparky’s Widget’s minipH.ino.
- Calibrate the readings.
- Implement any changes to the setup and Arduino sketch that will improve the readings.
- Document final readings.
Initial Run of minipH.ino
It was very easy to wire the prototype. All I needed to do was solder headers onto the minipH breakout board so that the Vin, GND, and I2C (SDA and SCL) pins can be wired to the Arduino.
I ran the sketch when the pH probe was in each of the calibration solutions and took a screen shot of the serial monitor:
Evolution of minipH.ino
minipH.ino gives me the basics of what I need to calibrate the pH voltage step and to read the pH. I will evolve this sketch to:
- use a state machine to handle input. This will make the code easier to read and easier to change to different displays. The first display I will use is the serial monitor.
- calibrate based on a weighted average of several readings.
- determine if the probe needs to be replaced.
- read the pH. In this case there is no need to change what Sparky’s Widgets has done.
- show the info on what was used in calculating the pH voltage step. I will use what Sparky’s Widget has provided and add to it.
State Machine Input
I based input from a person using this system on the following state machine:
|State||Valid Keys or Code To Run||Next State||Outputs|
|<any other character>||INVALID_ENTRY|
|CALIBRATE||-> calibrate pH||INPUT_CHAR||Display new slope|
|READ_PH||-> read pH||Display pH value|
|HELP||-> show help||INPUT_CHAR||Display inputs|
|CHECK_PROBE||->check probe||INPUT_CHAR||Display amount deviation and $ noise in readings|
|INFO||->show info||INPUT_CHAR||Display the params used in calculating the pH|
|INVALID_ENTRY||->print message, go to help||HELP||Display invalid entry text|
- 4 – assumes pH probe is in a pH 4 calibrated solution. Takes the reading and adjusts the pH voltage step to use this reading.
- 7 – assumes pH probe is in a pH 7 calibrated solution. Takes the reading and adjust the pH voltage step.
- vRef – as the shortened name implies, this is the voltage reference. It determines the mapping between the analog and digital output. For example, the vRef of the MCP1541 is a stable 4.096. When a reading comes in from the ADC, it’s discreet value will be between 0 and 4095. Which discreet value will be determined by VRef/4096. 4.096 is a great VRef for 12 bit ADCs since 4.096/4096 is 1mV. When the VRef is 4.93V – for example what I might see when using the USB port on my Mac as a power source, the division is 4.93/4096 = .001203613 – not as even a chunking of the analog into discreet parts. I’ll discuss this a bit more below.
- opampGain – recall in my earlier post the first op amp was used to amplify the voltages coming in from the pH probe. This is what the opampGain is. In the schematic for the minipH, the op amp gain is 5.68.
When I looked closer at the minipH breakout board, I noticed it did not include the MCP1541 as the schematic shows. The schematic seems to not be up to date with the actual minipH breakout board. OK. I can’t use the AREF of the Arduino, because AREF assumes the Arduino’s 10 bit ADC is being used. This means I will use the 5V out of the Arduino as the VRef to the ADC. Every time I have measured Arduino’s 5V out, it has been higher that 4.096, typically around 4.93. Yet constantly measuring and adjusting the vRef variable based on DMM readings was a non-starter for me. I could decide to use 4.93 – assuming this is “close enough” or somehow I could get the actual value of the Arduino’s 5V out. A Google search and I have found code from a very sharp person that indeed calculates the 5V out. How terrific is that? I may not be capable of figuring this code on my own, but happily – this person shared! See the readVcc() function in minipH_bitknitting.ino.
Output from the readVcc() function and my DMM got the same value – 4.94V for Arduino’s 5V out. mV results from a few ADC readings when the probe was in the pH 7 calibrating solution:
shows the difference when vRef is left at the default of 4.096 and not what is used when the MCP1541 is not use is about .5mV. I had this table that maps the pH value to the expected ADC reading (shift column) in my previous post:
Using the result from readVcc() gets a value that is closer to what I would expect to be more accurate.
Op Amp Gain
At first I was surprised to see the opAmpGain set to 5.25 in minipH.ino. After a closer check at the minipH schematic
the two resistors – R8 and R7 – used for the gain, I found R8 on the PCB to be 200K. So the OpAmpGain is indeed 5.25 and not 5.7 as calculated in the previous post.
- the pH 7 reading of a calibrated solution should be 0mV. Is the reading > 30mV or <-30mV?
- are the pH readings within a 2 minute time below an acceptable noise threshold?
Sending the ‘r’ or ‘R’ character to the arduino takes a pH reading. Check out the readpH() function to walk through how the pH is calculated based a reading of the ADC.
My Yippee! Moment came when it appears the minipH probe worked as advertised. It is a nice, simple design. I was surprised to find the VREF IC was not there. However, given the resolution of the readings, using the function to calculate the Vin seems to work fine.
I plan to evolve my knowledge of the minieC sensor using the same methods I used to understand the minipH sensor. By doing so, I am gaining a practical understanding of the components in the circuit. With perhaps op amps being the star of the show.
Thank you for reading this far. I hope you find many things to smile about.