Documentation Center

  • Trial Software
  • Product Updates

Contents

Arduino Analog Input

Measure voltage of analog input pin

Library

Simulink Support Package for Arduino® Hardware/Common

Description

Measure the voltage of an analog pin relative to the analog input reference voltage on the Arduino hardware. Output the measurement as a 10-bit value that ranges from 0 to 1023.

  • If the measured voltage equals the ground voltage, the block output emits 0.

  • If the measured voltage equals the analog reference voltage, the block output emits 1023.

The default value of the analog input reference voltage is 0 to 5 V. To change the Analog input reference voltage parameter in your model Configuration Parameters, select Tools > Run on Target Hardware > Options.

During simulations without the hardware, this block emits zeroes. See Block Produces Zeros or Does Nothing in Simulation

    Warning   The range of the voltage that can be applied to the analog input pin depends on the analog input reference voltage. For details, read the documentation for your Arduino hardware.

Dialog Box

Pin number

Enter the number of the analog input pin.

Do not assign the same pin number to multiple blocks within the model.

If you set the Target hardware parameter to:

  • Arduino Mega 2560, enter a pin number from 0 to 15.

  • Arduino Uno, enter a pin number from 0 to 5.

  • Arduino Nano, enter a pin number from 0 to 5.

  • Arduino Due, enter a pin number from 0 to 11.

    Note:   To change the Target hardware parameter, select Tools > Run on Target Hardware > Options.

Sample time

Specify how often this block measures the voltage of the analog input pin, in seconds. Enter a value greater than zero. This value defaults to a sample time of 1 second. The minimum value is 0.000001 second.

Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.

See Also

| | |

External Web Sites

Was this topic helpful?