Main Content


Read voltage from analog pin on Arduino hardware

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



voltage = readVoltage(a,pin) reads the voltage on the specified analog input pins on Arduino® hardware.


collapse all

Create an Arduino object and read voltage from and analog input pin.

a = arduino;
ans = 1.0606

Input Arguments

collapse all

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

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


If you connect to ESP32 board, the pin number must always correspond to a digital pin. For details, see Pin-mapping for ESP32 Boards.

Output Arguments

collapse all

Voltage read from an analog pin on an Arduino hardware specified as a numeric double.

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use readVoltage 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 readVoltage in the MATLAB Function block.

Version History

Introduced in R2014b