How to Read Soil pH with Arduino Using RS485 Sensor PR-3000-TR-PH-N01
How to Read Soil pH with Arduino Using RS485 Sensor PR-3000-TR-PH-N01
This guide walks you through wiring and coding Arduino UNO to read soil pH using the PR-3000-TR-PH-N01 Soil PH Sensor. It communicates over RS485, which makes it suitable for long-distance sensor networks in smart agriculture or IoT soil monitoring projects.
Required Components
- Arduino UNO R3
- Power Adapter 9V 2A
- USB cable for code upload
- MB-102 Breadboard (830 points)
- MAX485 Module (TTL to RS485)
- Soil PH Sensor RS485 PR-3000-TR-PH-N01
- OLED 128x64 I2C display, 0.96 inch
- Jumper wires: male-to-male, male-to-female, female-to-female, 20 cm each
Wire MAX485 to Arduino
The MAX485 module converts TTL signals from Arduino into RS485 signals that the sensor understands.
Arduino UNO → MAX485 Module
| Arduino | MAX485 |
|---|---|
| 5V | VCC |
| GND | GND |
| Pin 2 | RO |
| Pin 3 | DI |
| Pin 7 | DE |
| Pin 8 | RE |
Wire Soil PH Sensor to MAX485
MAX485 Module → Soil PH Sensor PR-3000-TR-PH-N01
| MAX485 | Sensor Wire |
|---|---|
| VCC | Brown wire |
| GND | Black wire |
| B | B- |
| A | A+ |
Wire OLED Display to Arduino
The OLED uses I2C, so only 4 wires are needed.
| Arduino | OLED |
|---|---|
| 5V | VCC |
| GND | GND |
| A4 | SDA |
| A5 | SCL |
Install the Library
- Download the library from the link provided with the original article
- Extract the archive using WinRAR or WinZip
- Copy the extracted folder to
Documents/Arduino/libraries/ - Restart Arduino IDE
Arduino Code to Read pH
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Define pins connected to MAX485
#define RO_PIN 2
#define DI_PIN 3
#define DE_PIN 7
#define RE_PIN 8
SoftwareSerial modbus(RO_PIN, DI_PIN); // RO=RX, DI=TX
void setup() {
Serial.begin(9600);
modbus.begin(9600);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("OLED init failed"));
while (true);
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
}
void loop() {
float phValue = readPH();
Serial.print("pH: ");
Serial.println(phValue, 1);
display.clearDisplay();
display.setCursor(10, 20);
display.print("pH: ");
display.println(phValue, 1);
display.display();
delay(1000);
}
float readPH() {
// Send Modbus command to read Holding Register at 0x0001 of PR-3000
// Adjust register address and scaling according to the sensor datasheet
digitalWrite(DE_PIN, HIGH);
digitalWrite(RE_PIN, HIGH);
delay(10);
byte request[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0x9A, 0x0B};
modbus.write(request, sizeof(request));
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
delay(100);
if (modbus.available() >= 7) {
byte response[7];
for (int i = 0; i < 7; i++) {
response[i] = modbus.read();
}
// Convert raw register values to pH float
// Adjust scaling per actual sensor datasheet
int rawHigh = response[3];
int rawLow = response[4];
float ph = (rawHigh * 256 + rawLow) / 100.0;
return ph;
}
return -1.0;
}
Note: The register address and raw data conversion in readPH() may need adjustment based on the actual sensor datasheet. If readings are abnormal, check the correct register address for pH data in your sensor’s documentation.
Upload and View Results
- Select Board: Arduino UNO and choose the correct Port
- Click Upload from Sketch > Upload menu
- Open Serial Monitor and set Baud Rate to 9600
- Wait for readings to stabilize — pH value appears on both Serial Monitor and OLED
Testing with Water
When the sensor tip is immersed in normal tap water, the reading should be approximately 6.6 pH, close to neutral. This confirms the sensor is working correctly.
If you test with slightly acidic water adjusted to pH 4.0, the reading should decrease accordingly, confirming the sensor responds correctly to pH changes.
Summary
Reading soil pH with Arduino over RS485 requires a MAX485 module to handle protocol conversion. The code uses SoftwareSerial with Modbus RTU to request pH data from the PR-3000 sensor. After parsing the response, the value is displayed on an OLED screen or Serial Monitor. This setup is ideal for extending into automated soil quality monitoring systems.
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย