Connect to Arduino Hardware

This example shows how to connect to Arduino® hardware in MATLAB®.

Make sure the Arduino hardware is connected to the computer. If the device is unofficial, note the port and board name.

Connect to an official Arduino hardware.

a = arduino()
a = 

  arduino with properties:

                    Port: 'COM4'
                   Board: 'Uno'
           AvailablePins: {'D2-D13', 'A0-A5'}
    AvailableDigitalPins: {'D2-D13', 'A0-A5'}
        AvailablePWMPins: {'D3','D5-D6', 'D9-D11'}
     AvailableAnalogPins: {'A0-A5'}
      AvailableI2CBusIDs: [0]   
               Libraries: {'I2C','RotaryEncoder','SPI','Servo','ShiftRegister','Ultrasonic''}

Connect by specifying the port and board name.

If you are using an unofficial (clone) Arduino hardware, specify port and board name to establish connection.

a = arduino('COM4','Uno')
a = 

  arduino with properties:

                    Port: 'COM4'
                   Board: 'Uno'
           AvailablePins: {'D2-D13', 'A0-A5'}
    AvailableDigitalPins: {'D2-D13', 'A0-A5'}
        AvailablePWMPins: {'D3','D5-D6', 'D9-D11'}
     AvailableAnalogPins: {'A0-A5'}
      AvailableI2CBusIDs: [0]   
               Libraries: {'I2C','RotaryEncoder','SPI','Servo','ShiftRegister','Ultrasonic''}