This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I thought some of you might be interested in this, seeing as we are all DIY enthusiasts and we should probably all be using pH meters.
I have been wanting a decent pH meter with a detachable / replaceable probe for a while, but the options have not been very appealing. I don't have the money to spend on a proper lab meter, and I don't think the lower-tier options are worth the gamble. What I do have are:
- Skills working with electronics
- Electronic components
- Tools
- Time
I decided to go the DIY route and build a meter from a commonly available and cloned amp board with a BNC connector. It would feed data into an Arduino-style microcontroller and run custom code and display on an LCD. It needed to be useable without any other equipment and be powered by a battery. There must be a way to calibrate it and if possible to get temperature data along with the pH. I was able to achieve all of these things. Here is a write-up which will allow you to recreate this project yourself if you desire.
Parts used (links go to an amazon product page -- I do not necessarily recommend the specific linked items, caveat emptor):
- Generic pH amplifier board & probe
- Project box
- 16x2 LCD panel with backlight and I2C interface board
- Arduino Nano clone
- 10K NTC Thermistor -- I also used a 10Kohm resistor
- 9V battery holder box with switch
- Through-hole prototyping PCB
Consumable materials used:
- Calibration tablets
- Purified water
- KCL for probe storage solution
Tools and gear:
- Soldering iron and solder
- Hand files
- Breadboard and jumpers
- Hot glue
- Nuts and fasteners
- Thermoplastic
- Superglue
- Random office supplies
- Heat shrink
Description:
First step is unpacking the amp board and probe. The probe storage solution dried out, so my first item of business was to make some KCL solution and let it sit in there for a few hours. I think this is written on the instruction sheet, but I can't understand Chinese.
Meanwhile, hook the amp board to a 5V voltage source and set the offset pot. The trimpot is also called a 'potentiometer' and is either of the two the blue boxes with the tiny dial on top. This is a variable resistor which is used to fine tune certain hardware settings. In this case the two pots alter:
- Threshold -- when pH reaches a certain level the red LED lights up and the Do pin sends out a signal which can be read by the attached device and trigger some kind of action. I am not using this and will ignore it
- Offset -- the amount of voltage differing from the 'neutral' value
The offset pot is the one closest to the BNC connector.
A quick word about how this probe and amp board work:
The probe contains a neutral buffer inside of it with an electrode, along with a reference electrolyte with a reference electrode. The liquid it is immersed in will act as an electrolyte and the differential between the reference electrolyte and reference electrode and the surrounding liquid and detecting electrode is detected as a tiny amount of positive or negative voltage.
The board that the probe connects to is an amplifier. It takes the tiny voltages and amplifies them so that they can be read by a less sensitive device and decoded through an A/D converter. The A/D takes a voltage and maps it over a range of numbers and outputs a number to a computer which can be read by a program. Since in this case the A/D is bound by 0V as minimum and 5V as maximum the amplifier board takes the positive and negative values and maps them between 0V and 5V.
This is where the offset pot comes in. pH is mapped at 0V being 0 pH and 5V being 14 pH, with 2.5V as neutral. The ideal setting for the offset pot is to get 2.5V output on the Po pin with the probe reading neutral. To accomplish this, we can short the probe contacts together and hook a multimeter to the Po pin and adjust the offset pot until hitting 2.5V.
I attempted to do this but the pot value was not in range. In this case I replaced the 10K pot with a 20K pot since I have them already and thought it was necessary. Turns out it wasn't, so you can skip this. If you are motivated to make this offset zero, you can, but it really just needs to be as close as you can get it.
Place a wire from the inside of the probe connector to the outside of the probe connector, connect a 5VDC supply on the VCC (V ) and GND pins, and hook the meter to GND and Po and set it to DC Volts and adjust the pot til you get as close to 2.5V as possible. Since the software calibrates by looking at voltage ranges, if the offset is too large it will fail to calibrate, so you should at least check this.
Next step is to hook it to an Arduino and connect to a computer and run a program to map the voltages to pH values.
I used an Arduino Uno (genuine) to set everything up and test it, and a Nano (clone) to use in the box.
If you are not familiar with the Arduino I will give you a basic run-down:
The Arduino is a series of SBCs (single board computers) or MCUs (microcontroller units) which act as the computing device for a large array of uses, such as acting as the computer in this pH meter. It has analog inputs and digital inputs, PWMs, I2C and SPI busses, and other things which can interface with various hardware and communicate information and control things. In this case we will be interfacing with three things (besides the computer used to program it):
- pH amplifier board (read pH)
- NTC thermistor (read temperature)
- LCD panel (display data)
The pH board will draw 5VDC from the Ardunio which acts as the power and voltage reference. It will give back a 0V - 5VDC signal which connects to an analog pin Arduino. The Arduino will use a program we give it to take the analog voltage and convert that to a digital value which will in turn be converted to a pH value. We will connect from the amp board to the Arduino the VCC (V ) to the 5V, the GND to GND, and the Po to an analog input pin (A0).
NTC stands for 'negative temperature coefficient' and a thermistor is a resistor which varies in resistance depending on temperature. The NTC part means resistance decreases as temperature increased. The Arduino cannot detect resistance, it can only detect voltage. Resistance and voltage are dependent on each other and can be computed easily with a simple setup.
To determine the resistance of the NTC, we must produce a voltage from it and in order to produce a voltage from resistance we use a voltage divider circuit. This is two resistors laying one end to the other with a voltage across them both and a connection in the middle. If the voltage across the resistors is known and the value of one of the resistors is known, then the voltage in the middle of the resistors will tell you the value of the second resistor.
This means that to find the resistance of the NTC we will use the NTC as a resistor and place it on the GND pin and another resistor on the 5V pin with both meeting on an analog input pin on the Ardunio (A1).
The LCD panel which I am using has an I2C interface board attached to it. This takes the many signals required to control the LCD and translates them to need only two signals, which are data (SDA) and clock (SCL). Data signals are just varying voltages and in order to decipher them a computer has to know where the parts of the signal start and end.
If you have a binary signal of bits (1s and 0s which combine to make up numbers representing everything digital) and transmit 1001011101010101010101110000011 how do you know where one digital piece ends and another begins, or even if the first bit is the start of a of a piece or the middle of one? One way to do this is to transmit a clock signal on another line, which will match a clock to the data so that the computer can decode the message. Pretty neat.
The pins on the LCD will connect to the Arduino like so: GND to GND, VCC to 5V, SDA to pin A4, and SCL to pin A5.
The sensors and LCD will be monitored and controlled with a program we give to the Arduino. Programs use libraries to do common things so that you don't have to do the low-level programming required for everything. For instance there is an NTC thermistor library which we can invoke to easily read the thermistor. I found a library which was meant for a similar pH board which had been modified to work with generic ones. It has functions to compute the pH from the voltage value and it can also run a basic calibration of the probe and save that data in the Arduino's EEPROM (re-writable permanent storage).
I took the example code from this library and modified that further to my liking and have provided it again, in turn. These libraries and programs are released open source which enables people to do things like this with it, and that is fantastic.
Here is the link to that library.
To use this, download the entire library as a zip file (in github click on the green code button and Download zip). Place the DFRobot_PH directory in your Arduino library folder (on Windows, Users\User\Documents\Arduino\libraries) and when you start the Arduino IDE it should be available as a library.
At this point you also need the LiquidCrystal_I2C library and the SmoothThermistor library. Go into Library manager and install them.
Then open the 'File' menu and then 'Examples' and go to 'External Libraries' and 'DFRobot_PH' and open the example.
Connect the amp board
V -> 5V
GND -> GND
Po -> A0
plug in the Arduino board to the computer and upload the example sketch and open the Serial Monitor and you should see pH values appear.
To get the temperature sensor working connect to the amp board
GND <- NTC -> A1
5V <- 10,000 Ohm resistor -> A1
That's it. You should now get a temperature reading.
You can now set the calibration data the for pH probe by using the serial monitor. You also need calibration buffer solution in pH 4.0 and pH 7.0. Type ENTERPH in the serial monitor and hit CTRL ENTER. A message will appear saying you need to put your probe in calibration solution. Do that for either one and when it has stabilized type CALPH then when you get a success message type EXITPH. Do all these steps again for the other solution. Your probe is now calibrated!
You can plug in the LCD as well
GND -> GND
VCC -> 5V
SDA -> A4
SCL -> A5
When you boot up the Arduino you should now get the data on the LCD.
It is time to put it all together.
Reference the pictures to see the build.
At this point I realized I had made an error. By prototyping it on the Uno I hadn't realized that powering by battery would result in different reference voltages (USB voltage vs 9V battery regulated to 5V) and thus the calibration data was invalid. The Uno will automatically switch from USB voltage to VIN (battery) voltage when they are both plugged in, so calibrating on the PC with the battery plugged in will use the battery voltage and it will be calibrated properly. The Nano does not do that, or at least the knock-off version I have doesn't.
This means I have to figure out how to get the voltage to be the regulated battery input voltage for the reference on the analog pins and still interface the Arduino with USB to use the serial monitor.
There are a few ways to do it:
- Connect through a serial TTY -> usb adapter using the pins on the nano instead of plugging in USB
- Program the Arduino to calibrate using buttons or something without a computer
- Disable the USB power to the Arduino but not the Data signals and power the Arduino from the battery which connected to the computer
I could do any of them, but I chose 3 because it is the easiest, considering I already did all the soldering and all I had to do for option 3 was cut some wires in the USB connection.
I have a bunch of female USB header boards and a USB-A to USB-A cable, so I wired this up and plugged it together.
I powered up my Arduino with the switch on the battery and ran the calibration again.
Perfect!
Any questions, critiques, or comments are welcome.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/DIYBeauty/c...