How can I connect simulink with Arduino Mega2560 ?

5 views (last 30 days)
I am using matlab R2021b and arduino mega2560 , I have designed 1 simple project up and running , but simulink gave error like below :
Anyone help me. Thanks

Answers (1)

Samhitha
Samhitha on 29 Aug 2025
There is a Simulink External Mode connection issue between MATLAB R2021b and Arduino Mega 2560. Here are few ways to resolve it
1.Check the COM Port:
  • Make sure your Arduino is connected to the correct COM port.
  • In Simulink, go to Hardware Settings > Target Hardware Resources > Host-board connection > Set the correct COM port (it should match the one in Device Manager).
2.Close Other Serial Connections:
  • The Arduino IDE Serial Monitor, or another application may be using the COM port.
  • Close the Arduino IDE and make sure only MATLAB/Simulink is using the COM port.
3.Baud Rate Mismatch
  • By default, Simulink external mode uses 115200 baud.
  • If you manually change it in the model or Arduino, make sure both matches. Arduino must be compiled with the same baud rate.
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!