DHT Class

DHT Class

Description
A class to use DHT temperature and humidity sensors.

Syntax
class DHT

Members

Public Constructors 
DHT::DHTConstructs a DHT object.
Public Methods 
DHT::beginInitialize the DHT sensor.
DHT::readTemperatureRead temperature(Fahrenheit or Celsius) from the DHT sensor.
DHT::convertCtoFConvert a value from Celsius to Fahrenheit.
DHT::convertFtoCConvert a value from Fahrenheit to Celsius.
DHT::readHumidityRead humidity value from the DHT sensor as percentage.
DHT::computeHeatIndexCompute the HeatIndex from the readings (Using both Rothfusz and Steadman’s equations).
DHT::readCheck if the sensor is readable.

DHT::DHT

Description
Constructs a DHT object.

Syntax
DHT(uint8_t pin, uint8_t type, uint8_t count = 6);

Parameters
pin: selected GPIO pin on Ameba board
type: The DHT sensor type (DHT11, DHT22, or DHT21)
count: The count is now ignored as the DHT reading algorithm adjusts itself based on the speed of the processor. Default value: 6

Returns
NA

Example Code
Example:DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

DHT::begin

Description
Initialize the DHT sensor.

Syntax
void begin(void);

Parameters
NA

Returns
NA

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

DHT::readTemperature

Description
Read temperature (Fahrenheit or Celsius) from the DHT sensor.

Syntax
float readTemperature(bool S = false, bool force = false);

Parameters
s: Temperature scale, True is Fahrenheit and False is Celsius
force: Enable or disable force mode. Default value: False

Returns
This function returns the current temperature as a float value in selected scale.

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

DHT::convertCtoF

Description
Convert a value from Celsius to Fahrenheit.

Syntax
float convertCtoF(float c);

Parameters
c: Temperature in Celsius.

Returns
This function returns the temperature in Fahrenheit as a float number.

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

DHT::convertFtoC

Description
Convert a value from Fahrenheit to Celsius.

Syntax
float convertFtoC(float f);

Parameters
f: Temperature in Fahrenheit

Returns
This function returns the temperature in Celsius as a float number.

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

DHT::readHumidity

Description
Read humidity value from the DHT sensor as percentage.

Syntax
float readHumidity(bool force = false);

Parameters
force: force read mode. Default value: False

Returns
This function returns current humidity value represented in float as percentage.

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function. Reading temperature or humidity takes about 250 milliseconds! Sensor readings may also be up to 2 seconds.

DHT::computeHeatIndex

Description
Compute the HeatIndex from the readings (Using both Rothfusz and Steadman’s equations). More details refer to http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml .

Syntax
float computeHeatIndex(bool isFahrenheit = true);
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit = true);

Parameters
temperature: The temperature value
percentHumidity: humidity value in percentage
isFahrenheit: True, temperature value in Fahrenheit; False, temperature value in Celsius. Default value: True

Returns
This function returns the heat index in Fahrenheit or Celsius as a float value.

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

DHT::read

Description
Check if the sensor is readable.

Syntax
boolean read (bool force = false);

Parameters
force: True if using force mode. False if not using force mode. Default value: False.

Returns
This function returns the last correct measurement of the sensor.

Example Code
Example: DHTTester
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GPIO/examples/DHTtester/DHTtester.ino)

Notes and Warnings
“DHT.h” must be included to use the class function.

請先確認已安裝QQ通訊軟體