Hallo! I currently have this problem that my soil sensor does not detect Phosphorus and Potassium.
the soil sensor that im using.
the circuit setup
Here is my code,
#include <ModbusMaster.h>
ModbusMaster node;
// Soil sensor Modbus address (often 1 by default)
#define SENSOR_ID 1
// RS485 control pin (RE/DE)
#define MAX485_RE_DE 4
void preTransmission() {
digitalWrite(MAX485_RE_DE, 1);
}
void postTransmission() {
digitalWrite(MAX485_RE_DE, 0);
}
void setup() {
Serial.begin(115200); // USB Serial Monitor (set Serial Monitor to 115200)
Serial.println("7-in-1 Soil Sensor Test");
// Set RS485 RE/DE pin as output
pinMode(MAX485_RE_DE, OUTPUT);
digitalWrite(MAX485_RE_DE, 0);
// Init Modbus
node.begin(SENSOR_ID, Serial2);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
// IMPORTANT: Sensor default = 4800 baud
Serial2.begin(4800, SERIAL_8N1, 26, 27); }
void loop() {
uint8_t result;
uint16_t data;
// Moisture (0000H)
result = node.readHoldingRegisters(0x0000, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("Moisture: ");
Serial.print(data);
Serial.println(" %");
}
// EC (0002H)
result = node.readHoldingRegisters(0x0002, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("EC: ");
Serial.print(data);
Serial.println(" uS/cm");
}
// pH (0004H)
result = node.readHoldingRegisters(0x0003, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("pH: ");
Serial.println(data / 10.0); // usually scaled by 10
}
// Nitrogen (001EH)
result = node.readHoldingRegisters(0x001E, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("Nitrogen: ");
Serial.print(data);
Serial.println(" mg/kg");
}
// Phosphorus (001FH)
result = node.readHoldingRegisters(0x001F, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("Phosphorus: ");
Serial.print(data);
Serial.println(" mg/kg");
}
// Potassium (0020H)
result = node.readHoldingRegisters(0x0020, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("Potassium: ");
Serial.print(data);
Serial.println(" mg/kg");
}
// Temperature (0001H)
result = node.readHoldingRegisters(0x0001, 1);
if (result == node.ku8MBSuccess) {
data = node.getResponseBuffer(0);
Serial.print("Temperature: ");
Serial.print(data / 10.0); // usually scaled by 10
Serial.println(" °C");
}
Serial.println("----------------------");
delay(2000); // Wait 2s before next read
}
Here is the sample output, the EC sometimes has value and i think the nitrogen has inflated value. I tested that it works because when i remove it from the soil the temperature increase then moisture go down but the nitrogen still remains on 4035 to 4045 range.
Moisture: 264 %
EC: 0 uS/cm
pH: 7.50
Nitrogen: 4038 mg/kg
Phosphorus: 0 mg/kg
Potassium: 0 mg/kg
Temperature: 25.80 °C
any insights are much welcome. Thank you!

