Modbus Read Input Registers Returns Zeroes
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about Modbus Read Input Registers Returns Zeroes. We cover key concepts, practical examples, and best practices.
The Problem
Modbus Function Code 04 (Read Input Registers) always returns 0.
Quick Fix
Wrong
// Reading input registers via FC 03 instead of FC 04
mb.readHoldingRegisters(1, 0, 1, data);```
Returns 0 or incorrect values (holding register space, not input space).
### Right
```cpp
#include <ModbusRtu.h>
Modbus master(1, Serial, 2);
void setup() {
master.begin(9600, SERIAL_8N1);
Serial.begin(9600);
}
void loop() {
// Read Input Registers (FC 04)
// Input registers are READ-ONLY — these are sensor values
uint16_t inputs[4];
int result = master.readInputRegisters(1, 0, 4, inputs);
if (result == 0) {
Serial.print("Temperature: ");
Serial.print(inputs[0] / 10.0); // Fixed-point: 255 = 25.5 C
Serial.println(" C");
Serial.print("Humidity: ");
Serial.print(inputs[1] / 10.0);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(inputs[2]);
Serial.println(" hPa");
} else {
Serial.print("FC 04 error: ");
Serial.println(result);
}
delay(2000);
}```
Temperature: 25.5 C Humidity: 65.3 % Pressure: 1013 hPa
## Prevention
Modbus FC 04 reads input registers (read-only). These are typically sensor values: temperature, humidity, pressure, etc. Input registers are 16-bit (uint16_t). They are in a separate address space from holding registers. Always use FC 04 for input registers, FC 03 for holding registers. Sensor values are often encoded in fixed-point (e.g., 255 = 25.5 C).
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
## FAQ
<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">### FC 04 vs FC 03?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>FC 04 = Read Input Registers (read-only sensor data). FC 03 = Read Holding Registers (read/write configuration). Different address spaces.</p>
<h3 id="what-data-format-for-sensors">What data format for sensors?</h3><p>Common: signed 16-bit integer, unsigned 16-bit integer, fixed-point (value/10), or IEEE 754 float (two consecutive registers). Check the device manual.</p>
<h3 id="can-i-write-to-input-registers">Can I write to input registers?</h3><p>No. Input registers are read-only. The name 'input' means input to the system from sensors, not input from the master.</p>
</div></details>
← Previous
Modbus Read Holding Registers Returns Exception Code 02
Next →
Modbus Write Single Coil Returns Exception Code 01
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro