Main Content

readHumidity

Read one sample of relative humidity data from the sensor

Since R2021a

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

Description

[humidityReading,timestamp] = readHumidity(humiditySensor) returns one sample of the relative humidity measured in % along with the timestamp. timestamp is optional.

Note

The readHumidity function is available for only the HTS221 sensor.

Examples

Read humidity Data from Sensor

Create an Arduino object and include the I2C library.

a = arduino();

Or, you can explicitly specify it in the Libraries Name-Value pair while creating the Arduino object.

clear a;
a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create the sensor object for the sensor in use.

humiditySensor = hts221(a);

Return one sample of humidity data.

humidityReading = readHumidity(humiditySensor)
humidityReading =
   69.6077

Input Arguments

collapse all

A sensor connection, specified as a hts221 object.

Output Arguments

collapse all

The relative humidity reading from the sensor, specified in percentage (%)

Data Types: double

The time at which MATLAB® receives humidity data from the sensor, specified as a datetime.

Data Types: datetime

More About

collapse all

Code Generation Using MATLAB Function Block

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

  • Timestamp returned is always in seconds.

Version History

Introduced in R2021a

See Also