Issues with Soil sensor (Temp, humidity and Ph, no npk) with MAX485)

#include <ArduinoRS485.h>
#include <Arduino.h>

#include <RingBuffer.h>
#include <SoftwareSerial.h>

#include <RS485.h>

// Defining pins
#define DE 2
#define RE 3

void setup() {
  // Initialize Serial communication
  Serial.begin(9600);
  
  // Set DE and RE as output
  pinMode(DE, OUTPUT);
  pinMode(RE, OUTPUT);

  // Set DE and RE to LOW initially (receive mode)
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);
  
  Serial.println("Setup complete, entering loop...");
}

void loop() {
  // Ensure DE and RE are set to LOW for receive mode
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);
  
  delay(10); // Small delay to stabilize after mode switch
  
  // Check for available data
  if (Serial.available() > 0) {
    String data = Serial.readString(); // Read the incoming data

    // Print the received data to the Serial Monitor
    Serial.print("Received Soil Moisture Data: ");
    Serial.println(data);
  } else {
    // Debug statement if no data is available
    Serial.println("No data available.");
  }

  // Optionally, switch to transmit mode
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  
  delay(10); // Small delay before switching back to receive mode
  
  delay(1000); // Wait a second before the next loop iteration
}

I am not getting any reading from the sensor at all even though the TX RX lights are blinking on my Arduino UNO R4 Wifi.

My serial monitor only says "No Data Available"

Please note that unlike the circuit diagram I have connected DE to PIN 2 and RE to PIN 3

I see a few problems:

  • you are using Serial to print debug informations and to communicate with the sensor ( note on the uno r4 wifi rx/tx pins are accessible via Serial1, if I'm not wrong )
  • your code is expecting some "string" on the serial line, are you sure the sensor works like this, have you got a manual for this sensor? This thread describe a similar sensor which is modbus

Create a circuit diagram that does not need words to explain what is and is not connected.

Have you connected Tx/Rx correctly?