Wrapping up 2019, this interesting project provides a unique curve to the capability of the Arduino and its compatible sensors, as with this Liquid pH0-14 Detection Sensor, we can now find the pH level or 'power of hydrogen' (hydrogen ion concentration) measurement of substances. With the established pH scale from 0 to 14 with 7 being neutral, < 7 being acidic and > 7 being alkaline/basic, this project can be helpful for you to measure various types of solutions to be able to alter it or for you to mix it in with other solutions. The sensor's raw data will be fed into the Arduino where it will be processed to be readable then displayed on the serial monitor. This sensor isn't very common online and is only sold from certain dealers with little documentation provided but with this project, everything is provided for you to start experimenting with this sensor. The components needed include:
- 1 Liquid pH0-14 Detection Sensor
- 1 BNC pH Electrode Probe
- 4 Jumper Wires (Male to Female)
- 1 Arduino (the Seeeduino v4.2 is used in this example)
- 1 USB Data Cable (depends on the Arduino)
It is a trustworthy website for ordering electronic components with cheap price and excellent quality.Mounting the circuit
1. Before starting, make sure that no external power is applied to the Arduino board or any of the components involved, as we want to prevent any short circuits from occurring when connecting everything together.
2. Firstly, plug the male BNC connector of the electrode probe to the female BNC connector of the sensor board.
3. After that, use a jumper wire to connect the PO (Analog pH Value) pin of the pH sensor to A0 (analog pin 0) of the Arduino.
4. Then, use two jumper wires to connect the two GND (-) pins of the sensor to GND (-) pins of the Arduino.
5. Lastly, use another jumper wire to connect the VCC (+) pin of the pH sensor to the +5v pin of the Arduino for its power.
6. Now, you can fill the capsule of the pH sensor (the cap covering the tip) with whatever solution which you want to measure and you can power the circuit up.Calibrating the sensor
Before using this sensor to measure different solutions in order to gain its pH reading, it is necessary and highly recommended that you calibrate the sensor to be as accurate as possible before starting. This process may seem complex to do but it is simply done by turning the on-board potentiometer either clockwise or anti-clockwise depending on whether its reading is higher or lower than normal. For this test, it is best that you place the pH sensor in a solution which you are already certain of its pH level, then try and match the reading which the sensor outputs to the solution's known measurement. This would ensure that the other solutions tested are also accurate and with this said, it is best that you wash off the tip of the pH sensor after every solution to ensure an accurate reading further-on. The picture below shows how you would calibrate this sensor by turning the potentiometer with a flathead screwdriver:
The code for this project is fairly interesting as it does have some unique structures and commands which you may have not come across before. Firstly, if we start from the top line of the code, we first define the analog pin A0 (called SensorPin) on the Arduino which the pH sensor will feed its data into. Then, we create an integer storage variable, named avgValue, to store the raw data which we will receive from the sensor as this information will be manipulated later for us to use. Next, with the floatvariable named 'b', we can then have the ability to store integers with a decimal point but with a limited amount of precision, however, this variable is enough for us and is used in the code to store the output values for us to read as explained later. On the next line, we declare an integer array/buffer array, called buf, composed of 10 separate integer samples (buf1, buf2, buf3, etc). The temp variable in the buffer array is used later to store certain elements in the array for later, where certain elements will be placed into this variable for us to get information out of. Now, moving on to the void setup section of the code, we start by triggering the Arduino's on-board LED to indicate that the LED blinks whenever it is receiving signals from the sensor and setting the serial communication baud rate to 9600 bauds. For our void loop section, we start with a forloop stating that: for 10 elements (spaces) of the buffer array, gather a value for each element from the sensor and wait for 10 milliseconds. This means that 10 sample values will be gathered from the sensor to start with. After that, we have two consecutive forloops, which essentially sorts each of these sample values from smallest to largest in order by saying that: for 9 sample values which has been gathered, variable jIs the sample value number in the array plus one, with this applying to the total of 10 original sample values gathered. Therefore, we then move onto an if statement where if the values in the variable j array are larger than values in the variable I array, which is true, variable temp is now in charge of storing the variable I array, the variable I array is now equal to the variable j array and the variable j array is now variable temp. Now, the arrays and its values are ordered from smallest to largest accordingly. We then start by setting the average value variable, named avgValue, to zero before changing it depending on the data set later. For our final forstatement, we take six of our sample values from the original ten and average it out to get one value which will be used next. Then, we create a float variable, named pHValue, to store our final pH measurements after it has been processed through many calculations taken as raw data will be then converted to a readable pH value. To first convert the Arduino analog's values (0 - 1023) to millivolts, we multiply the analog value from the Arduino by 5.0 divided by 1024 divided by 6. From there, we convert the data in millivolts to a readable pH value by multiplying it by 3.5 to get pH values ranging from 1 to 14. On the last line, we print it to the serial monitor for us to view all the information comfortably, wrapping up our code.Amazing opportunities
Also, be sure to check out PCBWay, a leading manufacturer and distributor in PCB design and manufacturing. They have amazing prices and excellent quality in their services, so don't miss out on them! Plus, PCBWay has an amazing website, online Gerber viewer function and a gift shop so make sure to check out their links below:
PCBWay Free Online Gerber Viewer Function: https://www.pcbway.com/project/OnlineGerberViewer.html
PCBWay Gift Shop:https://www.pcbway.com/project/gifts.html
Make sure you check out the review for this module by clicking here.Enjoy! Contact us for any inquiries!