Overview
In this project, we will make our own DIY Soil Ph Meter using Soil Ph Sensor & Arduino for the measurement of Soil Ph. Soils can be naturally acidic or alkaline & can be measured by testing their pH value. Soil pH is a measure of the acidity or alkalinity of the soil.
Soil is considered a natural medium for plant growth & development. Much research is going on to determine the internal factors of farmers’ crop production failure. One of the factors is the balance of nature in unstable or unfertile soil that inhibits plant growth and plant root development. The Ph is the acidity or basicity of material measured on a scale between 0 to 14. The Ph value lesser than 7 is considered acidic and greater than 7 is considered basic. If the pH scale is 7 then the material is neutral. The most ideal soil conditions for the growth & development of plants are neutral soil. However, some types of plants are still tolerant of soils with slightly acidic Ph with a maximum pH of 5.
Apart from Soil Ph, the Soil Nitrogen, Phosphorous, Potassium, EC & Salinity content is also useful for plant growth. For the measurement of NPK Content, we can use NPK Sensor. For Soil EC & Salinity measurement, we can use Soil EC Sensor But Soil Ph is completey different factor compared to Soil NPK. We have already discussed about Water Ph Sensor in one of our previous post, but Water Ph Sensor cannot be used to measure the Soil Ph due to construction and limitations factor. This is why we need an special Soil Ph Sensor to measure the Ph of a Soil.
While browsing through the internet, I found a great Ph Sensor manufactured by some Chinese R&D Manufacturer. The sensor is manufacture by a company called HONDETEC and you can check it on Alibaba. The sensor works perfectly with Modbus RS485 and the result is highly impressive. So, in this post we will learn about Soil Ph Sensor & Arduino Interfacing and design our own Arduino Soil Ph Meter. We will display the Soil Ph value on a 0.96″ OLED Display.
Bill of Materials
The bill of materials for making your own Soil Ph Meter is given below. All the components can be easily purchased from Amazon except the Soil Ph measurement sensor. You can get it from Amazon as well but may not be available every time.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino Nano Board | 1 | Amazon | AliExpress |
| 2 | Soil Ph Sensor | 1 | Amazon | AliExpress |
| 3 | 0.96" I2C OLED Display | 1 | Amazon | AliExpress |
| 4 | MAX485 Modbus Module | 1 | Amazon | AliExpress |
| 5 | 9V Power Supply | 1 | Amazon | AliExpress |
| 6 | Connecting Wires | 10 | Amazon | AliExpress |
| 7 | Breadboard | 1 | Amazon | AliExpress |
Soil Ph Measurement & its important
What is Soil Ph?
Soil pH is a measure of the acidity or alkalinity of the soil. A pH value is actually a measure of hydrogen ion concentration. Because hydrogen ion concentration varies over a wide range, a logarithmic scale (pH) is used
Most soils have pH values between 3.5 and 10. In higher rainfall areas the natural pH of soils typically ranges from 5 to 7, while in drier areas the range is 6.5 to 9. Soils can be classified according to their pH value:
1. 6.5 to 7.5—neutral
2. over 7.5—alkaline
3. less than 6.5—acidic, and soils with pH less than 5.5 are considered strongly acidic
Origins
Natural soil pH depends on the rock from which the soil was formed and the weathering processes that acted on it, i.e. climate, vegetation, topography & time. These processes tend to cause a lowering of pH (increase in acidity) over time.
Rain is also considered as one of the significant factors for the increase in acidity of the soil. Some fertilizers can change soil pH and increase or reduce the number of nutrients available to plants.
Effects
Soil pH affects the amount of nutrients and chemicals that are soluble in soil water. Some nutrients are more available under acid conditions while others are more available under alkaline conditions. However, most mineral nutrients are readily available to plants when soil pH is near neutral.
The development of strongly acidic soils can result in poor plant growth as a result of Aluminum & Manganese toxicity or calcium & magnesium deficiency. Alkaline soils may have problems with deficiencies of nutrients such as zinc, copper, boron & manganese.
Soil Ph Sensor
This is a waterproof and dustproof Soil Ph Sensor that can measure the Soil Ph value from 3 to 9 with high accuracy up to ±0.3PH. The sensor has an IP68 protective case & is sealed with High-density epoxy resin which can prevent moisture from entering the body interior part. The sensor is suitable for Suitable for agricultural cultivation, industrial production, environmental monitoring, animal husbandry, and sewage treatment.
Specifications
1.Probe type: Probe electrode
2. Measuring range: 3 ~ 9 PH
3. Measurement accuracy: ±0.3PH
4. Resolution: 0.1 PH
5. Outputsignal: RS485/0-5V / 0-10V / 4-20mA output
6. Supply voltage: 5V~30VDC
7. Working temperature range: -30 ° C ~ 70 ° C
8. Stabilization time: 5-10 Minutes after power on
9. Response Speed: ≤15S
10. Standard 2 meters Cable
11. Long-term Stability: ≤5%/y
Pinout
The Soil Ph Sensor has 4 pins as it need to be connected to RS485 or MAX485 Module. The four colored wires are Yellow, Blue, Black & Brown.
Communication Protocol & Register Address
The communication protocol that it uses is the Modbus. Thee device works as a Slave with the device address as shown below. You can send this instruction or Inquiry frame & Read soil PH at device address 0x01.
You will get the Response frame as follows. From the response frame, you can calculate the Ph Value.
From the received response, you can calculate the Ph Value. The 4th bit (starting from the 0th bit) is the value of Ph. For example, we got 0047H (hexadecimal) = 71 Decimal => pH = 7.1pH
To learn more about the Modbus RTU Communication protocol, you may follow the following tutorials:
- Modbus RTU Communication with Arduino
- Modbus RTU Communication with ESP32
- Modbus RTU Communication with Raspberry Pi Pico
Interfacing Soil Ph Sensor with Arduino & OLED Display
Now, let us interface the Soil Ph Sensor with the Arduino Nano Board using the MAX485 Modbus Module. The connection diagram is given below.
The R0 & DI pin of from the Modbus is connected to D2 & D3 of Arduino using Software Serial. Similarly, we have to enable DE & RE high which is done by connecting them to the D7 & D8 pin of Arduino. The NPK Sensor has 4 wires. The brown one is VCC which needs a 5V-30V Power Supply & can be connected to 5V of Arduino. The GND pin which is black in color needs to be connected to the GND of Arduino. The Blue wire which is the B pin is connected to the B pin of MAX485 & the Yellow Wire which is the A pin is connected to the A pin of MAX485.
The 0.96″ SSD1306 OLED Display is an I2C Module. The OLED Display VCC & GND are connected to 3.3V & GND of Arduino. Similarly, its SDA & SCL pins are connected to the A4 & A5 of Arduino. You can follow the circuit diagram & assemble the circuit on a breadboard or make a custom design PCB.
Source Code/Program
The source code for interfacing Soil Ph Sensor with Arduino & retrieving Soil Ph value from the Sensor via Modbus command is given below. You can send the command and retrieve the value in HEX Code. The HEX code needs to be converted into Decimal to get the Measured Soil Ph content data.
Since we are using OLED Display to display, you will need OLED Library. Download the following OLED Library and add it to the Arduino IDE.
1. Adafruit SSD1306 Library: Download
2. Adafruit GFX Library: Download
Here is the complete source code. Compile & upload it to the Arduino Nano Board.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#include <SoftwareSerial.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define RE 8 #define DE 7 const byte ph[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A}; byte values[11]; SoftwareSerial mod(2, 3); #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); mod.begin(4800); pinMode(RE, OUTPUT); pinMode(DE, OUTPUT); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } display.display(); delay(100); display.clearDisplay(); display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(2); display.setCursor(20, 20); display.print("PH Meter"); display.display(); delay(3000); } void loop() { byte val; digitalWrite(DE, HIGH); digitalWrite(RE, HIGH); delay(10); if (mod.write(ph, sizeof(ph)) == 8) { digitalWrite(DE, LOW); digitalWrite(RE, LOW); for (byte i = 0; i < 11; i++) { values[i] = mod.read(); Serial.print(values[i], HEX); } Serial.println(); } float soil_ph = float(values[4]) / 10; Serial.print("Soil Ph: "); Serial.println(soil_ph, 1); display.clearDisplay(); display.setTextSize(2); display.setCursor(20,0); display.println("Ph Value"); display.setTextSize(3); display.setCursor(35,30); display.print(soil_ph, 1); display.display(); delay(3000); } |
Testing & Monitoring Soil Ph Data on OLED Display
Once the code is uploaded, the OLED will initialize along with the sensor. The sensor will take some time to get stabilized and the reading may be incorrect for a few seconds initially.
Once the sensor gets stabilized, you are ready to go. The sensor when exposed to air gives 7.0 as a Ph which can be observed on an OLED Display.
So this is how you interface soil ph measurement sensor with Arduino & get the Ph Reading. Similarly, put the sensor in different samples of soil. You will see a variation in the Ph Value depending upon the type of soil. The value increased or decreases like an Analog Soil Ph Sensor and can also be used as IoT Soil Ph Sensor.
Video Tutorial & Guide
Follow the following video to learn about the entire project & code information.

















34 Comments
Good morning, excellent tutorial. Excuse me if the first value appears normal and the following appear at 0fffffffff soil ph: 25.5, it could be a sensor error.
I would also like to know if you have a tutorial on the soil moisture and temp and EC sensor
Initially the sensor will show 25.5 on first attempt. Then the sensor will start reading the correct Ph value.
I don’t have the soil ec+temp+moisture sensor based on modbus. Else i would have already posted the tutorial.
Greetings. Great tutorial. Very informative. May I know what changes will need to be made to make this code work on an Node MCU ESP32 system? I removed the coding for the screen and increased the baud rate to 115200. But I keep getting errors that seem to suggest that the avr library have a conflict with the arduino library.
The modbus doesn’t work with ESP8266 or ESP32 using this code. I already tried implementing the sensor with esp32/8266 but failed everytime.
Good day! I am trying to make this project using an Arduino mega 2560 and 16×2 LCD module (I2c) but the pH never changes from 25.5 value. I followed everything except for the codes for the oled display, what should I change?
Please check A and B pins connection and also the connections of RS485. Please check the VCC supply for sensor. Supply 12V and check.
You can also check the frame bit from instruction manual
Good day! I tried doing what you said. The pH value is still 25.5.
hi sir thank you for the great work. i got all the components you used and connected exactly it still resulted to a display of 25.5 but when i connected an external supply of about 12V same thing but changing the board rate from 4800 to 9600 i received the following feedback on the Serial monitor
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
13200B844FFFFFFFF
Soil Ph: 0.0
i don’t know if this could help you help us out thanks.
will be waiting for your humble reply
i can confirm that it works because Mine just worked.
thanks again
Hey, may I know what change you made to get your setup to work?
Hey, may I know what change you made, to make your one work?
Made the 2 board rates the same
9600
Ok. Thanks.
Hi sir: How do you know pH value is 4th bit?
And why the pH value divided by 10?
Read the datasheet
Hello and thank you for this tutorial. I have the same problem as the others. The value is stuck at 25.5.
I changed the baudrate, but the problem is still there.
If anyone has a solution.
Thank you
Hello! Can I use the same address to my pH sensor? I bought the same sensor that you are using but there’s no manual included in my ordered item. If not, beside from contacting the seller, what else can I do to find the manual or address of my device? Thank you!
You can try with same one.
good day, Sir! May I know how do you calibrate your pH sensor?
Good day, Sir! May I know how do you calibrate your pH Sensor? Thanks!
donde puedo conseguir los sensores estoy ubicado en Colombia Bogotá
what type of jumper wires did you use? and how did you connect the circuit to 5V – 30V DC Supply?
do you have source code for connect to blynk apps as ioT project?
do you have any solutions for this problem??
me too
i try change adress (for ph) with {0x01, 0x03, 0x02, 0x00, 0x42, 0x38, 0x75} like a datasheet say
but i hav 0.0
help me plaese
i have a soil ph sensor input: 10-30V output: 0-5V
i have (like output:rs485) 4 cable, vcc gnd A e B
i have use rs 485 and the sketch like in this site
but, it’s dosen’t work
buenas noches si pudo hacer funcionar el sensor con el esp 32?
Good afternoon, greetings from Ecuador, I have a query and I already replicated the code exactly but it always gives me the value of 25.5
Very good explanation, thank you very much, but I have a query, I already entered the communication protocol example that comes to me in the manual of the sensor, but when loading the program, only the value 25.5 appears, please help, I only need this sensor to finish with my worked.
same -_-
Hello, I have a query about output displyaed. After replicating the code exactly it always gives the value of 25.5. Is there any suggestion, what to change?
did you get the values
Hello David, I am working on a similar project, I have uploaded the codes except for the the screen but the value remains 25.5. Please what solution did you apply to yours?
For all of those with only 0 or 25 as a result. Double check your inquiry frame that was on the datasheet. Mine differed from the one shown here and updating it fixed it for me.
Hello, I want to ask if there’s a vision for this project that includes an ESP32 or ESP8266 for Wi-Fi connection. Thank you; I really love your project! ❤️