Simple robot controlled by MatLab

Few tips how to connect a Arduino based simple robot to MatLab.

  • Connect the Arduino board to the computer

hint Connect the Arduino board with a bluetooth module

  • Connect a bluetooth module to the Arduino board
  • Connect the  Arduino board to the computer. Light of LEDs on Arduino and the bluetooth module should indicated the power is “on”
  • Pair the computer with the bluetooth module. Popular pin codes for bluetooth modules: 0000, 1111, 1234

  • One or multiple devices with the serial ports should now exist in the system

hint ”Find

In the Terminal and run the command, and look for a new added port for connected bluetooth module

ls -lat /dev/tty* /dev/cu* | grep root | head -10


The command displays top 10 devices with names starting “/dev/cu” or “/dev/tty”, sorted by date-time, for the user “root”. In the example above – and Arduino board is connected to the computer with devices “/dev/cu.usbmodel1411” and “/dev/tty.usbmodem1411”; the bluetooth module HC-05 is connected with devices “/dev/tty.HC-05-DevB“, “/dev/cu.HC-05-DevB”, “/dev/cu.Bluetooth-Incoming-Port“, “/dev/tty.Bluetooth-Incoming-Port

  • Test connection to the bluetooth module: in the Terminal – run the command “screen””, where “/dev/tty.HC-05-DevB” is the name of the connected bluetooth module’s serial port, 19200 – the speed of the port (available options: 1200, 2400, 4800, 9600, 19200, 38400, 57600 and 115200)
screen /dev/tty.HC-05-DevB 19200
  • Open the Arduino IDE and upload following program to the Arduino board. For Arduino Leonardo or other board based on ATmega with integrated USB port – change the name of the Serial to Serial1
void setup() {
 while (!Serial) {}

void loop() {
  • Look at the terminal with the opened connection to the bluetooth module – it should output “Test”
  • Close the terminal with the connection to a bluetooth module. Serial port devices can be still opened – release processes which using them:
    • find process PID-s
    • ps | grep /dev/


    • release processes
      kill 34518
      kill 34715
  • Start the MatLab and in the Command window create an instance of the “serial” objectmatlab-serial-communication-01
  • The variable “s” now contains the instance of the class “serial”. Open the serial port (it takes few seconds)
  • fopen(s)

hint Use the command 'instrfind' to see used instances of the serial

Command instrfind provides informations on all used serial ports – opened and closed. If there was only one port used – the information about this port shown. If there were multiple instances of ports used – the list is provided. This information can be used to close all opened ports


Key-value parameters can narrow the outcome of the command “instrfind”

instrfind('Type', 'serial', 'Status', 'open')

hint Install the Support Package Installer if needed

 Support Package Installer. In the Command window run the command supportPackageInstaller


Select an option to “Install from Internet”matlab-installsupportpackages

Choose “Arduino” package


Hit the button “Next” and login to the MathWorks accountmatlab-install-arduino-support-package-02

Follow the installation wizard to download and complete the installationmatlab-install-arduino-support-package-05

Install Java for legacy products when requested


Look at the examples in the help file “MATLAB Support Package for Arduino Hardware Examples”




Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.