Reading RS485 Sensor Data with Arduino Mega Using ModbusRTUClient

Hey all,
I’m new to IoT and development board and I need help reading a sensor communicating in RS485 with Arduino Mega.
I have the SparkFun RS485 breakout board and connected the TX to pin 19, RX to 18, and RTS to 8.
I’m using this code:

#include <ArduinoModbus.h>
#define RTS 8
// How often (in milliseconds) the sensors will be read.
const unsigned long REPORT_INTERVAL = 1000;

void setup() {
  pinMode(RTS, OUTPUT);
  if (!ModbusRTUClient.begin(9600)) {
    Serial.println("Failed to start Modbus RTU Client!");
    while (1);

// The time at which the sensors were last read.
unsigned long lastMillis = 0;

void loop() {
  // If enough time has elapsed, read again.
  if (millis() - lastMillis > REPORT_INTERVAL) {
    lastMillis = millis();
    // The Modbus RTU temperature and humidity sensor:
    // Address: 0x01
    // Holding Register: 0x00
    // Read Length: 2
    // Temperature = result[0]
    // Humidity = result[1]
    if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x00, 2)) {
      Serial.print("failed to read registers! ");
    else {
      // If the request succeeds, the sensor sends the readings, that are
      // stored in the holding registers. The read() method can be used to
      // get the raw temperature and the humidity values.
      short rawtemperature =;
      short rawhumidity =;
      // The raw values are multiplied by 10. To get the actual
      // value as a float, divide it by 10.
      float temperature = rawtemperature / 100.0;
      float humidity = rawhumidity / 100.0;
      Serial.print("Temperature: ");
      Serial.print("Humidity: ");

But I’m getting "failed to read registers! " error and some random characters, anyone has any idea why? The TX LED on the Mega is blinking and so is the RTS LED on the breakout board… I’d highly appreciate any help.

you might retitle this as a ModbusRTUClient, not an rs-485 problem

Done, thanks for the comment, any idea about the issue itself?

Any updates here OP? I'm looking to do the same and Googling has not led me to a straightforward solution yet.

What is the sensor you are trying to read from? Do you have a link to a datasheet or user manual?