Main Content

Connect to Arduino Hardware

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

Make sure the Arduino or ESP32 hardware is connected to the computer. If the device is unofficial, note the port and the 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'}
Show all properties

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'}
Show all properties