IOT

DIY Soil Ph Meter using Soil Ph Sensor & Arduino

In this project, we will create our own DIY Soil Ph Meter utilizing a Soil Ph Sensor and an Arduino to monitor soil pH. Soils can be inherently acidic or alkaline, and their pH value can be determined by testing. The acidity or alkalinity of the soil is measured by its pH.

Soil is regarded as a natural substrate for plant development and growth. There is a lot of research going on right now to figure out what’s causing farmers’ crop failure. One of the reasons that hinder plant growth and root development is the natural equilibrium in unstable or infertile soil. The pH is a scale that measures the acidity or basicity of a substance on a scale of 0 to 14. A pH number of less than 7 is considered acidic, whereas a value of more than 7 is considered basic. If the pH scale reads 7, the substance is neutral. Neutral soil provides the best circumstances for plant growth and development. Some plants, on the other hand, can tolerate slightly acidic soils with a maximum pH of 5.

Apart from the Soil Ph, the Nitrogen, Phosphorous, Potassium, EC, and Salinity content of the soil are also important for plant growth. The NPK Sensor can be used to measure NPK content. We can use a soil EC sensor to assess EC and salinity, but soil Ph is a completely different factor than soil NPK. We have a Water Ph Sensor in one of our previous posts, however owing to construction and restrictions, the Water Ph Sensor cannot be utilized to test the Soil Ph. This is why a specific Soil Ph Sensor is required to determine the pH of soil.

Arduino Soil Ph Meter

The sensor runs perfectly with Modbus RS485 and produces outstanding results. So, in this post, we’ll learn about Soil Ph Sensors and Arduino Interfacing, as well as how to make our own Arduino Soil Ph Meter. On a 0.96′′ OLED Display, we’ll show the pH of the soil.

Components Required:

  • Arduino Nano
  • NPK Sensor
  • 0.96″ I2C OLED Display
  • Modbus Module
  • 5V – 30V DC Supply
  • Connecting Wires
  • Breadboard

Soil Ph Measurement & its important

What is Soil Ph?

The acidity or alkalinity of the soil is measured by its pH. The concentration of hydrogen ions is measured by the pH value. Because the concentration of hydrogen ions varies so much, a logarithmic scale (pH) is utilized.

The pH of most soils is between 3.5 and 10. The natural pH of soils in locations with more rainfall normally ranges from 5 to 7, while in drier areas, the pH ranges from 6.5 to 9. The pH value of soil can be used to classify it:

  • 6.5 to 7.5—neutral
  • over 7.5—alkaline
  • less than 6.5—acidic, and soils with pH less than 5.5 are considered strongly acidic

Origins

The pH of natural soil is determined by the rock from which it was created, as well as the weathering processes that acted on it over time, such as climate, vegetation, geography, and time. Over time, these actions tend to create a decrease in pH (an increase in acidity).

Rain is also thought to be a major contributor to the rise in soil acidity. Some fertilizers can alter the pH of the soil and hence the number of nutrients accessible to plants.

Effects

The amount of nutrients and compounds that are soluble in soil water is affected by soil pH. Some nutrients are more readily available in acidic environments, whereas others are more readily available in alkaline environments. When the pH of the soil is near neutral, however, most mineral nutrients are readily available to plants.

Because of aluminum and manganese toxicity, as well as calcium and magnesium deficiencies, the formation of severely acidic soils can result in poor plant growth. Nutrient shortages such as zinc, copper, boron, and manganese may occur in alkaline soils.

Soil Ph Sensor

This is a waterproof and dustproof Soil Ph Sensor that measures the pH of the soil from 3 to 9 with high accuracy of 0.3PH. The sensor is protected by an IP68 protective cover and sealed with high-density epoxy resin to keep moisture out of the body’s interior. Agricultural cultivation, industrial production, environmental monitoring, animal husbandry, and sewage treatment are all applications for the sensor.

Specifications

  • Probe type: Probe electrode
  • Measuring range: 3 ~ 9 PH
  • Measurement accuracy: ±0.3PH
  • Resolution: 0.1 PH
  • Output signal: RS485/0-5V / 0-10V / 4-20mA output
  • Supply voltage: 5V~30VDC
  • Working temperature range: -30 ° C ~ 70 ° C
  • Stabilization time: 5-10 Minutes after power on
  • Response Speed: ≤15S
  • Standard 2 meters Cable
  • Long-term Stability: ≤5%/y

Pinout

As it must be connected to an RS485 or MAX485 module, the Soil Ph Sensor has four pins. Yellow, Blue, Black, and Brown are the four different colored wires.

Communication Protocol & Register Address

Modbus is the communication protocol that it employs. With the device address as stated below, the device functions as a slave. With a device address 0x01, you can transmit this command or Inquiry frame & Read soil PH.

The Response frame will look like this. The Ph value can be calculated using the response frame.

You can compute the Ph Value based on the response you received. The value of Ph is the 4th bit (beginning from the 0th bit). For instance, 0047H (hexadecimal) = 71 decimal = pH = 7.1pH.

Interfacing Soil Ph Sensor with Arduino & OLED Display

Let’s use the MAX485 Modbus Module to connect the Soil Ph Sensor to the Arduino Nano Board. The following is a schematic of the connections.

Using Software Serial, the R0 and DI pins of the Modbus are linked to D2 and D3 of the Arduino. Similarly, we must enable DE and RE high by connecting them to Arduino’s D7 and D8 pins, respectively. The NPK Sensor is made up of four wires. VCC is the brown one, which requires a 5V-30V power supply and can be linked to Arduino’s 5V. The GND pin, which is black in color, should be linked to Arduino’s GND. The B pin of the MAX485 is linked to the B pin of the wire, and the A pin of the wire is connected to the A pin of the MAX485.

The SSD1306 OLED Display is an I2C module with a 0.96′′ display. The VCC and GND of the OLED Display are linked to the Arduino’s 3.3V and GND. Its SDA and SCL pins are also connected to Arduino’s A4 and A5. You can either follow the circuit layout and assemble the circuit on a breadboard, or you can create a bespoke PCB design.

Source Code/Program

The source code for connecting a Soil Ph Sensor with an Arduino and getting the sensor’s Soil Ph value via a Modbus command can be seen below. You can send the command and get the HEX Code value back. To obtain the Measured Soil Ph content data, the HEX code must be translated to decimal.

You’ll need OLED Library because we’re using an OLED Display. Add the OLED Library to the Arduino IDE by downloading it.

1. Adafruit SSD1306 Library: Download

2. Adafruit GFX Library: Download

Here is the complete source code. Compile & upload it to the Arduino Nano Board.

#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

The OLED and the sensor will both initialize after the code is submitted. It will take some time for the sensor to stabilize, and the reading may be erroneous for a few seconds at first.

You’re ready to proceed after the sensor has stabilized. When exposed to air, the sensor produces a Ph of 7.0, which may be seen on an OLED display.

So that’s how you connect an Arduino to a soil ph measuring sensor and receive a Ph reading. Similarly, place the sensor in several soil samples. Depending on the type of soil, you’ll notice a difference in the Ph Value. Like an Analog Soil Ph Sensor, the value increases or decreases, and it may also be utilized as an IoT Soil Ph Sensor.

Analog Soil Ph Meter Arduino

Conclusion

I hope all of you understand how to design Soil Ph Meter using Soil Ph Sensor & Arduino. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.