Sensor – DHT – Temperatuur en Luchtvochtigheid sensor

Hardware

DHT11

DHT22

BESTELLEN

Informatie

Met deze module kun je de temperatuur en luchtvochtigheid meten, hij is door de fabrikant al behoorlijk geijkt, eventuele aanpassingen (bijvoorbeeld ijken) kunnen softwarematig gedaan worden, de meetwaarden van de DHT22 zijn nauwkeuriger dan zijn broertje, de DHT11.

– Werkt op: 3-5V.
– 2.5mA max stroomverbruik wanneer data opgevraagd wordt.
– Temperatuur bereik: -40 t/m 80 ºC.
– Temperatuur nauwkeurigheid: ±0,5 ÂºC.
– Vochtigheid bereik: 20-95% RH.
– Vochtigheid nauwkeurigheid: ±5,0% RH.
– Response tijd: < 5 sec.

Let op: de DHT11 geeft geen decimalen weer, de DHT22 wel!

Ps. Voor velen wordt deze sensor als een oude reliek gezien, maar….het is de enige sensor die kan communiceren over lange afstanden met kabel, de modernere sensoren hebben een I2C of SPI interface, en zijn daardoor beperkt met een max. kabellengte van 15-30 cm!


Vergelijking tussen de DHT121 en DHT22:

Pinout

Pin:Functie:
01+5V
02Data
03NC (niet aangesloten)
04GND

Arduino

De sensor werkt met binaire data, er zijn daarvoor diverse bibliotheeken geschreven om het makkelijk te maken.

1) Weerstand 4,7 kOhm
2) Arduino DHT bibliotheek

Sluit de module aan volgens onderstaand overzicht:

Arduino DHT11 los schema

Arduino DHT22 los schema

 Ps. de weerstand is nodig voor de pull-up!

Arduino pin:BMP280 pin:
+5V+5V (VCC)
GNDGND
A5SCL
Serial Clock (line)
A4SCA
Serial Clock (data)

Script (voorbeeld Markruys bibliotheek)

Output

DHT11 seriele monitor


Script (RobTillaart “DHTlib” library)

Voorbeeld met een DHT22 sensor

Output

Arduino RobTillaart DHTlib library output


Arduino Library

Installatie van Arduino IDE libraries: Arduino info

DHT informatie @ Arduino Playground

RobTillaart “DHTlib” library (aanbevolen voor Arduino)

The DHT11, 21, 22, 33 and 44 are relative inexpensive sensors for measuring temperature and humidity.

This library can be used for reading both values from these DHT sensors.
The DHT11 only returns integers (e.g. 20) and does not support negative values.
The others are quite similar and provide one decimal digit (e.g. 20.2)
The hardware pins of the sensors and handshake are identical so ideal to combine in one lib.

The library (0.1.13 version) is confirmed to work on:

UNO (tested myself)
2009 (tested myself)
MEGA2560
DUE
attiny85 @8MHz
Digistump Digix @ 84 MHz

Dowload Robtillaart DHTlib library @ Github

Markruys “arduino-DHT” library (arduino)

  • Ondersteuning voor DHT11. DHT22, AM2302, RHT03.
  • Detecteert automatisch het sensor model.
  • Verbruikt weinig geheugen.
  • Zeer kleine code.

Dowload Markruys arduino-DHT library @ Github

Adafruit “DHT library” (arduino)

This is an Arduino library for the DHT series of low cost temperature/humidity sensors.

To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

Dowload Adafruit DHT library @ Github

Niesteszeck “idDHT11” library

De DHT bibliotheek van Niesteszeck is interrupt gedreven en belast de atmega minder, zodat er capaciteit overblijft voor andere taken.

Dowload Niesteszeck – idDHT11 library @ Github

Bronnen:
ControlEverythongCommunity @ Github.com
raspberrypi-spy.co.uk


Raspberry Pi

Let op: Soms krijg je geen uitslag/resultaat van de scripts, dat komt omdat Linux de (precieze) timing van de aanroepen niet kan garanderen!, bij voorkeur zijn de DHT sensoren niet geschikt voor een Raspberry Pi

De sensor werkt met binaire data, er is daarvoor een bibliotheek geschreven om het makkelijk te maken.

1) Python DHT sensors bibliotheek

Aansluiten op de Raspberry Pi

Sluit de DHT sensor aan zoals aangegeven op onderstaand schema:

Raspberry Pi DHT11 schema

Raspberry Pi pin:DHT11 pin:
1 (+3.3v)1 (+3.3 - 5v)
72 (data)
14 (GND)4 (GND)

Ps. de weerstand is nodig voor de pull-up!

Raspberry Pi pin:DHT22 pin:
1 (+3.3v)1 (+3.3 - 5v)
182 (data)
14 (GND)4 (GND)

Scripts

Onderstaand script leest eenvoudig een DHT 11 sensor uit op GPIO 4, en geeft de waarden weer via de console.

Maak een bestand aan, bijvoorbeeld /usr/src/dht.py (evt onder root, en vergeet niet chmod te gebruiken om het bestand uit te kunnen voeren), voeg deze inhoud daar in toe:

Commandolijn parameters

Wil je commandolijn parameters gebruiken?, bijvoorbeeld als je meerdere DHT sensors hebt aangesloten via de GPIO pinnen, gebruik deze voorbeeld code.

Start het script met commandolijn:  sudo python /usr/src/dht.py [11/22/2302] [GPIO pin]

Het commando sudo python /usr/src/dht.py 22 24  leest bijvoorbeeld een DHT22 sensor uit die aangesloten is op  GPIO pin 24 (Broadcom SOC)

Gegevens wegschrijven naar CSV bestand

Je kan de gegevens ook opslaan in een CSV bestand, onderstaand script maakt ook gebruik van de commandolijn parameters en slaat gegevens op in een bestand (per maand) in /usr/src/DHT_DATA_[YYYY]_[MM].csv

De inhoud van het CSV bestand ziet er zo uit:


Script met Adafruit bibliotheek

Onderstaand script leest eenvoudig een DHT 22 sensor uit op GPIO 18, en geeft de waarden weer via de console.

Maak een bestand aan, bijvoorbeeld /usr/src/dht.py (evt onder root, en vergeet niet chmod te gebruiken om het bestand uit te kunnen voeren), voeg deze inhoud daar in toe:

Bronnen:
community.mydevices.com
raspberrytips.nl

Python Library

Python library to read the DHT series of humidity and temperature sensors on a Raspberry Pi or Beaglebone Black.

Currently the library is only tested with Python 2.6/2.7.

For all platforms (Raspberry Pi and Beaglebone Black) make sure your system is able to compile Python extensions. On Raspbian or Beaglebone Black’s Debian/Ubuntu image you can ensure your system is ready by executing:

Installatie via GIT (github)

Download Adafruit_Python_DHT @ Github


Afmetingen

Teardown

Inside the case is a small PCB with a SOIC 14 packaged IC unfortunately the part number has been removed so there is really no way to tell if this is a custom part or a specially programmed MCU. along the edge of the IC are couple of  ceramic capacitors for decoupling and noise suppression, and some other misc passive components. The green resistor I can assume is a precision resistor for the humility sensor (explained in more detail later).

On the other side the sensor hardware itself. This consists of a PCB with interlaced traces that creates capacitance this with change based on the amount of moisture present in the air around it.

HOW DOES IT WORK

The interlaced +ive and -ive traces allow a small amount of charge to be stored in each of the traces allowing the circuit to charge up a little, this is called capacitance and this is effected by the material separating the +ive and -ive which is mostly air and its airs permittivity one of the factors for calculating capacitance is affected by temperature and humidity.
So the chip uses the precision resistor I mentioned earlier and measures the discharge time through that resistor to calculate the capacitance, and then uses that figure used with the internal temperature sensor inside the main IC to calculate the relative humidity.

Datasheet

Fritzing

Downloads

GEEN GEGEVENS