# Arduino Uno reading Modbus holding registers

**URL:** <https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366>\
**Category:** General Guidance\
**Created:** [December 17, 2025, 5:40pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366 "2025-12-17T17:40:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 17, 2025, 5:40pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/1 "2025-12-17T17:40:32Z")

</div>

I've been at this project for months and have decided I need help. Using an Arduino Uno to read specific holding registers on my generator's controller, but keep getting a timeout error. 485MAX chip is in use. I think the code is fine, compiles and runs, but I am wondering if i need to convert the modbus registers in my code to hexadecimal format for it to work properly. Would anyone like to guide me? I've scoured online resources for awhile with no progress to be had. Using Pin 2 of the Uno to control DE/RE on the 485MAX, Uno TX-\>DI 485MAX, Uno RX-\>RO 485MAX

```arduino
    #include <ModbusMaster.h>
    #include <SoftwareSerial.h> // If using SoftwareSerial for Modbus communication
    

//Define Pins and Objects.
    #define RS485_DE_RE_PIN 2 // Example pin for DE/RE control
    #define MODBUS_RX_PIN 8 // Example pin for Modbus RX
    #define MODBUS_TX_PIN 7 // Example pin for Modbus TX

    SoftwareSerial modbusSerial(MODBUS_RX_PIN, MODBUS_TX_PIN); // If using SoftwareSerial
    ModbusMaster node; // Modbus Master object
//•	//Pre/Post Transmission Callbacks: Define functions to control the RS485 transceiver's data direction (DE/RE pin):
    void preTransmission() {
      digitalWrite(RS485_DE_RE_PIN, HIGH); // Enable transmit
    }

    void postTransmission() {
      digitalWrite(RS485_DE_RE_PIN, LOW); // Enable receive
    }
//Setup Function.
    void setup() {
      Serial.begin(19200); // Initialize Serial for debugging output
      pinMode(RS485_DE_RE_PIN, OUTPUT);
      digitalWrite(RS485_DE_RE_PIN, LOW); // Start in receive mode

      modbusSerial.begin(19200); // Initialize SoftwareSerial for Modbus communication (match slave's baud rate)
      node.begin(1, modbusSerial); // Initialize ModbusMaster with slave ID (e.g., 1) and serial object(may have to change to just "Serial")
      node.preTransmission(preTransmission);
      node.postTransmission(postTransmission);
    }
//Loop Function (Reading and Printing).
    void loop() {
      uint8_t result;
      uint16_t data[5];//array to store 5 register values

      // Example: Read a holding register (function code 0x03)
      // Replace 0x01 with the actual register address and 1 with the number of registers to read
      result = node.readHoldingRegisters(401102, 1);//holding register for oil pressure
      

      if (result == node.ku8MBSuccess) {
        data[0] = node.getResponseBuffer(0); // Get the data from the response buffer (index 0 for the first register)
        

        Serial.print("Engine Oil Pressure: ");
        Serial.println(data[0]);
        
      } else {
        Serial.print("Modbus read error: ");
        Serial.println(result, HEX); // Print error code in hexadecimal
      }

      delay(500); // Delay between readings
      
      result = node.readHoldingRegisters(401107, 1);//holding register for battery voltage
      

      if (result == node.ku8MBSuccess) {
        data[1] = node.getResponseBuffer(1); // Get the data from the response buffer (index 1 for the 2nd register)
        

        Serial.print("Battery Voltage: ");
        Serial.println(data[1]);
        
      } else {
        Serial.print("Modbus read error: ");
        Serial.println(result, HEX); // Print error code in hexadecimal
      }
      delay(500);//delay between readings
      
      result = node.readHoldingRegisters(401340, 1);//holding register for L-L avg
      

      if (result == node.ku8MBSuccess) {
        data[2] = node.getResponseBuffer(2); // Get the data from the response buffer (index 2 for the 3rd register)
        

        Serial.print("AVG L-L Voltage: ");
        Serial.println(data[2]);
        
      } else {
        Serial.print("Modbus read error: ");
        Serial.println(result, HEX); // Print error code in hexadecimal
      }
      delay(500);//delay between readings

      result = node.readHoldingRegisters(401103, 1);//holding register for coolant temp
      

      if (result == node.ku8MBSuccess) {
        data[3] = node.getResponseBuffer(3); // Get the data from the response buffer (index 3 for the 4th register)
        

        Serial.print("Coolant Temp: ");
        Serial.println(data[3]);
        
      } else {
        Serial.print("Modbus read error: ");
        Serial.println(result, HEX); // Print error code in hexadecimal
      }
      delay(500);//delay between readings

      result = node.readHoldingRegisters(401506, 1);//holding register for run time
      

      if (result == node.ku8MBSuccess) {
        data[4] = node.getResponseBuffer(4); // Get the data from the response buffer (index 4 for the 5th register)
        

        Serial.print("Run Time: ");
        Serial.println(data[4]);
        
      } else {
        Serial.print("Modbus read error: ");
        Serial.println(result, HEX); // Print error code in hexadecimal
      }
      delay(500);//delay between readings

    }

type or paste code here

```

```arduino
type or paste code here

```

---

<div class="post-metadata">

**Author:** ![blh64](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/blh64/32/605986_2.png) [@blh64](https://forum.arduino.cc/u/blh64)\
**Post date:** [December 17, 2025, 5:48pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/2 "2025-12-17T17:48:19Z")

</div>

Welcome to the forums. Take a moment and read this: [How to get the best out of this forum - Using Arduino / Installation & Troubleshooting - Arduino Forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966)

Then Post your code (using code tags) and how you have your 485Max chip connected and it will greatly improve your chances of someone being able to help you.

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 17, 2025, 6:02pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/3 "2025-12-17T18:02:16Z")

</div>

Thanks, I'm stumbling through this first post, aren't I? lol

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [December 17, 2025, 6:09pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/4 "2025-12-17T18:09:09Z")

</div>

> [@mister480v](#):
>
> `401107,`401102, 401340

Please give a link to the document where You found that?

---

<div class="post-metadata">

**Author:** ![van\_der\_decken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/van_der_decken/32/1006976_2.png) [@van\_der\_decken](https://forum.arduino.cc/u/van_der_decken)\
**Post date:** [December 17, 2025, 6:15pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/5 "2025-12-17T18:15:22Z")

</div>

Hmm.

> [@mister480v](#):
>
> ` result = node.readHoldingRegisters(401340, 1);//holding register for L-L avg`

From [ModbusMaster.h](https://github.com/4-20ma/ModbusMaster/blob/master/src/ModbusMaster.h):

```arduino
uint8_t readHoldingRegisters(uint16_t, uint16_t);

```

The range of a `uint16_t` is [0..65535].

401340 doesn't fit in that range.

So that's obviously not going to work.

Begin by dealing with all the warnings that crop up when you turn the compiler's warning level to ALL.

```arduino
arduino-cli compile -b arduino:avr:uno --warnings all --output-dir ~/tmp --no-color (in directory: /home/me/Documents/sketchbook/Uno_R3/test)

/home/me/Documents/sketchbook/Uno_R3/test/test.ino: In function 'void loop()':
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:38:51: warning: large integer implicitly truncated to unsigned type [-Woverflow]
       result = node.readHoldingRegisters(401102, 1);//holding register for oil pressure
                                                   ^
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:55:51: warning: large integer implicitly truncated to unsigned type [-Woverflow]
       result = node.readHoldingRegisters(401107, 1);//holding register for battery voltage
                                                   ^
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:71:51: warning: large integer implicitly truncated to unsigned type [-Woverflow]
       result = node.readHoldingRegisters(401340, 1);//holding register for L-L avg
                                                   ^
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:87:51: warning: large integer implicitly truncated to unsigned type [-Woverflow]
       result = node.readHoldingRegisters(401103, 1);//holding register for coolant temp
                                                   ^
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:103:51: warning: large integer implicitly truncated to unsigned type [-Woverflow]
       result = node.readHoldingRegisters(401506, 1);//holding register for run time
                                                   ^
In file included from /home/me/Documents/sketchbook/libraries/ModbusMaster/src/ModbusMaster.h:58:0,
                 from /home/me/Documents/sketchbook/Uno_R3/test/test.ino:1:
/home/me/Documents/sketchbook/libraries/ModbusMaster/src/util/crc16.h: At global scope:
/home/me/Documents/sketchbook/libraries/ModbusMaster/src/util/crc16.h:71:17: warning: 'uint16_t crc16_update(uint16_t, uint8_t)' defined but not used [-Wunused-function]
 static uint16_t crc16_update(uint16_t crc, uint8_t a)
                 ^ ~~~~~~~~~~~
/home/me/Documents/sketchbook/libraries/ModbusMaster/src/ModbusMaster.cpp: In member function 'uint8_t ModbusMaster::requestFrom(uint16_t, uint16_t)':
/home/me/Documents/sketchbook/libraries/ModbusMaster/src/ModbusMaster.cpp:84:44: warning: unused parameter 'address' [-Wunused-parameter]
 uint8_t ModbusMaster::requestFrom(uint16_t address, uint16_t quantity)
                                            ^ ~~~~~~
/home/me/Documents/sketchbook/libraries/ModbusMaster/src/ModbusMaster.cpp:94:27: warning: 'read' is used uninitialized in this function [-Wuninitialized]
   _u8ResponseBufferLength = read;
   ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
Sketch uses 7996 bytes (24%) of program storage space. Maximum is 32256 bytes.
Global variables use 691 bytes (33%) of dynamic memory, leaving 1357 bytes for local variables. Maximum is 2048 bytes.
Compilation finished successfully.

```

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 17, 2025, 6:18pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/6 "2025-12-17T18:18:06Z")

</div>

That's the holding registers provided by the manufacturer, can't link the document because its proprietary.

 ![Screenshot 2025-12-17 121444](https://europe1.discourse-cdn.com/arduino/original/4X/e/6/e/e6ec9c18784d6763799e29cde6f89b5aa3d9db77.jpeg)

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [December 17, 2025, 6:51pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/7 "2025-12-17T18:51:17Z")

</div>

Okey, thanks. What does the table say at the head? As You said in the post, are they hexadecimal numbers? In Your code they appear as integers but they are too big to fit in a standard integer, -32768 to + 32767 for a 16 bit.

Signed, or unsigned long could be important as well as adding the hex suffix.

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 17, 2025, 7:11pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/8 "2025-12-17T19:11:28Z")

</div>

![register logic](https://europe1.discourse-cdn.com/arduino/original/4X/d/4/8/d4861b73e1a9a5e2b43666ca10db4507130947a7.jpeg)  
Reckon my code should say 1339 instead of 401340? That's what I'm gathering from the manual description anyway. It appears they're saying its 0 based, so -1 from what it's displayed as and omit the 40 prefix as that designates its a holding register and nothing more, am I getting warmer here or not so much?

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 17, 2025, 7:13pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/9 "2025-12-17T19:13:47Z")

</div>

I'm learning new things already, lol. Thanks. I don't know how to turn on the "ALL" function on my compiler, just using the Arduino IDE. Might try it through Eclipse later when I'm home. Appreciate the help.

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 18, 2025, 5:42pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/10 "2025-12-18T17:42:47Z")

</div>

so I changed the registers in my code, omitted the 40 and my theory proved incorrect. still no communication between devices. I'm open to any ideas at this point. I didn't think this would be a difficult project....

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [December 18, 2025, 6:08pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/11 "2025-12-18T18:08:12Z")

</div>

> [@mister480v](#):
>
> omitted the 40

> [@mister480v](#):
>
> omitted the 40

That sounds wrong to me. Adding “UL” makes the compiler handle the large number correctly.

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 18, 2025, 6:42pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/12 "2025-12-18T18:42:05Z")

</div>

Can you give me an example of what you're referring to? I'm so new to this that I'm surprised I can even make a basic loop function properly.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [December 18, 2025, 6:56pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/13 "2025-12-18T18:56:16Z")

</div>

Arduino/reference is a very good place to visit. Look for “variables”.

Learn what a “bit”, a “byte”, an “integer”, “long integer” stands for. It’s a common mistake to use the wrong format.

---

<div class="post-metadata">

**Author:** ![blh64](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/blh64/32/605986_2.png) [@blh64](https://forum.arduino.cc/u/blh64)\
**Post date:** [December 18, 2025, 8:18pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/14 "2025-12-18T20:18:35Z")

</div>

> [@mister480v](#):
>
> I don't know how to turn on the "ALL" function on my compiler, just using the Arduino IDE.

File -\> Preferences -\> Compiler Warnings = ALL

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [December 18, 2025, 8:53pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/15 "2025-12-18T20:53:22Z")

</div>

> [@mister480v](#):
>
> but keep getting a timeout error.

When you get timeout, it's quite surely not related to wrong address. Correctly made slave should give an other exception if address is not valid.  
Also, 401506 can only translate to 0x05E1 or 0x05E2. Try them both.

Post more info about your wiring, length, soldered or not, powering, termination resistors used etc...

---

<div class="post-metadata">

**Author:** ![blh64](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/blh64/32/605986_2.png) [@blh64](https://forum.arduino.cc/u/blh64)\
**Post date:** [December 18, 2025, 9:05pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/16 "2025-12-18T21:05:36Z")

</div>

> [@mister480v](#):
>
> `#include <ModbusMaster.h>`

There are several different ModbusMaster libraries. Which one are you using? The one referenced by @van_der_decken allows you to use SoftwareSerial as your Stream. Others do not. They only allow hardware Serial ports.

Another thing you may try is this. Since your proprietary documentation mentions that the leading digit (or digits) still represent the type of Modbus register, 04 = an Input Register, not a Holding Register.

Replace this:

> result = node.readHoldingRegisters(401102, 1);

with

> result = node.readInputRegisters(1102, 1);

Good Luck!

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 18, 2025, 11:53pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/17 "2025-12-18T23:53:52Z")

</div>

I believe the one I'm using allows for SoftwareSerial. I did try to use 1102 as a holding register with no change in status. Wiring does not use a terminating resistor, wiring is about 1 foot, I'm operating at the back of the controller. I removed the remote serial annunciator currently in use before hooking up to the generator controller. The annunciator works fine, but it is programmed to be a Modbus master and you can't have 2 masters on the same line.

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 18, 2025, 11:58pm UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/18 "2025-12-18T23:58:18Z")

</div>

![warnings](https://europe1.discourse-cdn.com/arduino/original/4X/1/f/a/1fafa84cc2c3528b150a86c53c469bfc79658453.png)  
changed to a long and enabled all warnings on the compiler, this is what i get. What does this mean? I understand its maybe expecting a larger integer than what the register is, but this shouldn't affect how the program runs, right?

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 19, 2025, 12:05am UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/19 "2025-12-19T00:05:16Z")

</div>

![holding registers](https://europe1.discourse-cdn.com/arduino/original/4X/f/d/6/fd6893ea3dfb2730711e670dbacd599b6e153573.jpeg)  
manual says they're holding registers, idk

---

<div class="post-metadata">

**Author:** ![mister480v](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mister480v/32/1126588_2.png) [@mister480v](https://forum.arduino.cc/u/mister480v)\
**Post date:** [December 19, 2025, 12:07am UTC](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366/20 "2025-12-19T00:07:23Z")

</div>

So I should be writing my holding registers in HEX format in the program? So instead of 401506, I should be writing (0x05E1,1)?

[Next page](https://forum.arduino.cc/t/arduino-uno-reading-modbus-holding-registers/1420366.md?page=2)
