Main Content

Set Up and Configure Arduino Hardware

Once you have installed the MATLAB® Support Package for Arduino® Hardware, as described in Install the Support Package, you can configure the host computer to communicate with the Arduino board via USB, Bluetooth®, or Wi-Fi®. If you are using ESP32-DevKitV1, ESP32-DevKitC, NanoESP32, or ESP32-S3-DevKitM boards, see Set Up and Configure ESP32 Hardware.

Note

You can directly use MATLAB Support Package for Arduino Hardware in MATLAB Online™ without installing the support package. For more information see, Get Started with MATLAB Online for Arduino.

Prepare Arduino Board for Setup

Before configuring your Arduino hardware for communication, set up the hardware with these steps.

  1. Connect the Arduino board to the host computer using a USB cable. You must start the setup with a USB connection even if you plan to communicate with the Arduino board using Bluetooth or Wi-Fi.

    Arduino connected via USB

  2. In MATLAB, open Hardware Setup window by entering arduinosetup at the command prompt.

  3. Select the board type and the port number from the Choose board and Choose port lists. Then, click Next.

    Arduino hardware board setup

  4. To configure your hardware for communication, choose your connection type. The Choose Connection Type pane lists only the connection types supported for the board you selected in the previous step. Follow the steps in the section relevant to your connection type:

Connection over USB

Before you configure your Arduino hardware for communication, complete the steps described in Prepare Arduino Board for Setup.

To configure your Arduino hardware to communicate via USB:

  1. Specify connection type USB and click Next.

    Arduino hardware board setup - USB

  2. Select the libraries to include in your Arduino server. Click Program to begin uploading the server to your Arduino board.

    Arduino hardware board libraries setup

  3. After the upload is successful, click Next to proceed.

  4. To test the connection between your host computer and the Arduino board, click Test connection.

    Test Arduino hardware board with USB connection

  5. After the connection test is successful, click Next to proceed.

  6. Click Finish to complete the hardware setup. To connect to your Arduino board, see Connect to Arduino Hardware.

    Arduino setup complete

Connection over Bluetooth

Before you configure your Arduino hardware for communication, complete the steps described in Prepare Arduino Board for Setup, and disconnect the USB.

If you are using a Windows® desktop computer, connect a Bluetooth dongle to your computer. You should use a dongle supporting Bluetooth 4.0 or higher to connect to the MKR1010, UnoR4WiFi, Nano33 IoT, Nano 33 BLE, or, Nano 33 BLE Sense boards over Bluetooth.

To configure your Arduino hardware to communicate via Bluetooth:

  1. Specify connection type as Bluetooth and click Next.

    Arduino hardware board setup - Bluetooth

  2. Select the libraries to include in your Arduino server. Click Program to begin uploading the server to your Arduino board.

    If you are using MKR1010, UnoR4WiFi, Nano 33 IoT, Nano 33 BLE, or the Nano 33 BLE Sense board, on the Upload Arduino Server screen:

    • Use the Name field to assign a new name to your Arduino hardware or choose a device name from the list.

    • Select the libraries that you want to upload to your Arduino hardware.

    • Click Program to complete uploading libraries to the Arduino device and retrieve the Bluetooth Device address from the Arduino board.

    Arduino hardware board libraries setup

  3. If you are using the Uno, Due, Mega2560, Leonardo, Micro, or the Nano3 board, select the Bluetooth device that you want to use to communicate with the Arduino board.

  4. If you are using the HC-05 or HC-06 boards and you have not configured the device using the arduinosetup interface, click No to first configure your Bluetooth device.

  5. If you are using the Uno, Due, Mega2560, Leonardo, Micro, or the Nano3 board, to configure your Bluetooth device, follow the on-screen links in the Hardware Setup window to pair your Bluetooth Classic device and to get your Bluetooth serial port or address.

  6. After the upload is successful, click Next to proceed.

  7. To test the connection between your host computer and the Arduino board, click Test connection.

    Test Arduino hardware board with Bluetooth connection

  8. After the connection test is successful, click Next to proceed.

  9. Click Finish to complete the hardware setup.

Connection over Wi-Fi

Before you configure your Arduino hardware for communication, complete the steps described in Prepare Arduino Board for Setup, and disconnect the USB.

To configure your Arduino hardware to communicate via Wi-Fi:

  1. Specify connection type as Wi-Fi.

    Arduino hardware board setup - WiFi

  2. Choose the encryption type of your Wi-Fi network, and enter the necessary credentials.

    • If you have previously configured your Arduino board in Hardware Setup to use Wi-Fi retrieve the credentials from your previous configuration by selecting Retrieve last configuration from Arduino board.

    • If you select Use static IP address , make sure that you use an available static IP address and that your router allows the usage of static IP. Ensure that the Subnet Mask is 255.255.255.0 and the Default Gateway is the IP address of the network gateway.

  3. Select the libraries that you want to include in your Arduino board. Click Program to begin uploading the server to your Arduino board.

    Arduino hardware board libraries setup

  4. After the upload is successful, click Next to proceed.

  5. To test the connection between the host computer and the Arduino board, click Test connection.

    Test Arduino hardware board with WiFi connection

  6. After the connection test is successful, click Next to proceed.

  7. Click Finish to complete the hardware setup.

See Also

Topics