Use Serial Communication with Arduino Hardware
Arduino® hardware has serial ports, also known as UARTs, that can communicate with other devices that have serial interfaces.
Hardware
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. You can run your model in the External mode for all the Arduino boards. To know pin mapping for different Arduino boards, see Pin Mapping Table in: Pin Mapping for Arduino Timer Independent 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:
Add the Serial Transmit block to your model.
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.
In the Arduino Serial Transmit block, select a Port number.
Click the Tools menu in the model, and select Run on Target Hardware Options.
In the Configuration Parameters dialog that opens, on the Hardware Implementation > Serial port properties, set the baud rate for the serial port you selected in the Arduino Serial Transmit block.
Connect the appropriate digital transmit pin to the hardware that receives the data.
Run the model, as described in Run Model on Arduino Hardware.
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:
Add the Serial Receive block to your model.
On the Arduino Serial Receive block, connect the Data block output to a block that uses the data.
Open the Arduino Serial Receive block and specify the Port number.
Click the Tools menu in the model, and select Run on Target Hardware > Options.
In the Configuration Parameters dialog that opens, on the Hardware Implementation > Serial port properties, set the baud rate for the serial port you selected in the Arduino Serial Receive block.
Connect the digital receive pin to the hardware that transmits the data.
Run the model, as described in Run Model on Arduino Hardware.
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.