Arduino UNO R4 RS232

In this tutorial, we will learn how to use RS232 communication with Arduino UNO R4. We will cover:

The tutorial gives guidance on using both Hardware Serial and SoftwareSerial.

Arduino UNO R4 RS-232

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×TTL to RS232 Module
1×Jumper Wires
1×(Optional) RS232 to USB Cable
1×(Optional) RS232 Gender Changer
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of TTL to RS232 Module

When using the Serial.print(), Serial.read(), Serial.write() functions on Arduino UNR R4, it sends out data through the TX pin or receives data from the RX pin. The signals on these pins are TTL level, which cannot travel long distances. To communicate over longer distances, you need to convert the TTL signal to RS232, RS485, or RS422 signals.

The TTL-to-RS232 module changes TTL signals into RS232 signals, and also does the opposite.

Pinout

The RS232 to TTL module features two types of connections:

  • The TTL interface, which connects to Arduino UNG R4, has 4 pins:
    • VCC pin: This is the power pin. Connect it to the VCC (5V).
    • GND pin: This is the power pin. Connect it to the GND (0V).
    • RXD pin: This is the data pin. Connect it to the RX pin on the Arduino UNO R4.
    • TXD pin: This is the data pin. Connect it to the TX pin on the Arduino UNO R4.
  • The RS232 interface has a DB9 female D-Sub connector. Connect this to your serial device.
RS232 Pinout

Wiring Diagram

  • If you are using hardware serial, here is the wiring diagram.
The wiring diagram between Arduino UNO R4 TTL to RS232

This image is created using Fritzing. Click to enlarge image

  • Wiring diagram for using software serial
The wiring diagram between Arduino UNO R4 RS232 to TTL

This image is created using Fritzing. Click to enlarge image

How To Program Arduino UNO R4 to use the RS232 module

  • Sets up the Serial connection.
Serial.begin(9600);
  • To use SoftwareSerial, first include the library and then create a SoftwareSerial object.
#include <SoftwareSerial.h> SoftwareSerial SoftSerial(7, 6); // RX on pin 7, TX on pin 6

Arduino UNO R4 Code for Hardware Serial

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-rs232 */ void setup() { // start communication with baud rate 9600 Serial.begin(9600); // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on Serial if (Serial.available()) { char data = Serial.read(); // read the received character Serial.print(data); // echo back to data to the sender } }

Arduino UNO R4 Code for Software Serial

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-rs232 */ #include <SoftwareSerial.h> SoftwareSerial SoftSerial(7, 6); // RX: 7, TX: 6 void setup() { // start communication with baud rate 9600 SoftSerial.begin(9600); // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on SoftSerial if (SoftSerial.available()) { char data = SoftSerial.read(); // read the received character SoftSerial.print(data); // echo back to data to the sender } }

Testing

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the Arduino Uno R4 to the TTL-to-RS232 module according to the provided diagram.
  • Connect the Arduino Uno R4 to board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the provided code and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to transfer the code to the Arduino UNO R4.

To perform a test where you send data between your PC and Arduino UNO R4 using RS232, follow these steps:

  • Connect the Arduino UNO R4 to your computer using the RS232-to-USB cable as shown:
Arduino UNO R4 RS232 to PC communication
  • Download a Serial Terminal Program such as Tera Term or PuTTY.
  • Open the Serial Terminal Program and set up the Serial parameters (COM port, baud rate, etc.).
  • Enter some data in the Serial Terminal to send to the Arduino UNO R4.
  • If it works, you will see the echoed data appear on the Serial Terminal.

Video Tutorial

※ 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!