กลับหน้าหลัก
views
How to Read Soil pH with Arduino Using RS485 Sensor PR-3000-TR-PH-N01
Last updated on

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

ArduinoMAX485
5VVCC
GNDGND
Pin 2RO
Pin 3DI
Pin 7DE
Pin 8RE
Circuit diagram showing Arduino UNO connected to MAX485 Module with all 6 wire connections labeled

Wire Soil PH Sensor to MAX485

MAX485 Module → Soil PH Sensor PR-3000-TR-PH-N01

MAX485Sensor Wire
VCCBrown wire
GNDBlack wire
BB-
AA+
Diagram showing MAX485 A/B terminals connected to the corresponding A+ and B- wires from the PR-3000 sensor with wire color labels

Wire OLED Display to Arduino

The OLED uses I2C, so only 4 wires are needed.

ArduinoOLED
5VVCC
GNDGND
A4SDA
A5SCL
Arduino A4/A5 pins connected to OLED SDA/SCL pins with clear wire routing

Install the Library

  1. Download the library from the link provided with the original article
  2. Extract the archive using WinRAR or WinZip
  3. Copy the extracted folder to Documents/Arduino/libraries/
  4. 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

  1. Select Board: Arduino UNO and choose the correct Port
  2. Click Upload from Sketch > Upload menu
  3. Open Serial Monitor and set Baud Rate to 9600
  4. 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

จ้างทำโปรเจคเลย

ประเมินราคาอัตโนมัติ + Reference Code

ขอให้ AI ประเมินราคาโปรเจคนี้

กรอกข้อมูลให้ครบ ระบบจะสร้างรหัสอ้างอิงและประเมินราคา/ระยะเวลาคร่าว ๆ จากรายละเอียดงาน แล้วให้กด Add LINE พร้อมพิมพ์รหัสนี้เพื่อคุยต่อ

คำถามให้ AI ประเมินแม่นขึ้น

หลังส่งฟอร์ม ระบบจะโชว์ Reference Code ให้ copy แล้วกด Add LINE เพื่อคุยต่อ ข้อมูลส่วนตัวจะไม่ถูกส่งเข้า GA4

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...