RS485 Modbus Arduino interfacing opens the door to industrial-grade sensor communication. Unlike hobbyist I2C or SPI sensors, RS485 Modbus sensors are designed for harsh factory environments — they can communicate over cable runs of up to 1200 metres, withstand electrical noise from heavy machinery, and support daisy-chaining of up to 247 devices on a single bus. This guide covers everything you need to connect industrial Modbus sensors to Arduino for factory monitoring, energy metering, and environmental control applications across India.
Table of Contents
- What is RS485?
- Understanding Modbus RTU Protocol
- Hardware: RS485 Modules for Arduino
- Wiring RS485 Sensors to Arduino
- Reading a Modbus Temperature Sensor
- Multiple Devices on One Bus
- Troubleshooting Modbus Communication
- Frequently Asked Questions
What is RS485?
RS485 (also written RS-485 or EIA-485) is a serial communication standard designed for long-distance, noise-immune data transmission. Unlike RS232 which uses single-ended signalling, RS485 uses differential signalling on a twisted pair cable — the receiver looks at the voltage difference between the two wires (A and B), making it immune to common-mode noise from motors, inverters, and power lines.
Key advantages of RS485:
- Distance: Up to 1200 metres (vs 15 m for RS232, 30 cm for I2C)
- Noise immunity: Differential signalling rejects electromagnetic interference
- Multi-drop: Up to 32 devices (standard) or 256 devices (high-impedance) on one bus
- Half-duplex: Two-wire communication (A, B) — simple wiring
- Industry standard: Used in factories, HVAC systems, energy meters, and building automation worldwide
Understanding Modbus RTU Protocol
Modbus is a communication protocol that runs on top of RS485. It defines how devices request and send data. There are two variants:
- Modbus RTU: Binary format, compact, used with RS485 serial links (this guide)
- Modbus TCP: Runs over Ethernet/WiFi, same register model
Modbus uses a master-slave architecture. The Arduino (master) sends a request to a specific slave device (identified by its address 1-247), and the slave responds with the requested data.
Modbus Function Codes
| Code | Function | Use Case |
|---|---|---|
| 0x01 | Read Coils | Read relay/switch states |
| 0x02 | Read Discrete Inputs | Read digital inputs |
| 0x03 | Read Holding Registers | Read sensor values (most common) |
| 0x04 | Read Input Registers | Read measurement data |
| 0x06 | Write Single Register | Change device settings |
| 0x10 | Write Multiple Registers | Batch configuration |
Hardware: RS485 Modules for Arduino
Arduino does not have a native RS485 interface. You need an RS485 transceiver module that converts between UART (TTL) serial and RS485 differential signals. The most common chip is the MAX485.
MAX485 Module Pinout
| Pin | Function | Connect To |
|---|---|---|
| DI | Data In (TTL TX) | Arduino TX pin |
| RO | Receiver Out (TTL RX) | Arduino RX pin |
| DE | Driver Enable | Arduino digital pin (direction control) |
| RE | Receiver Enable (active LOW) | Connected to DE pin |
| A | RS485 Data+ | Sensor A terminal |
| B | RS485 Data- | Sensor B terminal |
DE and RE are typically shorted together and controlled by a single Arduino pin: HIGH = transmit mode, LOW = receive mode.
Wiring RS485 Sensors to Arduino
Here is the complete wiring for reading a Modbus temperature/humidity sensor:
Arduino Uno → MAX485 Module → Modbus Sensor
Arduino 5V → MAX485 VCC
Arduino GND → MAX485 GND
Arduino D3 → MAX485 DI (TX)
Arduino D2 → MAX485 RO (RX)
Arduino D8 → MAX485 DE + RE (direction)
MAX485 A → Sensor A (Data+)
MAX485 B → Sensor B (Data-)
Arduino GND → Sensor GND (if sensor has separate power)
Cable: Use twisted pair cable (Cat5e Ethernet cable works well — use one pair for A and B). For runs over 50 metres, add a 120 ohm termination resistor at each end of the bus.
Reading a Modbus Temperature Sensor
Install the ModbusMaster library from the Arduino Library Manager. Here is code to read a typical industrial temperature/humidity sensor:
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
#define DE_RE_PIN 8
#define RX_PIN 2
#define TX_PIN 3
SoftwareSerial rs485Serial(RX_PIN, TX_PIN);
ModbusMaster node;
// Called before Modbus transmission
void preTransmission() {
digitalWrite(DE_RE_PIN, HIGH); // Enable transmitter
}
// Called after Modbus transmission
void postTransmission() {
digitalWrite(DE_RE_PIN, LOW); // Enable receiver
}
void setup() {
Serial.begin(9600);
rs485Serial.begin(9600); // Most Modbus sensors use 9600 baud
pinMode(DE_RE_PIN, OUTPUT);
digitalWrite(DE_RE_PIN, LOW); // Start in receive mode
// Modbus slave address = 1 (default for most sensors)
node.begin(1, rs485Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
Serial.println("Modbus RTU Sensor Reader - Zbotic.in");
}
void loop() {
uint8_t result;
// Read 2 registers starting at address 0x0000
// Register 0: Temperature (x10)
// Register 1: Humidity (x10)
result = node.readInputRegisters(0x0000, 2);
if (result == node.ku8MBSuccess) {
float temperature = node.getResponseBuffer(0) / 10.0;
float humidity = node.getResponseBuffer(1) / 10.0;
Serial.print("Temperature: ");
Serial.print(temperature, 1);
Serial.print(" C | Humidity: ");
Serial.print(humidity, 1);
Serial.println(" %");
} else {
Serial.print("Modbus Error: 0x");
Serial.println(result, HEX);
}
delay(2000);
}
Multiple Devices on One Bus
The beauty of RS485 is daisy-chaining. Connect multiple sensors using just 2 wires (A and B):
Arduino ──→ MAX485 ─── A ──┬── Sensor 1 (addr 1)
B ──┤
├── Sensor 2 (addr 2)
├── Sensor 3 (addr 3)
└── Sensor 4 (addr 4)
[120Ω terminator]
// Reading from multiple sensors
ModbusMaster sensor1, sensor2, sensor3;
void setup() {
rs485Serial.begin(9600);
sensor1.begin(1, rs485Serial); // Address 1
sensor2.begin(2, rs485Serial); // Address 2
sensor3.begin(3, rs485Serial); // Address 3
// Set pre/post transmission callbacks for all
sensor1.preTransmission(preTransmission);
sensor1.postTransmission(postTransmission);
sensor2.preTransmission(preTransmission);
sensor2.postTransmission(postTransmission);
sensor3.preTransmission(preTransmission);
sensor3.postTransmission(postTransmission);
}
void loop() {
readSensor(sensor1, "Cold Room");
delay(100); // Small gap between requests
readSensor(sensor2, "Warehouse");
delay(100);
readSensor(sensor3, "Production Line");
delay(5000);
}
void readSensor(ModbusMaster &sensor, const char* location) {
uint8_t result = sensor.readInputRegisters(0x0000, 2);
if (result == sensor.ku8MBSuccess) {
Serial.printf("%s: %.1fC, %.1f%%n", location,
sensor.getResponseBuffer(0) / 10.0,
sensor.getResponseBuffer(1) / 10.0);
}
}
Troubleshooting Modbus Communication
- No response at all: Check A/B wiring (some sensors label them differently). Verify baud rate matches the sensor datasheet (common: 4800, 9600, 19200). Ensure DE/RE pin goes LOW after transmission to enable receiving.
- CRC errors: Check for loose connections, use twisted pair cable, and add 120 ohm termination resistors at both ends for cable lengths over 10 metres.
- Timeout errors: Increase the response timeout. Some sensors take 200-500 ms to respond. Add
delay(100)between consecutive reads to different devices. - Wrong values: Check the register address and data format in the sensor datasheet. Some sensors use register address 0x0000 while others start at 0x0001. Values might be signed (int16) or unsigned (uint16).
- Works with one sensor, fails with multiple: Each sensor must have a unique address (1-247). Change addresses using the sensor’s configuration tool or Modbus write register command.
Frequently Asked Questions
What cable should I use for RS485?
Use shielded twisted pair cable. Cat5e Ethernet cable (use one pair for A/B, connect shield to GND at one end only) works well for most installations. For industrial environments, use dedicated RS485 cable rated for the distance needed.
What is the maximum cable length for RS485?
RS485 supports up to 1200 metres at 9600 baud. At higher baud rates, maximum distance decreases. For most factory sensor networks in India, 100-300 metre runs are typical and work flawlessly.
Can I use ESP32 instead of Arduino for Modbus?
Yes, and it is often better. ESP32 has multiple hardware serial ports, so you do not need SoftwareSerial. Plus, ESP32 can forward Modbus data to WiFi/MQTT for cloud monitoring. Use Serial2 (GPIO 16/17) for the RS485 connection.
What is the difference between Modbus RTU and Modbus ASCII?
Modbus RTU uses binary encoding and is more efficient (fewer bytes per message). Modbus ASCII uses hexadecimal text encoding and is easier to debug but slower. RTU is the standard for sensor communication; ASCII is rarely used in new installations.
How do I change a Modbus sensor’s slave address?
Most sensors allow address changes by writing to a configuration register (often register 0x0100 or similar). Check the sensor datasheet. Use function code 0x06 (Write Single Register) with the current address to set the new address.
Conclusion
RS485 Modbus communication bridges the gap between Arduino hobbyist projects and industrial automation. With a ₹50 MAX485 module, you can read data from professional-grade sensors that are used in factories, cold storage facilities, and HVAC systems across India. The long cable runs, noise immunity, and multi-device support make RS485 the right choice for any project that needs to extend beyond the bench.
Explore our range of industrial communication modules at Zbotic.in — from RS485 converters to Modbus relay modules, we have everything for your industrial IoT project.
Add comment