Difference between revisions of "DHT"
(→Control6) |
(→Control6) |
||
Line 83: | Line 83: | ||
== [[Control6|Control6]] == | == [[Control6|Control6]] == | ||
− | Humidity and temperature can be accessed | + | Humidity and temperature can be accessed in [[Control6]] scripts through the DHT_HUMIDITY and DHT_TEMPERATURE keywords. The values returnd are fixed point integers including one decimal. The following example calculates and outputs the dew point on a LCD one every minute. |
<source lang="text"> | <source lang="text"> |
Revision as of 10:39, 5 March 2013
DHT | |
---|---|
Status | Experimental
|
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 |
Contents
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:
DHT11
- 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
DHT22
- 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
Connection
Likewise, it is fairly easy to connect up to the DHT sensors. They have four pins
- VCC (3 to 5V power)
- Data out
- Not connected
- 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, i.e. PA0 as listed in the pinning example:
ifdef(`conf_DHT', `dnl pin(DHT, PA0, INPUT) ')
Configuration
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 | | --- Debugging Flags | | [*] DHT
ECMD
DHT implements an ECMD interface for reading humidity and temperature values. See ECMD reference.
Control6
Humidity and temperature can be accessed in Control6 scripts through the DHT_HUMIDITY and DHT_TEMPERATURE keywords. The values returnd are fixed point integers including one decimal. The following example calculates and outputs the dew point on a LCD one every minute.
#include <math.h>
CONTROL_START
THREAD(read_dht)
ON ONCE CLOCK_MIN == 0 DO
float a = 17.271;
float b = 237.7;
float temperatur = (a * DHT_TEMPERATURE) / (b + DHT_TEMPERATURE) + log(DHT_HUMIDITY/100);
float taupunkt = (b * temperatur) / (a - temperatur);
hd44780_clear();
hd44780_home();
hd44780_printf_P("Taupunkt: %f", taupunkt);
END
THREAD_END(read_dht)
ON STARTUP DO
THREAD_START(read_dht);
END
CONTROL_END