Build a Polled RS485 Sensor Network with Arduino: Wiring, Turnaround and Timeouts
RS485 is useful when several controllers need to communicate along a cable. A simple polled sensor network is a good first project: one controller asks a particular node for a reading, that node replies, and every other node remains quiet. This makes bus ownership and failures easier to understand than having every device transmit whenever it likes.
The PMD Way RS485 shield collection includes an RS485 and XBee shield. Its different interfaces and power connections need to be identified independently. Do not treat a connector marked for power as a data pair, or assume that fitting the shield automatically defines a network protocol.
Separate the electrical link from the messages
RS485 specifies electrical characteristics rather than an application message format. Texas Instruments’ RS485 design guide explains the differential interface and common bus arrangements. Nodes still need to agree on serial settings, addresses, message boundaries and response behaviour.
For a private learning network, a small documented request-and-response format can be sufficient. If connecting commercial equipment, use its documented protocol and register definitions instead. “RS485 compatible” does not mean arbitrary bytes will be understood.
Start with two nodes on the bench. Add more only after the first request and response work reliably and you can explain how the transmitter releases the bus.
Verify the terminals before connecting a cable
Identify the differential data connections, signal reference and any separate supply terminals from the actual board markings and schematic. A/B naming conventions are not applied consistently across all products, so compare the equipment documentation rather than relying on letters alone.
The linked shield’s catalogue wording mixes RS485 terminal and supply descriptions. Do not use that wording as a wiring diagram. Obtain the correct mapping for the supplied revision before applying power or connecting another device.
With power removed, inspect the jumpers and check the intended path. The listing describes host UART routing through D1/TX and D0/RX in its RS485 setting, but verify how that relates to your particular Arduino and any upload or monitoring connection.
Use a suitable bus layout
Arrange a main twisted-pair cable with short connections to the nodes. For a conventional terminated network, match the termination to the cable and place it at the ends, rather than fitting a resistor at every device. Check which boards already include termination.
Biasing and termination solve different problems. The first establishes a defined idle condition where required; the second controls reflections. TI’s RS485 design questions explains idle-bus behaviour and isolation considerations.
Provide the reference, protection and isolation arrangement appropriate to the installation. Differential signalling does not make arbitrary ground-potential differences harmless. A bench experiment with a short cable is not a qualification test for a long outdoor installation.
Control transmit direction deliberately
On a half-duplex pair, nodes take turns driving the cable. Some interfaces manage direction automatically; others expose driver and receiver enable controls. Determine which arrangement the shield uses before selecting software.
The essential sequence is to enable the driver, send the complete message, wait until the final bit has left the UART and then release the driver. Releasing too early truncates the message; releasing too late can interfere with the reply.
Arduino’s Serial.flush reference describes waiting for outgoing serial transmission to finish in supported Arduino implementations. Confirm the behaviour of the actual serial class and library you are using. An application transmit buffer becoming empty is not always the same event as the wire becoming idle.
Give each request an identity
A useful request can contain a destination address, command and sequence number. The response echoes enough information to show which request it answers. Add a defined integrity check and enforce a maximum message length.
For example, a controller may ask node 3 for its temperature using sequence 41. The reply should identify node 3, sequence 41, the measurement and its validity. If an old reply arrives late, the controller can reject it rather than attach it to the next request.
Define units and scaling. An integer of 237 might represent 23.7 °C if the protocol says so, but it should not depend on an undocumented assumption. Also specify how the node reports a disconnected or failed sensor.
Design timeouts around the whole exchange
The response allowance must cover request transmission, turnaround, processing and reply transmission, plus an appropriate margin. Choosing an arbitrary short timeout can produce retries even when the network is behaving normally.
As a calculation example, ten bytes using eight data bits, no parity and one stop bit occupy 100 serial bits including start bits. At 9,600 bit/s that is approximately 10.4 milliseconds of wire time, before any processing or turnaround.
After a timeout, record the failed node and continue a defined recovery policy. Avoid blocking all other sensors forever because one device is absent. Limit retries so that a failed node does not monopolise the bus.
Keep receive handling bounded
| Condition | Useful response |
|---|---|
| Incomplete message | Discard it after a defined inter-byte or overall timeout. |
| Excessive length | Reject it without writing beyond the receive buffer. |
| Wrong destination | Remain silent unless the protocol defines another action. |
| Failed integrity check | Reject the content and increment an error counter. |
| Unsupported command | Return a defined error only when addressed appropriately. |
Keep diagnostics separate from the data channel. Printing human-readable debugging text onto a shared network can create malformed messages or collisions.
Test faults before increasing the node count
Disconnect one node, restart it and deliberately delay a response in the test firmware. Confirm that the controller keeps serving the other nodes and accepts the returning device cleanly. Watch error counters while adding normal application work.
Save the terminal map, jumper settings, serial configuration and protocol description together. A dependable RS485 network is one where wiring, bus ownership and missing-message behaviour are all explicit.