Cannot read input register from rs485

Hello guys, can you help me?
I try to read temperature and humidity from xymd-02 sensors using RS485. I connect them to arduino uno. I also using modbus as the protocol. This the code i use :

#include <ModbusMaster.h>

#define MAX45_DE 3
#define MAX45_RE_NEG 2

ModbusMaster node;

void preTransmission(){
digitalWrite(MAX45_RE_NEG, 1);

void postTransmisson(){
digitalWrite(MAX45_RE_NEG, 0);

void setup() {
// put your setup code here, to run once:
pinMode(MAX45_RE_NEG, OUTPUT);
pinMode(MAX45_DE, OUTPUT);

digitalWrite(MAX45_RE_NEG, 0);




void loop() {
// put your main code here, to run repeatedly:
uint8_t resultMain;

resultMain = node.readInputRegisters(0x0001, 2);
Serial.print("Hasil : ");
if (resultMain == node.ku8MBSuccess) {
Serial.print("Suhu : ");
Serial.print("Kelembapan : ");

When i try to run this code, on serial monitor always display something like this:

and when i try to print resultMain on monitor, it always display 226.

Anyone can help to solve this problem?

Probably a good time to learn about using the forum and how to post code.

There are helper posts at the top of each category.
How to,post good

@charles221b, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Please edit your post, select all code and click the </> button to apply code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Looking at your code, you're using pins 0 and 1 of the Arduino Uno for RS485; those pins are also used for the USB connection to the PC so you have a conflict which can explain the result.

Note that I'm not familiar with ModBus.

thank you for that, i will try.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.