Main Content

Read and Write Data from Arduino Pins

R2026b
Read and write directly to Arduino® hardware

Create an Arduino object using arduino before you use read and write functions. See Connect to Arduino Hardware for more information.

You can use Arduino Explorer to interactively configure pins on Arduino and other supported hardware, enabling you to read and write data in MATLAB® and MATLAB Online™. For more information, see Configure Read and Write for GPIO Pins Using Arduino Explorer App.

For a complete list of hardware supported in the installed version of MATLAB, see Supported Hardware. For more information regarding supported boards, workflows, and platforms supported on MATLAB Online, see Get Started with MATLAB Online for Arduino.

Note

All functions, except playTone, generate code using the MATLAB Function block. For more details, see Deploy Arduino Functions to Arduino Hardware Using MATLAB Function Block.

Functions

arduinoConnection to the Arduino and Arduino-compatible ESP32 hardware
configurePinSet Arduino pin mode
readDigitalPinRead data from a specified pin on Arduino hardware
writeDigitalPinWrite data to a specified pin on Arduino hardware
writePWMVoltageGenerate PWM signal with specified voltage on digital pin
writePWMDutyCycleGenerate PWM signal with specified duty cycle on digital pin
playTonePlay tone on piezo speaker using digital pin
readVoltageRead voltage from analog pin on Arduino hardware

Topics