In this Tutorial, you will learn how to use the pH sensor with Arduino and find the pH value of different liquids “Water, Milk and Cold rink”, and display the pH value on the serial monitor. As this is a getting started tutorial, so in this tutorial, we will only cover the extreme basics like for example
- How a pH sensor work
- Application of pH meter
- pH sensor Calibration
- pH sensor interfacing with Arduino
- Basic programming to find the pH value of different liquids and finally
Gravity: Analog pH Sensor / Meter Kit For Arduino by DFrobot:https:
Arduino Uno: https://amzn.to/2tVz1vu
Gravity: Analog pH Sensor / Meter Kit For Arduino by DFrobot: https://amzn.to/2MEtRzy
Mega 2560: https://amzn.to/2ze1kdu
Voltage sensor 0-25v: best offer https://amzn.to/2PcMGXY
Nodemcu esp8266 wifi module: Best price https://amzn.to/2NAvmiB
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330 ohm resistors pack: https://amzn.to/2NtlAeh
5v 2A adaptor: https://amzn.to/2GsNfcw
2n2222 npn transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
female DC power jack socket: https://amzn.to/2KEo1gt
470 uf capacitors: https://amzn.to/2xDCOzf
5×7 cm vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / strip board: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wire cutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF
Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Let’s first start with the very basic questions
What is pH? And how a pH sensor actually works?
“pH stands for power of hydrogen, which is a measurement of the hydrogen ion concentration in the body. The total pH scale ranges from 1 to 14, with 7 considered to be neutral. A pH less than 7 is said to be acidic and solutions with a pH greater than 7 are basic or alkaline.”
If you’re using litmus paper, and you are not interested in any automatic system, or any notification system then none of this matters. You can check manually the pH values of different liquids. The basic idea is that the paper turns a slightly different color in solutions between pH 1 and 14 and, by comparing your paper to a color chart, you can simply read off the acidity or alkalinity without worrying how many hydrogen ions there are.
But a pH meter somehow has to measure the concentration of hydrogen ions. How does it do it?
An acidic solution has far more positively charged hydrogen ions in it than an alkaline one, so it has greater potential to produce an electric current in a certain situation.
in other words, it’s a bit like a battery that can produce a greater voltage. A pH meter takes advantage of this and works like a voltmeter: it measures the voltage (electrical potential) produced by the solution whose acidity we’re interested in, compares it with the voltage of a known solution, and uses the difference in voltage (the “potential difference”) between them to deduce the difference in pH….
About the DFrobot pH Sensor kit:
This is the analog pH sensor kit from the DFrobot, DFrobot is a leading robotics and open source hardware provider. They create innovative, user-friendly hardware & software products that become the building blocks in all kinds of electronic projects. I personally recommend you should definitely visit www.dfrobot.com .
This pH Sensor kit can be used in Water quality monitoring equipment, it can be used in the water tanks, Fish aquarium, this pH Sensor kit can be used with GSM, nodemcu esp8266 wifi module for remote notifications.
This pH sensor kit is best for measuring the water quality and other parameters. It has an LED which works as the Power Indicator, a pH sensor, a BNC connector, a variable resistor which is used for the calibration which I will explain during the testing and PH2.0 sensor interface circuit.
pH Sensor Kit Interfacing with Arduino:
For the step by step interface connections watch video Tutorial “Click Here”
Connect the red wire with the Arduino’s 5v…
Connect the black wire with the Arduino’s Ground…
Connect the blue wire with the Arduino’s Analog pin A0..
so that’s all about the interfacing, now let’s have a look at the pH sensor Arduino programming/code.
Arduino pH sensor code / Programming:
This is a very simple and basic program to find the pH value of different liquids, I will be using some known liquids, whose pH values are already known. For the demonstration purposes, I will be using Water, Milk, and a cold drink. In upcoming tutorials, I will modify this program and display the pH Values on the LCD. I will also make an IOT version of the same project.
#define SensorPin 0 // the pH meter Analog output is connected with the Arduino’s Analog
unsigned long int avgValue; //Store the average value of the sensor feedback
Serial.println("Ready"); //Test the serial monitor
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
for(int i=0;i<9;i++) //sort the analog from small to large
for(int i=2;i<8;i++) //take the average value of 6 center sample
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
We use a for loop to get 10 sample values from the pH sensor and store these values in an array. Then we use these two for loops to sort the values from small to larger in the ascending order…
This for loop is used to take the average value of 6 center samples and the value is stored in avgValue. Then we convert this value into millivolts and into the pH value. Then finally we display the ph value on the serial monitor.
For the Practical Demonstration watch video given at the end or “click Here”.
First of all, let’s find the pH value of the Water, the water under test is not pure water, so in this case, the ph value can be slightly greater than 7. After you are done with the program uploading,
connect Arduino with the laptop and open the Serial monitor.
The pH of pure water is 7. In general, water with a pH lower than 7 is considered acidic, and with a pH greater than 7 is considered basic. The normal range for pH in surface water systems is 6.5 to 8.5, and the pH range for groundwater systems is between 6 to 8.5. So the water under test is safe as you can see in the video and can be used for drinking without any problem….
Now let’s test the pH value of the Milk.
Fresh cows milk has a pH of between 6.7 and 6.5. Values higher than 6.7 denote mastitic milk and values below pH 6.5 denote the presence of bacterial deterioration. For more information click on the link below.
Now, let’s check the pH value of Cold drink. Remove milk and clean this with water… If you search on Google you will find that the pH value for the cola drinks can be from 2 to 5. As you can see on the screen the pH value is between 2 and 5.
This pH sensor kit from the DFrobot is the most accurate pH sensor kit. We checked the pH values of three different liquids and got accurate values.
Arduino pH Sensor Calibration:
The calibration is really easy, all you need is select a liquid with the known pH values like for example the cow milk and check it’s value, if the value is greater or lower than the exact pH value which you can, of course, find in the chart, then all you need is to rotate this variable resistor which you can find near to the BNC connector clearly labeled in the picture above, and adjust the value.