7 in 1 soil sensor help

Hello everybody,

I am struggling on making a 7 in 1 soil sensor work.

I am using this sensor, with a TTL to RS-485 module. I've tried interacting with the sensor using the code bellow, but haven't seen any responses at all.

I've tried lots of different things (changing the wiring, code and even the arduino board), so I'm guessing it's a problem with the sensor itself. I wanted to ask just in case.

If anyone has any idea I should try, please say so (I'm desperate).

Code:

#include <SoftwareSerial.h>

// RO -> D10, DI -> D11
SoftwareSerial rs485(10, 11); // RX, TX

// Read holding register 40001 (address 0x0000)
byte tempCmd[] = { 
  0x01, 0x03, 
  0x00, 0x00, 
  0x00, 0x01, 
  0x84, 0x0A 
};

void setup() {
  Serial.begin(9600);     // USB monitor
  rs485.begin(9600);      // Sensor baud rate

  Serial.println("RS485 soil sensor test (UNO)");
}

void loop() {
  // Send request
  rs485.write(tempCmd, sizeof(tempCmd));
  delay(10);

  // Read response
  unsigned long start = millis();
  Serial.print("Response: ");

  while (millis() - start < 1000) {
    if (rs485.available()) {
      byte b = rs485.read();
      if (b < 0x10) Serial.print("0");
      Serial.println(b, HEX);
    }
    else {
      Serial.println("RS not available");
    }
  }

  Serial.println("\n----");
  delay(3000);
}


These sensors are a total scam - You are wasting your time trying to get them to deliver the 7 attributes.

Assuming your TTL to RS-485 module is connected correctly - you could try this improved code (your code was saturating the Tx buffer of Serial by printing all the time RS not available which would then become blocking).

#include <SoftwareSerial.h>

SoftwareSerial rs485(10, 11);

const byte tempCmd[] = { 0x01, 0x03,  0x00, 0x00,  0x00, 0x01,  0x84, 0x0A};

void setup() {
  Serial.begin(115200);
  rs485.begin(9600);
}

void loop() {
  Serial.println("Sending command");
  rs485.write(tempCmd, sizeof tempCmd);

  unsigned long start = millis();
  while (millis() - start < 5000) {
    if (rs485.available()) {
      byte b = rs485.read();
      if (b < 0x10) Serial.write('0');
      Serial.print(b, HEX);
      Serial.write(' ');
    }
  }
  Serial.println("\nEnd of listening");
  delay(3000);
}

open you serial monitor at 115200 bauds

You need to have DE and RE connected to the UNO.
Do you have ALL grounds connected together?
Are you supplying 12V DC?

1 Like

A recent post on the forum included a screenshot of the manufacturer's instructions. The N, P, and K parts you have to enter from outside sources; they do not get their data from the soil.

Hi @phobos_43 ,

Welcome to the forum..

As @jim-p mentions, you need the RE and DE hooked up and add the code for them..

And yes, these devices don’t actually do what they say, but it should communicate..

Sketch for 7 in 1 Modbus..

good luck.. ~q

Still need help?

I've tried your suggestion, but it sadly doesn't work. I guess it's the sensor. Thanks for helping though! Really appreciate it. :+1:

I have not given you the correct code yet.
Do you still want help?

Even if you got numbers out of it, what confidence could you ever have that they are even close to the truth?

Just one determination from the long list measurements it claims would need to be verified by lab grade methods in order to calibrate it. pH for example needs two buffer solutions to check the slope. Conductivity needs a standard solution of potassium chloride.

Better to get one good measurement than half a dozen dubious ones.