Documentation Center

  • Trial Software
  • Product Updates

Contents

Use Serial Communications with Arduino Hardware

Arduino® hardware has serial ports, also known as UARTs, that can communicate with other devices that have serial interfaces.

Hardware

The Arduino Uno board has one serial port, serial port 0, connected to:

  • The digital pins marked TX 1 (transmit) and RX 0 (receive).

  • The USB port, through a serial-to-USB converter.

The Arduino Nano board has

  • The digital pins marked TX 1 (transmit) and RX 0 (receive).

The Arduino Mega 2560 and Arduino Due board have four serial ports:

  • Serial port 0 is connected to Communication pins marked TX0 1 (transmit) and RX0 0 (receive). Serial port 0 is also connected to the USB port through a converter.

  • Serial port 1 is connected to Communication pins marked TX1 18 (transmit) and RX1 19 (receive).

  • Serial port 2 is connected to Communication pins marked TX2 16 (transmit) and RX2 17 (receive).

  • Serial port 3 is connected to Communication pins marked TX3 14 (transmit) and RX3 15 (receive).

You can use serial port 0 to communicate with other devices that have serial ports, or to communicate with a computer over the USB port.

Each serial port supports one Serial Transmit and one Serial Receive block, one block per pin.

If you intend to use External mode with Arduino Mega 2560 or Arduino Due hardware, use serial ports 1 through 3 for serial communications. Serial port 0 is not available for serial communications because it is connected to the USB port, which External mode uses to communicate with the host computer. This restriction does not apply to Arduino Uno hardware, because External mode is not supported. For more information, see Tune and Monitor Model Running on Arduino Mega 2560 Hardware.

Serial communications are not supported in models that also use the Arduino Standard Servo Read, Standard Servo Write, and Continuous Servo Write blocks.

    Warning   Do not connect the serial port pins to an RS-232 serial interface, such as the DE-9M connector on a computer, without limiting the voltage. The RS-232 standard allows higher voltages that can damage your hardware. For details, read the documentation for your Arduino hardware.

Transmit Serial Data

To transmit data through a serial port or USB port on the Arduino hardware:

  1. Add the Arduino Serial Transmit block to your model.

  2. Connect a data source to the block input on the Serial Transmit block.

    If the data type is not uint8, use a Data Type Conversion block to convert it to uint8.

  3. In the Arduino Serial Transmit block, select a Port number.

  4. Click the Tools menu in the model, and select Run on Target Hardware > Options.

    In the Configuration Parameters dialog that opens, on the Run on Target Hardware pane, set the baud rate for the serial port you selected in the Arduino Serial Transmit block.

  5. Connect the appropriate digital transmit pin to the hardware that receives the data.

  6. Run the model, as described in Run Model on Arduino Hardware.

  7. If your model uses the Arduino USB port (Serial port 0) to transmit data to a device that is not your host computer, reconnect the USB cable to that device and press the RESET button.

Receive Serial Data

To receive data through a serial port or USB port on the Arduino hardware:

  1. Add the Arduino Serial Receive block to your model.

  2. On the Arduino Serial Receive block, connect the Data block output to a block that uses the data.

  3. Open the Arduino Serial Receive block and specify the Port number.

  4. Click the Tools menu in the model, and select Run on Target Hardware > Options.

    In the Configuration Parameters dialog that opens, on the Run on Target Hardware pane, set the baud rate for the serial port you selected in the Arduino Serial Receive block.

  5. Connect the digital receive pin to the hardware that transmits the data.

  6. Run the model, as described in Run Model on Arduino Hardware.

  7. If your model uses the Arduino USB port (Serial port 0) to receive data from a device that is not your host computer, reconnect the USB cable to that device and press the RESET button.

Was this topic helpful?