ModularSensors > Classes > Sensor > AOSongDHT
ModularSensors > Modules > AOSong DHT > AOSongDHT

AOSongDHT class

The Sensor sub-class for the AOSong digital-output relative humidity and temperature sensor modules.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

AOSongDHT(int8_t powerPin, int8_t dataPin, const uint8_t type, uint8_t measurementsToAverage = 1)
Construct a new AOSongDHT object - need the power pin, the data pin, and the sensor type.
~AOSongDHT()
Destroy the AOSongDHT object - no action needed.

Public functions

bool setup(void ) override
Do any one-time preparations needed before the sensor will be able to take readings.
String getSensorName(void ) override
Get the name of the sensor.
bool addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

AOSongDHT(int8_t powerPin, int8_t dataPin, const uint8_t type, uint8_t measurementsToAverage = 1)

Construct a new AOSongDHT object - need the power pin, the data pin, and the sensor type.

Parameters
powerPin

The pin on the mcu controlling power to the AOSong DHT. Use -1 if it is continuously powered.

  • The DHT requires a 3.3 - 6V power source
dataPin The pin on the mcu receiving data from the AOSong DHT
type

The type of DHT. Possible values are DHT11, DHT21, AM2301, DHT22, or AM2302.

  • NOTE: The DHT type should be entered without quotation marks since the values are members of an enum rather than a string.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

bool setup(void ) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets the pin modes of the _powerPin and _dataPin, updates _sensorStatus, and returns true.


String getSensorName(void ) override

Get the name of the sensor.

Returns String The sensor name as given in the constructor.

bool addSingleMeasurementResult(void ) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.