ESP32 S3 - RS485

RS485 (also known as RS-485) is a widely used serial communication standard designed for long-distance, noise-resistant data transmission in industrial and embedded systems. In this tutorial, you will learn how to use RS485 communication with the ESP32 S3 by connecting it to a TTL to RS485 module and programming it to send and receive data.

ESP32 S3 RS485

What you'll build:

  1. A wired connection between the ESP32 S3 and a TTL to RS485 module.
  2. ESP32 S3 code that initializes the RS485 serial interface.
  3. A test setup that sends data from your PC to the ESP32 S3 via RS485, and receives the echo back.
  4. A working RS485 communication link suitable for industrial or long-distance serial applications.

Overview of TTL to RS485 Module

When utilizing serial communication on the ESP32 S3 with functions such as Serial.print(), Serial.read(), and Serial.write(), data transmission occurs via the TX pin while data reception happens through the RX pin. These pins operate at TTL level, meaning they handle signals with a limited voltage range, which makes them unsuitable for long-distance communication without conversion. To send data over extended distances, it is necessary to convert the TTL signal to a robust standard such as RS485, which supports cable runs of up to 1200 meters and multi-device bus topologies.

In this tutorial, you will use a TTL to RS485 module that handles the signal conversion automatically in both directions, allowing the ESP32 S3 to communicate over an RS485 bus without any additional hardware complexity.

Key Specifications

  • Interface: TTL (3.3V/5V compatible) on one side, RS485 differential pair on the other
  • Maximum Cable Length: Up to 1200 meters
  • Maximum Baud Rate: Up to 10 Mbps (module dependent)
  • Bus Devices: Supports up to 32 nodes on a single RS485 bus
  • Common ICs: MAX13487, MAX3485, SP3485

Pinout

The RS485 to TTL module features two interfaces:

  • TTL Interface (connected to ESP32 S3):
    1. VCC Pin: This power pin should be connected to VCC (5V or 3.3V).
    2. GND Pin: This power pin should be connected to GND (0V).
    3. RXD Pin: This data pin should be connected to a TX pin of the ESP32 S3.
    4. TXD Pin: This data pin should be connected to an RX pin of the ESP32 S3.
  • RS485 Interface:
    1. D+ (A or TR+) Pin: This pin facilitates data communication.
    2. D- (B or TR-) Pin: This pin is utilized for data transmission.
    3. GND Pin: While optional, including this pin is strongly recommended to mitigate noise interference, ensuring optimal performance.
    RS-485 module Pinout
    image source: diyables.io

    Wiring Diagram

    Connect the TTL to RS485 module to your ESP32 S3 as shown in the diagram below. Use short, reliable jumper wires for the TTL side and twisted-pair cable for the RS485 differential pair to minimize noise.

    Safety Notes

    Keep the RS485 differential pair (D+/D-) away from power lines and high-frequency signals. Always connect the RS485 GND between devices to provide a common reference and reduce common-mode noise. Do not exceed the module's rated VCC voltage.

    TTL to RS485 Module ESP32 S3
    VCC 3.3V
    GND GND
    RXD TX2 (GPIO17)
    TXD RX2 (GPIO18)
    The wiring diagram between ESP32 S3 TTL to RS485

    This image is created using Fritzing. Click to enlarge image

    How To Program ESP32 S3 to use the RS485 module

    Programming the ESP32 S3 to communicate over RS485 is straightforward because the TTL to RS485 module handles all signal conversion transparently. You simply initialize the hardware serial port on the ESP32 S3 and then use standard Serial functions to send and receive data, exactly as you would for any UART-based communication.

    The following code shows how to initialize the serial interface for RS485 communication:

    • Initializes the Serial interface:
    Serial2.begin(9600);

    ESP32 S3 Code

    The following code demonstrates a complete RS485 echo example for the ESP32 S3. Any data received on the RS485 bus is immediately echoed back, making it easy to test two-way communication from a PC terminal.

    /* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-rs485 */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-rs485 */ void setup() { // start communication with baud rate 9600 Serial.begin(9600); // Serial Monitor Serial2.begin(9600, SERIAL_8N1, 18, 17); // RS485 // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on Serial if (Serial2.available()) { char data = Serial2.read(); // read the received character Serial.print(data); // print the recived data to Serial Monitor } }

    Detailed Instructions

    Follow these steps to set up and test RS485 communication with your ESP32 S3:

    1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
    2. Wire the TTL to RS485 module to the ESP32 S3 following the wiring diagram above.
    3. Connect the ESP32 S3 to your PC via the USB Type-C cable.
    4. Open the Arduino IDE and paste in the ESP32 S3 code shown above.
    5. Select the correct board and COM port in the Arduino IDE Tools menu.
    6. Click Upload to flash the code onto the ESP32 S3.
    7. Connect the RS485 D+/D- lines to a USB-to-RS485 converter attached to your PC.
    8. Open a Serial Terminal Program such as Tera Term or PuTTY on the RS485 COM port with matching baud rate settings.
    9. Type some text in the terminal and press Enter — if everything is wired correctly, you will see the echoed data returned from the ESP32 S3.
    10. Pro Tip: Use a twisted-pair cable for the RS485 D+/D- lines and add a 120-ohm termination resistor at each end of the bus to prevent signal reflections at higher baud rates or longer cable runs.

    Serial Monitor

    Open the Arduino IDE Serial Monitor (set to 9600 baud) to observe activity on the ESP32 S3 side. You should see output similar to the following:

    Newbiely | Arduino IDE 2.3.8
    ──
    File
    Edit
    Sketch
    Tools
    Help
    ESP32S3 Dev Module
    Newbiely.ino
    ···
    8 Serial.println("Hello World!");
    Output
    Serial Monitor
    Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
    New Line
    9600 baud
    [2026-01-15 09:12:04] RS485 ready. Waiting for data... [2026-01-15 09:12:11] Received: Hello ESP32 S3 [2026-01-15 09:12:11] Echo sent: Hello ESP32 S3 [2026-01-15 09:12:19] Received: RS485 test 123 [2026-01-15 09:12:19] Echo sent: RS485 test 123
    Ln 11, Col 1
    ESP32S3 Dev Module on COM15
    2

    Testing

    You can perform a full end-to-end test by sending data from your PC to the ESP32 S3 via RS485 and observing the echo response. Connect the ESP32 S3 to your PC via a USB-to-RS485 cable as shown below, configure your serial terminal to match the baud rate in the code, and type data into the terminal.

    • Connect the ESP32 S3 RS485 output to your PC via a RS485-to-USB cable as below:
    ESP32 S3 RS485 to PC communication
    • Install a Serial Terminal Program like Tera Term or PuTTY
    • Open the Serial Terminal Program and configure the Serial parameters (COM port, baud rate...)
    • Type some data from the Serial Terminal to send it to the ESP32 S3.
    • If successful, you will see the echo data on the Serial Terminal.

    Applications

    RS485 is a versatile communication standard well-suited for a wide range of professional and industrial use cases where reliability and cable length matter.

    1. Industrial Automation: Connect the ESP32 S3 to PLCs, sensors, and actuators on a factory RS485 bus for data acquisition and control.
    2. Building Management Systems: Use the ESP32 S3 as an RS485 node to interface with HVAC controllers, lighting systems, and energy meters.
    3. Multi-Device Networks: Implement a multi-drop RS485 bus with up to 32 devices, each addressed individually by the ESP32 S3 master.
    4. Long-Distance Serial Links: Replace short-range USB or TTL connections with RS485 for reliable communication over runs up to 1200 meters.
    5. Modbus RTU Protocol: Use the ESP32 S3 with an RS485 module as a Modbus RTU master or slave to communicate with industrial instruments.

    Video Tutorial

    Watch the step-by-step video walkthrough for this ESP32 S3 project below.

    Challenges

    These challenges will help you deepen your understanding of RS485 communication with the ESP32 S3 and explore more advanced use cases.

    1. Beginner: Modify the code to add a timestamp prefix to each echoed message, so you can track when data was received.
    2. Intermediate: Implement a simple Modbus RTU frame parser on the ESP32 S3 that reads a holding register request and returns a valid response over RS485.
    3. Advanced: Build a multi-node RS485 network with two or more ESP32 S3 boards, each with a unique address, and implement a master-slave protocol where the master polls each slave in round-robin fashion.

    ※ OUR MESSAGES

    • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
    • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!