8 in 1 soil sensor with hex send and receiver

I am doing a project but i'm confused and frustrated, i'm doing a 8 in 1 intergrated soil sensor using arduino nano, TTL to RS485 converter module , i also have the MAX485, 0.96 oled display but my codes and wiring dont work, please who can help

Welcome to the forum

As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming category of the forum

Ok thanks

Post a link to your sensor
Post a drawing of your circuit, mention how things are powered
Post your code

You wouldndo yourself a favour and you read How to get the best out of this forum and post accordingly (including as mentioned code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).


This is my diagram

There is no link on my manual except this

type or paste code here
```#include <SoftwareSerial.h>

#define RE 7
#define DE 6

const uint32_t TIMEOUT = 500UL;

const byte moist[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
const byte temp[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA};
const byte EC[] = {0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x25, 0xCA};
const byte PH[] = {0x01, 0x03, 0x00, 0x03, 0x00, 0x01, 0x74, 0x0A};

byte values[11];
SoftwareSerial mod(2, 3); // Rx pin, Tx pin

void setup() {
  //  Serial.begin(9600);
  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

  delay(500);
}

void loop() {
  uint16_t val1, val2, val3, val4;

  Serial.println("Moisture: ");
  val1 = moisture();
  float Val1 = val1 * 0.1;
  delay(1000);
  //Serial.print(val1);
  Serial.print(Val1);
  Serial.println(" %");
  Serial.println("-----");
  //delay(1000);

  Serial.println("Temperature: ");
  val2 = temperature();
  float Val2 = val2 * 0.1;
  delay(1000);
  //Serial.print(val2);
  Serial.print(Val2);
  Serial.println(" *C");
  Serial.println("-----");
  //delay(1000);

  Serial.println("Conductivity: ");
  val3 = conductivity();
  delay(1000);
  Serial.print(val3);
  Serial.println(" us/cm");
  Serial.println("-----");

  Serial.println("Ph: ");
  val4 = ph();
  float Val4 = val4 * 0.1;
  delay(1000);
  //Serial.print(val4);
  Serial.print(Val4);
  Serial.println(" ph");
  Serial.println("-----");

  delay(5000);
}

int16_t moisture() {
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(moist, sizeof(moist));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
  }
  Serial.println();
  return (int16_t)(values[4] << 8 | values[5]);

}

int16_t temperature() {
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(temp, sizeof(temp));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
  }
  Serial.println();
  return (int16_t)(values[4] << 8 | values[5]);

}

int16_t conductivity() {
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(EC, sizeof(EC));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
  }
  Serial.println();
  return (int16_t)(values[4] << 8 | values[5]);

}

int16_t ph() {
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(PH, sizeof(PH));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
  }
  Serial.println();
  return (int16_t)(values[4] << 8 | values[5]);

}

void printHexByte(byte b)
{
  Serial.print((b >> 4) & 0xF, HEX);
  Serial.print(b & 0xF, HEX);
  Serial.print(' ');
}

This is the code i used last

This is the model number ygc-sm-kv-w2 soil integrated sensor

Try with 9600 for mod.

The default baud rate is 9600 which i have tried still nothing

If your sensor is wired like on your wiring image, it is not even powered (missing power supply negative).

It is powered i connected the ground with the sensor, arduino. And modmus (common ground) then 12v- to that same ground, 12v+ to the VCC of the sensor

You did not read and follow the instructions referenced here

Be aware the scam of the 8 in 1 soil sensor is well known, a hobby sensor can not measure NPK. Given that the entire sensor could be garbage.
You will get readings, but they are nonsense.

No readings at all

So sorry

Post your code in code tags. Also post the compile result in code tags.

I'm not so good with this, i dont even know how to go about it. Please can you guide

Ok i dont have any code, i just copied this online to test, can you give me a code to start with