Projects / RS-232 to Wi-Fi bridge

RS-232 to Wi-Fi bridge

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Read the manual

    Note baud rate, format and cable type.

  2. ESP32

    Wire the level converter

    Check TXD and RXD against the pins.

  3. ESP32

    Test with a loopback

    Join TX and RX on the DB9 and echo text.

  4. ESP32

    Connect the instrument

    See its data on the serial monitor.

  5. ESP32

    Add Wi-Fi

    Print the bridge address.

  6. ESP32

    Connect from a PC

    Use nc or PuTTY raw to the port.

  7. ESP32

    Log to a file

    Redirect the output to a text file.

In short

How do you build an RS-232 to Wi-Fi bridge?

Connect an old instrument or machine with an RS-232 port to Wi-Fi so its data reaches a PC. You need ESP32 DevKit V1, RS232 to TTL module (MAX3232) and 5 V 2 A USB adapter. It takes 7 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
3

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
MAX3232 module VCCESP32 3V3Power (3.3 V works with a MAX3232)
MAX3232 module GNDESP32 GNDGround
MAX3232 TXDESP32 GPIO16 (UART2 RX)Data from the instrument
MAX3232 RXDESP32 GPIO17 (UART2 TX)Data to the instrument
Module DB9 or screw terminalsInstrument's RS-232 portUse a straight or null-modem cable as the manual says
5 V adapterESP32 USBPower

Code

RS-232 uses voltages of roughly plus and minus 5 to 15 V, which would damage the ESP32, so the MAX3232 module converts them to 3.3 V logic. Check the instrument's manual for its baud rate, data bits, parity and whether it needs a straight or null-modem (crossed) cable; if no data arrives, swapping TX and RX is the usual fix. The bridge opens a plain TCP port with no password or encryption, so anyone on the same network can read or send to the instrument. Use it only on a trusted network, put it on its own guest network if the instrument is important, and never expose the port to the internet. Do not use this for equipment that controls anything dangerous. Fill in the Wi-Fi placeholders yourself and keep them out of shared code. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// RS-232 to Wi-Fi bridge: TCP port 2323 <-> UART2. Board: ESP32 Dev Module. No extra libraries.
#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const long BAUD = 9600;                       // match your instrument (check its manual)
const uint32_t FORMAT = SERIAL_8N1;           // 8 data bits, no parity, 1 stop bit; change if needed

WiFiServer server(2323);
WiFiClient client;

void setup() {
  Serial.begin(115200);
  Serial2.begin(BAUD, FORMAT, 16, 17);        // RX = GPIO16, TX = GPIO17
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) delay(300);
  Serial.print("Bridge address: "); Serial.println(WiFi.localIP());
  server.begin();
}

void loop() {
  if (!client || !client.connected()) {
    WiFiClient c = server.available();
    if (c) { client.stop(); client = c; Serial.println("Client connected"); }   // newest client wins
  }
  if (client && client.connected()) {
    while (client.available()) Serial2.write(client.read());   // network to instrument
  }
  while (Serial2.available()) {                                // instrument to network
    int b = Serial2.read();
    if (client && client.connected()) client.write((uint8_t)b);
  }
}

/* On the PC: log everything the instrument sends to a file (Linux or macOS):
   nc 192.168.1.50 2323 >> instrument-log.txt
   On Windows use PuTTY in Raw mode, or a short Python script with the socket module. */

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Bridge address: 192.168.1.42

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
LoopbackWhat you type returns
Instrument sends dataAppears in the PC log
Send a command from the PCInstrument responds
Wi-Fi dropsBridge reconnects after the client reconnects

If it does not work

No data

Swap TX and RX or use a null-modem cable.

Garbled data

Match baud rate and parity to the manual.

Cannot connect

Check the IP address and that the PC is on the same network.

Missed data

Increase the buffer or lower the instrument's rate.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the RS-232 to Wi-Fi bridge?

ESP32 DevKit V1, RS232 to TTL module (MAX3232) and 5 V 2 A USB adapter.

How long does the RS-232 to Wi-Fi bridge take to build?

About 120 minutes for a intermediate maker, in 7 steps.

How do I know the RS-232 to Wi-Fi bridge works?

Loopback: What you type returns. Instrument sends data: Appears in the PC log. Send a command from the PC: Instrument responds.

No data: what should I check?

Swap TX and RX or use a null-modem cable.

Garbled data: what should I check?

Match baud rate and parity to the manual.

Cannot connect: what should I check?

Check the IP address and that the PC is on the same network.

Missed data: what should I check?

Increase the buffer or lower the instrument's rate.