From Ethersex_Wiki
Jump to: navigation, search
menuconfig I/O->Humidity & temperature sensors->DHT 11/22
Pinning yes
Ecmd yes
Control6 yes
Code https://github.com/ethersex/ethersex/tree/master/hardware/dht

DHT11/DHT21/DHT22 etc. Temperature & Humidity sensors

These sensors are very basic and slow, but are great for hobbyists who want to do some basic data logging. The DHT sensors are made of two parts, a capacitive humidity sensor and a thermistor. There is also a very basic chip inside that does some analog to digital conversion and spits out a digital signal with the temperature and humidity.

DHT11 vs DHT22

There are two versions of the DHT sensor available, they look a bit similar and have the same pinout, but have different characteristics. Here are the specs:


  • Ultra low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 20-80% humidity readings with 5% accuracy
  • Good for 0-50°C temperature readings ±2°C accuracy
  • No more than 1 Hz sampling rate (once every second)
  • Body size 15.5mm x 12mm x 5.5mm
  • 4 pins with 0.1" spacing


  • Low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 0-100% humidity readings with 2-5% accuracy
  • Good for -40 to 125°C temperature readings ±0.5°C accuracy
  • No more than 0.5 Hz sampling rate (once every 2 seconds)
  • Body size 15.1mm x 25mm x 7.7mm
  • 4 pins with 0.1" spacing


Likewise, it is fairly easy to connect up to the DHT sensors. They have four pins

  1. VCC (3 to 5V power)
  2. Data out
  3. Not connected
  4. Ground

Simply ignore pin 3, it is not used. You will want to place a 10K resistor between VCC and the data pin, to act as a medium-strength pull up on the data line.

The data out can be connected to any port pin of the ATmega. Each sensor requires its own port pin for data input.


Ethersex polls the sensors every n seconds. The advantage of this feature is that the reading opererates without any noticeable lags. Also it is easier to have multiple applications requesting sensor information since more request will not increase traffic.

 | | I/O  --->
 [*] Humidity & temperature sensors  --->
 [*] DHT 11/22  --->
 | |       (DHT11) Sensor type
 | |       (30) Time between polling in 1s steps
 | |            Edit pin configuration
 | |       [-] SNMP support
 | |       --- ECMD Support
 | |       [x] temp
 | |       [x] humid
 | |       [x] list
 | |       [-] list with values
 | |       --- Debugging Flags
 | |       [ ] DHT

The module has its own pinning file hardware/dht/dht_pinning.conf, that you can edit via the edit menu entry.

 # DHT Configuration File
 # You can assign pins and names to your sensors here.
 # Keep in mind that this names must consist of alphanumeric
 # characters only!
 # Every line starting with a hash sign (#) is a comment.
 # PIN | Name
 PB3     keller
 PA3     bad


DHT implements an ECMD interface for reading humidity and temperature values. See ECMD reference.


Humidity and temperature can be accessed in Control6 scripts through the DHT_HUMIDITY sensor number and DHT_TEMPERATURE sensor number keywords. The values returnd are fixed point integers including one decimal. The following example calculates and outputs the dew point on a LCD once every minute. To output floating point values the floating point printf version is required (Makefile: LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm).

#include <stdio.h>
#include <math.h>
#include "hardware/lcd/hd44780.h"



  float a = 17.271;
  float b = 237.7;
  float temperatur = (a * DHT_TEMPERATURE 0) / (b + DHT_TEMPERATURE 0) + log(DHT_HUMIDITY 0 /100);
  float taupunkt = (b * temperatur) / (a - temperatur);

  fprintf_P(&lcd, PSTR("Taupunkt: %f"), taupunkt);