Arduino DHT Sensor Protocol

The DHT Controller devices are able to get measurements from DHT11 or DHT22 temperature and humidity sensors. The temperature and humidity sensors are treated as seperate devices although they are physically on the same DHT sensor module. You can install multiple devices and connect multiple DHT sensor modules to a single microcontroller.

DHT11:
  • 0-50 °C (+/- 2°C accuracy)
  • 20-80 RH (5% accuracy)
  • Gets new data in every 2 seconds
DHT22:
  • -40-80 °C (+/- 0.5°C accuracy)
  • 0-100 RH (2-5% accuracy)
  • Gets new data in every 2 seconds

How to build a test circuit with a DHT22 and an Arduino Mega?
Arduino codes are included.

I. "Welcome" event from microcontroller

Example

//See as the temperature and humidity sensors are treated as seperate devices
//Although they can be on the same DHT sensor module
c=welcome&id=knRJ67&type=OzDHTSensor&pos=2&name=MyTemperatureSensor&t=2
c=welcome&id=QZ5M12&type=OzDHTSensor&pos=3&name=MyHumiditySensor&t=3

Parameters

Parameter Type Range Functionality
c String "welcome" Identifies the welcome message.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
type String "OzDHTSensor" Determines the type of the device.
pos Byte 0-255 Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position.
name (optional) String e.g. "MyTemperatureSensor" You can give default names for devices to seperate the temperature and humidity sensor.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



II. Commands to microcontroller

All commands work on both sensors (DHT11 or DHT22 and on both
temperature or humidity measurements of these DHT sensors).

"getvalue" command

You can request temperature (°C) or relative humidity (%) at any time. This depends on the device you are reading the value from.

Example

c=getvalue&id=knRJ67&t=0

Parameters

Parameter Type Range Functionality
c String "getvalue" Identifies the command.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

In the response you will get the actual temperature or humidity value from the DHT sensor.

Example

//This can be both temperature or humidity (It depends on the device ID)
c=getvalue_resp&value=24.00&id=knRJ67&t=4
Parameter Type Range Functionality
c String "getvalue_resp" Identifies the response
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
You will see the current temperature or humidity measurements depending on the type of device you use.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



"repchange" command

Sets threshold compared to the last measurement. A "change" event is sent everytime it passes the threshold in one of the directions. If it is set to 0 it is turned off.

Example

c=repchange&value=3.00&id=knRJ67&t=1

Parameters

Parameter Type Range Functionality
c String "repchange" Identifies the command.
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
Sets measurement threshold value compared to the last measured value. If it is set to 0 than the "change" event is turned off.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

Responds if the threshold value has been set.

Example

c=repchange_resp&value=3.00&id=knRJ67&t=5

Parameters

Parameter Type Range Functionality
c String "repchange_resp" Identifies the response.
value Int The value you have set in the command. The measurement threshold value to trigger a "change" event has been set. If it is set to 0 than the "change" event is turned off.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



"repabove" command

Triggers an "above" event everytime the measurement value passes the value you set with this command.

Example

c=repabove&value=60.00&id=knRJ67&t=2

Parameters

Parameter Type Range Functionality
c String "repabove" Identifies the command.
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
If the measured value of the pin crosses this value than an "above" event is triggered.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

Responds if the above value has been set.

Example

c=repabove_resp&value=60.00&id=knRJ67&t=6

Parameters

Parameter Type Range Functionality
c String "repabove_resp" Identifies the response.
value Int The value you have set in the command. If the measured value of the pin crosses this value than an "above" event is triggered.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



"repbelow" command

Triggers a "below" event everytime the measurement value passes the value you set with this command.

Example

c=repbelow&value=30.00&id=knRJ67&t=3

Parameters

Parameter Type Range Functionality
c String "repbelow" Identifies the command.
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
If the measured value of the pin crosses this value than a "below" event is triggered.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

Responds if the below value has been set.

Example

c=repbelow_resp&value=30.00&id=knRJ67&t=7

Parameters

Parameter Type Range Functionality
c String "repbelow_resp" Identifies the response.
value Int The value you have set in the command. If the measured value of the pin crosses this value than a "below" event is triggered.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



III. Event from microcontroller

"change" event

This event is called if the measured value has changed more then the threshold set with the "repchange" command. This event shows the current temperatur or humidity measured with the OzDHTController.

Example

c=change&value=40.00&id=knRJ67&t=8

Parameters

Parameter Type Range Functionality
c String "change" Identifies the event.
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
The current value of the measured temperature or humidity on the appropriate DHT pin. It is the value measured after it has passed the threshold.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.


"above" event

This event is called if the measured value has crossed above a preset value which you can set with the "repabove" command.

Example

c=above&value=65.00&id=knRJ67&t=9

Parameters

Parameter Type Range Functionality
c String "above" Identifies the event.
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
The current value of the measured temperature or humidity on the appropriate DHT pin. It is the value measured after it has crossed the 'above' value that has been set.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.


"below" event

This event is called if the measured value has crossed below a preset value which you can set with the "repbelow" command.

Example

c=below&value=25.00&id=knRJ67&t=10

Parameters

Parameter Type Range Functionality
c String "below" Identifies the event.
value Int If temperature:
DHT11: 0-50 (°C)
DHT22: -40-80 (°C)
If humidity:
DHT11: 20-80 (%)
DHT22: 0-100 (%)
The current value of the measured temperature or humidity on the appropriate DHT pin. It is the value measured after it has crossed the 'below' value that has been set.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.

More information