Main Content


Read data from digital pin on Arduino hardware

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.



value = readDigitalPin(a,pin) reads data from the specified pin on the Arduino® hardware in connection a.


collapse all

Create a connection to Arduino hardware and read digital pin 13.

a = arduino;
ans = 1

Input Arguments

collapse all

Arduino hardware connection created using arduino, specified as an object.

Digital pin number on the physical hardware, specified as a character vector.

Output Arguments

collapse all

Value acquired from digital pin, returned as a numeric double.

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use readDigitalPin in a MATLAB® Function block with the Simulink® Support Package for Arduino Hardware to generate code that can be deployed on Arduino Hardware.

  • Configure the Arduino peripherals to the appropriate mode using configurePin before using readDigitalPin in the MATLAB Function block.

Version History

Introduced in R2014b