Simulink on the host with Simulink Target for Arduino

In this example, Simulink is running on a desktop computer to find the ball, calculate the necessary control commands and then communicate via UDP with an Arduino to control the motors. The buildExecutable function is used to convert the host function into an executable.

Step 1: Deploy the Simulink target model to the Arduino

Open and build the model called targetArduinoSimulink.slx.

Step 2: Run the Simulink host model on the host computer

Open and run the function called hostSimulink.slx

Step 3: Generate an executable out of the MATLAB Function

Stop the model "hostSimulink.slx" by clicking on the stop button.

Run the following command in the MATLAB Command Window:


Step 4: Run the executable hostSimulink.exe in a terminal

Step 5: Run the Simulink Arduino model in External Mode

Set the model "targetArduinoSimulink.slx" to external mode by selecting "External" from the Simulink Mode dropdown.

This will run the code on the Arduino while enabling the user to tune and monitor any signal from the model. In this case, the user will see the motor commands being sent to the Servo Write blocks.

Deployment Options

Note: Try not to run the Simulink host model and the Simulink target model in external mode at the same time. They will interfere with each other.

The options are:

  1. Run Simulink host model on the host computer
  2. Build the target model on the Arduino


  1. Run Simulink host executable on the host computer
  2. Run the target model in External Mode on the Arduino