Arduino Nano 33 IoT - RS232

In this guide, we will learn how to use RS232 communication with the Arduino Nano 33 IoT. Specifically, we will learn:

Arduino Nano 33 IoT - RS232

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×TTL to RS232 Module
1×Jumper Wires
1×Breadboard
1×Optionally, RS232 to USB Cable
1×Optionally, RS232 Gender Changer
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

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 you use serial communication functions like Serial.print(), Serial.read(), or Serial.write() on the Arduino Nano 33 IoT, the board sends data from the TX pin and receives data on the RX pin. The signals on these pins are at TTL level, which means they are only good for short distances. So, if you want to use serial communication over a long distance, you need to change the TTL signal into an RS232, RS485, or RS422 signal.

This module changes a TTL signal into an RS232 signal, and it can also change an RS232 signal back into a TTL signal.

Pinout

The RS232 to TTL module has two ports:

  • The TTL interface (connected to the Arduino Nano 33 IoT) has 4 pins:
  • VCC pin: This is the power pin. Connect it to VCC (5V/3.3V).
  • GND pin: This is the ground pin. Connect it to GND (0V).
  • RXD pin: This is a data pin. Connect it to the RX pin on the Arduino Nano 33 IoT.
  • TXD pin: This is a data pin. Connect it to the TX pin on the Arduino Nano 33 IoT.
  • The RS232 interface uses a DB9 female D-Sub connector. Connect this to your serial device.
RS232 Pinout

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT TTL to RS232

This image is created using Fritzing. Click to enlarge image

How To Program Arduino Nano 33 IoT to use the RS232 module

  • Set up the pins for serial communication:
#define RX1PIN D3 #define TX1PIN D2
  • Sets up the serial connection:
Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN); // Initialize RS232 serial communication
  • To read data from RS232, you can use these functions:
    • Serial.read() – Reads one byte.
    • Serial.readBytes() – Reads multiple bytes.
    • Serial.readBytesUntil() – Reads bytes until it finds a specific character.
    • Serial.readString() – Reads text data.
    • Serial.readStringUntil() – Reads text data until it finds a specific character.
  • To write data to RS232, you can use these functions:
    • Serial.print() – Sends data without a new line.
    • Serial.println() – Sends data and then adds a new line.
    • Serial.write() – Sends data in byte format.
  • For more functions and details on using RS232, see the Serial reference at https://arduinogetstarted.com/reference/arduino-33-iot-serial.

Arduino Nano 33 IoT Code for RS232

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-rs232 */ #define RX1PIN 3 #define TX1PIN 2 void setup() { // start communication with baud rate 9600 Serial.begin(9600); // Serial Monitor Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN); // RS232 // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on Serial1 if (Serial1.available()) { char data = Serial1.read(); // read the received character Serial1.print(data); // echo back to data to the sender Serial.print(data); // print the recived data to Serial Monitor } }

Testing

You can run a simple test by sending data back and forth between your computer and the Arduino Nano 33 IoT using RS232. Follow these steps:

  • Plug the Arduino Nano 33 IoT into your computer with an RS232-to-USB cable as shown in the picture below.
Arduino Nano 33 IoT RS232 to PC communication
  • Install a Serial Terminal Program like Tera Term or PuTTY. Open the program and set the serial settings (for example, COM port and speed). Type some information into the Serial Terminal to send it to the Arduino Nano 33 IoT. If everything works, you will see the same information come back 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!