Serial communication is one of the most common ways to exchange data between electronic devices. However, when distances increase or the environment has electromagnetic interference, communication signals can be prone to errors. That's where the RS485 communication standard comes into play, offering a robust and effective alternative. Arduino, with its versatility, allows us to take full advantage of this protocol quite easily.
In this article, we will see how RS485 communication between multiple Arduinos can be implemented using modules based on the MAX485 chip, a chip that converts TTL signals (from Arduino) to RS485 and vice versa. Throughout this tutorial, we will cover both the basics and practical examples that will allow you to implement simplex, half-duplex and full-duplex communication between Arduino microcontrollers, and explain how you can extend this communication system to handle multiple devices on a single RS485 bus.
What is RS485?
The RS485 It is a communications standard widely used in the industry, known for its sturdiness and its ability to withstand long distance transmission, even in noisy industrial environments. Unlike other types of serial communication, such as RS232, RS485 allows multiple devices to be connected on the same bus, making it ideal for industrial automation and control applications.
This protocol is resistant to electromagnetic noise because it uses a differential signaling system, which means that data is sent over two wires, A and B, that are opposite versions in voltage. This allows any noise picked up on the wires to be easily cancelled out, ensuring signal integrity.
One of the main advantages of RS485 is that Supports distances of up to 1200 meters and speeds of up to 35 Mbps over short distances, making it an ideal protocol for industrial and control applications in environments where long cabling is necessary.
RS485 communication modes

In RS485 communication, we can configure the system in three different ways: simplex, half-duplex and full-duplex. Each has its own particularities and is implemented according to the needs of the project.
Simplex Communication
In simplex mode, communication only goes in one direction, that is, one device acts as transmitter and another like receiverThis is useful in situations where you only want to send or receive data without needing feedback.
For example, we can set up a system where an Arduino reads a sensor value and sends it to another device that simply receives it. In this case, since there is only data traveling in one direction, certain additional control elements can be dispensed with, making the system simpler and cheaper.
Half-Duplex Communication
Most RS485 applications on Arduino are implemented in half-duplex mode because it only requires two wires, and allows you to both send and receive data, although not simultaneously. That is, if one device is sending data, the other devices must be in receiving mode, and vice versa.
To switch between transmit and receive modes, you use additional pins (RE/DE) on the MAX485 module, which you will control from code to determine whether the device should be sending or receiving at any given time.
This mode is especially useful if you have multiple devices on the same bus that need to communicate with each other, but not simultaneously.
Full-Duplex Communication
In full-duplex mode, devices can send and receive data at the same time. However, to implement full-duplex on RS485, a separate set of ports is required. two pairs of twisted threads, which increases wiring cost and complexity. Additionally, you will need two MAX485 modules per device to manage the transmit and receive channels separately.
Components needed for RS485 communication with Arduino
To implement an RS485 communication system on Arduino, you will need the following components:
- One or more Arduinos: Any Arduino model will do, but in this tutorial we will use Arduino UNO and Arduino MEGA as examples.
- MAX485 Modules: These modules allow you to convert Arduino TTL signals to RS485 and vice versa. They are very cheap and easy to find in stores like AliExpress or eBay.
- Terminating resistors: A 120 ohm resistor is usually placed at each end of the bus to prevent reflections in the signal. For short distances, they can be dispensed with, but for longer installations they are essential to maintain signal integrity.
- Twisted pair cables: It is recommended to use twisted pair cables to minimize electromagnetic interference, especially in noisy industrial environments.
General connection diagram
Connecting MAX485 modules to an Arduino is pretty straightforward. The most important pins are A and B, which correspond to the RS485 bus lines. These pins need to be connected to all devices on the bus. Additionally, the module has RE and DE pins that control whether the module is in receiver or transmitter mode.
In general, the connection of the modules to the Arduino is done as follows:
- VCC and GND on the module connect to VCC and GND on the Arduino.
- DI (Data Input) of the module is connected to the Arduino TX pin if the module is going to act as a transmitter.
- RO (Receiver Output) of the module is connected to the Arduino RX pin if the module is to act as a receiver.
- DE and RE must be controlled from an Arduino digital pin to toggle between transmit and receive modes.
If you only need the module to function as a transmitter or receiver, you can connect RE and DE directly to HIGH or LOW. However, for more complex communications where the device has to switch between transmitting and receiving, it is best to control these pins from software.
Code examples for RS485 communication
Below are several examples covering the different RS485 communication configurations on Arduino.
Simplex Communication
Issuer code
For a basic simplex system where we only have one sender and one receiver, the code for the sender might look like this:
void setup() { Serial.begin(9600); } void loop() { Serial.write(analogRead(0)); delay(500); }
Receiver code
The receiver will simply read the data coming through the serial port:
void setup() { Serial.begin(9600); } void loop() { if (Serial.available()) { int data = Serial.read(); Serial.println(data); } }
Half-Duplex Communication
In this example, we implement a half-duplex system where devices alternate between sending and receiving data.
Master Code
const int reDePin = 2; void setup() { pinMode(reDePin, OUTPUT); Serial.begin(9600); } void loop() { digitalWrite(reDePin, HIGH); Serial.write('H'); delay(100); digitalWrite(reDePin, LOW); if (Serial.available()) { int data = Serial.read(); Serial.println(data); } }
Slave Code
const int reDePin = 2; void setup() { pinMode(reDePin, OUTPUT); Serial.begin(9600); } void loop() { digitalWrite(reDePin, LOW); if (Serial.available()) { int data = Serial.read(); delay(100); digitalWrite(reDePin, HIGH); Serial.write(data + 1); } }
Full-Duplex Communication
To implement full-duplex communication, two MAX485 modules will be needed per Arduino. Each pair of modules will handle one data line: one for transmitting and one for receiving.
The code will be similar to the previous examples, but in this case both devices would always be transmitting and receiving simultaneously.
Expansion to multiple devices on RS485
RS485 has the ability to connect up to 32 devices on a single bus, and in special cases it can go up to more. This makes it an excellent choice for projects involving multiple microcontrollers or devices. To identify each of them on the network, it is common to implement an address or ID for each device.
In this case, the master will send a message with the address of the device with which it wants to communicate, and only that device will be responsible for processing the message and giving a response.
Added to this is the possibility of using more complex protocols such as MODBUS, which allow for the creation of highly efficient and secure networks in the industry.
For home projects or less demanding applications, you can simply assign an identifier to each Arduino and have them respond only to messages intended for them.