ModularSensors > Modules > Supported Sensors > AOSong DHT

AOSong DHT module

Classes for the AOSong DHT digital-output relative humidity and temperature sensor.

Quick Notes

  • Applies to AOSong modules:
  • Depends on the Adafruit DHT library
  • Communicate with a single-bus single wire digital signaling protocol
    • Can be connected to any digital pin on a Arduino
    • The communication with these sensors is slow and interrupts are turned off during communication.
    • See the Adafruit DHT library's DHT.cpp for details.
    • Could possibly cause issues if used in combination with other interrupt-driven sensors.
  • Only 1 can be connected to a system at a time
  • Requires a 3.3 - 6V power source
  • Sensors should not be polled more frequently than once every 2 seconds
  • Uses a Maxim DS18 sensor internally

Sensor Datasheet

Datasheet

Sensor Constructor

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.


Example Code

The DHT is used in the menu a la carte example.

#include <sensors/AOSongDHT.h>

// NOTE: Use -1 for any pins that don't apply or aren't being used.
const int8_t DHTPower = sensorPowerPin;  // Power pin
const int8_t DHTPin   = 10;              // DHT data pin
const int8_t dhtType =
    DHT11;  // DHT type, one of DHT11, DHT12, DHT21, DHT22, or AM2301

// Create an AOSong DHT sensor object
AOSongDHT dht(DHTPower, DHTPin, dhtType);

// Create humidity, temperature, and heat index variable pointers for the DHT
Variable* dhtHumid =
    new AOSongDHT_Humidity(&dht, "12345678-abcd-1234-ef00-1234567890ab");
Variable* dhtTemp = new AOSongDHT_Temp(&dht,
                                       "12345678-abcd-1234-ef00-1234567890ab");
Variable* dhtHI   = new AOSongDHT_HI(&dht,
                                     "12345678-abcd-1234-ef00-1234567890ab");

Classes

class AOSongDHT
The Sensor sub-class for the AOSong digital-output relative humidity and temperature sensor modules.
class AOSongDHT_Humidity
The Variable sub-class used for the humidity output from an AOSong DHT.
class AOSongDHT_Temp
The Variable sub-class used for the temperature output from an AOSong DHT.
class AOSongDHT_HI
The Variable sub-class used for the heat index output calculated from measurements made by an AOSong DHT.

Defines

#define DHT_NUM_VARIABLES = 3
Sensor::_numReturnedValues; the DHT can report 3 values.
#define DHT_INC_CALC_VARIABLES = 0
Sensor::_incCalcValues; we don't calculate any additional values.

Sensor Timing

The sensor timing for an AOSong DHT

#define DHT_WARM_UP_TIME_MS = 1700
Sensor::_warmUpTime_ms; DHT warms up in 1700ms (1.7sec).
#define DHT_STABILIZATION_TIME_MS = 0
Sensor::_stabilizationTime_ms; We assume the sensor is stable immediately after warm-up.
#define DHT_MEASUREMENT_TIME_MS = 2000
Sensor::_measurementTime_ms; DHT takes 2000ms (2s) to complete a measurement.

Humidity

The humidity variable from an AOSong DHT

  • Accuracy is ± 2 % RH for DHT22 and ± 5 % RH for DHT11
  • Range is 0 to 100 % RH

AOSongDHT_Humidity(AOSongDHT* parentSense, const char* uuid = "", const char* varCode = DHT_HUMIDITY_DEFAULT_CODE) explicit

Construct a new AOSongDHT_Humidity object.

Parameters
parentSense The parent AOSongDHT providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "DHTHumidity".

#define DHT_HUMIDITY_RESOLUTION = 1
Decimals places in string representation; humidity should have 1 (0.1 % RH for DHT22 and 1 % RH for DHT11)
#define DHT_HUMIDITY_VAR_NUM = 0
Sensor variable number; humidity is stored in sensorValues[0].
#define DHT_HUMIDITY_VAR_NAME = "relativeHumidity"
Variable name in ODM2 controlled vocabulary; "relativeHumidity".
#define DHT_HUMIDITY_UNIT_NAME = "percent"
Variable unit name in ODM2 controlled vocabulary; "percent" (percent relative humidity or % RH)
#define DHT_HUMIDITY_DEFAULT_CODE = "DHTHumidity"
Default variable short code; "DHTHumidity".

Temperature

The temperature variable from an AOSong DHT

  • Accuracy is ±0.5°C for DHT22 and ± ±2°C for DHT11
  • Range is -40°C to +80°C

AOSongDHT_Temp(AOSongDHT* parentSense, const char* uuid = "", const char* varCode = DHT_TEMP_DEFAULT_CODE) explicit

Construct a new AOSongDHT_Temp object.

Parameters
parentSense The parent AOSongDHT providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "DHTTemp".

#define DHT_TEMP_RESOLUTION = 1
Decimals places in string representation; temperature should have 1 - resolution is 0.1°C.
#define DHT_TEMP_VAR_NUM = 1
Sensor variable number; temperature is stored in sensorValues[1].
#define DHT_TEMP_VAR_NAME = "temperature"
Variable name in ODM2 controlled vocabulary; "temperature".
#define DHT_TEMP_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (degrees Celsius, °C)
#define DHT_TEMP_DEFAULT_CODE = "DHTTemp"
Default variable short code; "DHTTemp".

Heat Index

The heat index variable from an AOSong DHT

  • Heat index is calculated within the Adafruit library from the measured temperature and humidity.

AOSongDHT_HI(AOSongDHT* parentSense, const char* uuid = "", const char* varCode = DHT_HI_DEFAULT_CODE) explicit

Construct a new AOSongDHT_HI object.

Parameters
parentSense The parent AOSongDHT providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "DHTHI".

#define DHT_HI_RESOLUTION = 1
Decimals places in string representation; heat index should have 1 - resolution is 0.1°C.
#define DHT_HI_VAR_NUM = 2
Sensor variable number; HI is stored in sensorValues[2].
#define DHT_HI_VAR_NAME = "heatIndex"
Variable name in ODM2 controlled vocabulary; "heatIndex".
#define DHT_HI_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)
#define DHT_HI_DEFAULT_CODE = "DHTHI"
Default variable short code; "DHTHI".