mod-pH
Datasheet
Procedure
Following good lab procedures is important to obtain the best results while also staying safe. pH measurements typically involve calibration solutions which are generally all toxic or hazardous to some extent. Aside from safety considerations, the following is a step-by-step process calibration:
- Collect all the materials needed: calibration solutions, clean water, towels, equipment, etc.
- Rinse the probe in clean water. RO/DI, deionized, or distilled water is best. Tap off excess water drops trapped in the probe tip and blot dry.
- Pour some calibration solution into a separate container. It should be enough to fully submerge the tip of the probe, then submerge the probe.
- Continually take measurements, watching for the measurement to stabilize. Eventually, only the third decimal place will vary from measurement to measurement. When the reading stabilizes, have the module calibrate itself for the solution.
- Safely dispose of the calibration solution and clean or dispose of the container.
- Repeat steps 2 through 5 for each calibration point. It is important to note that pH solutions change slightly with temperature. The internal calculations in the module account for this when given the solution’s temperature. When calibrating, use the labeled pH value, not the temperature-adjusted value.
Calibration Types
The module supports three methods of calibration.
Single Point
Single point is the least useful and should generally not be used. It uses one point and is only accurate for a small range around that one point.
If this method is used, it should not be used at 7.0 pH. The reason is the pH scale is not a straight linear line all the way through the entire range. It is generally linear through 4.0 to 7.0 pH and separately linear through 7.0 to 10.0 pH. The differing slopes will skew readings near the 7.0 pH point.
Dual Point
Dual point calibration is used for measuring between two set points. For pH measurements, the two points are typically 10. pH to 7.0 pH, or 7.0 pH to 4.0 pH. This type of calibration will provide accurate measurements between the two points and less accurate results outside of the points.
Triple Point
With three points of calibration at 4.0, 7.0, and 10.0, nearly the entire pH range can be accurately measured. Towards the extremes of the pH scale, there is significant non-linearity, and they must be calibrated more closely to the expected range (10.0 to 14.0, for example).
Precedence
The module will select the best calibration type from the available calibrated points as follows:
- If there are high, mid, and low points, it will use triple-point calibration to calculate the result.
- If there are high and low points, it will use dual-point calibration to calculate the result.
- If there is a single-point calibration data, it will use single-point calibration to calculate the results.
- No calibration points used will result in an uncalibrated measurement.
Calibration data is stored on the module. Measurements will automatically use calibration data; there won’t be a change until both a high and low point have been entered.
More Explanation
The temperature of a solution affects the pH. For example, a solution at 25°C may measure 6.5 pH, and the same solution at 20°C may be 6.45 pH. Part of the difference is the actual change in pH of the solution and not an error. A much smaller part of the change is due to a change in the resistance of the probe and is accounted for with a temperature compensation formula.
The module uses several points of data for taking measurements and calibration. With all the points together, it applies a temperature compensation formula that adjusts the measured value to a compensated value. It is good practice to notate in some way that pH measurements have been temperature compensated for comparisons to other measurements. It is important to note that pH measurements from other devices may use different compensation formulas or no formula at all.
1.
🔽 Install Arduino IDE
Install the Arduino IDE
2.
📦 Install the library
Start the Arduino IDE, press the Sketch menu, and then Include Library > Manage Libraries
. Search for Microfire_Mod-pH
and install the library.
3.
🔢 Code
Below is the Basic example. It can be found in File > Examples > Microfire_Mod-pH > Basic
in the Arduino IDE.
#include <Microfire_Mod-pH.h>
Microfire::Mod_pH::i2c ph;
void setup() {
Serial.begin(9600);
Wire.begin();
ph.begin();
}
void loop() {
ph.measurepH();
Serial.println((String) ph.pH + " pH");
delay(1000);
}
4.
➡️ Upload the code
Pick the board and port, then Upload the code.
5.
🔎 View the output
Open the Serial Monitor, measurements should be displayed in the monitor, with updates every second.
6.
Documentation
The library is documented here:
1.
📦 Install ESPHome
Follow the instructions on the ESPHome website.
2.
⌨️ Start a project
Type esphome wizard mod-ph.yaml
in the terminal. Make sure the path on the terminal is where you want the project to be. Follow the steps, and there should be a .yaml file in the directory you ran the command in. For this write-up, it will be mod-ph.yaml
. If you type esphome compile mod-ph.yaml
you should see the project compile.
3.
🔢 Code
The YAML file should be changed to the following:
esphome:
name: microfire-mod-ph
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
# import the mod-ph component
external_components:
- source:
type: git
url: https://github.com/u-fire/ESPHomeComponents/
# https://esphome.io/components/i2c.html
i2c:
sda: 21
scl: 22
sensor:
- platform: mod_ph
id: ph
name: pH
update_interval: 15s
button:
- platform: template
id: ph_calibrate_low
name: pH Calibrate Low 4.0
icon: mdi:format-vertical-align-bottom
on_press:
lambda: |-
id(ph).calibrateLow(4.0);
- platform: template
id: ph_calibrate_mid
name: pH Calibrate Mid 7.0
icon: mdi:format-vertical-align-center
on_press:
lambda: |-
id(ph).calibrateMid(7.0);
- platform: template
id: ph_calibrate_high
name: pH Calibrate High 10.0
icon: mdi:format-vertical-align-top
on_press:
lambda: |-
id(ph).calibrateHigh(10.0);
- platform: template
id: ph_calibrate_reset
name: pH Calibrate Reset
icon: mdi:restore
on_press:
lambda: |-
id(ph).calibrateReset();
- platform: factory_reset
name: Restart with Factory Default Settings
This example uses the esp32dev
board, make sure to change it as needed. Change the wifi
section to your network and password. Check that the i2c
section is using the correct pins.
4.
➡️ Upload
Type esphome run mod-ph.yaml
. It will compile the project and ask you which serial device to upload the code to. After that, you’ll see the ESP debug output. If everything goes to plan, you should see a device has been discovered in Home Assistant.
5.
🏠 Home Assistant
From within Home Assistant, press Settings > Devices & Services
and find the device in the ESPHome integration box. Click it and then click where it says 1 Device. You should see a screen with all the information, conductivity measurement, and some buttons to calibrate and reset the device. You can create dashboards, scripts, and anything else Home Assistant can do from here.
There are more examples for various combinations of sensors/modules on our ESPHomeComponents GitHub repo.
Wiring
1.
📦 Install the library
This Python library can be installed through pip in a terminal:
pip3 install Microfire-Mod-pH
Typing python3 -m Microfire_Mod_pH.shell
will start the shell application and give access to
all features and functions of the module. Type help
to see a listing of the commands available.
2.
🔢 Code
Create a python script and run the following sample code.
import Microfire_Mod_pH
ph = Microfire_Mod_pH.i2c()
ph.begin()
ph.measurepH(23.1)
if ph.status:
print("Error: " + ph.status_string[ph.status])
else:
print("{:.2f}".format(ph.pH), end='')
print(" pH")
3.
Documentation
The library is documented here: