Description
The DHT22 is a low-cost digital temperature and humidity sensor with a single wire digital interface. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed).
The sensor is calibrated and doesn’t require extra components so you can get the right to measuring relative humidity and temperature.
It is quite simple to use but requires careful timing to grab data. You can only get new data from it once every 2 seconds.
Package Includes:
- 1 x DHT22 Temperature And Humidity Module.
- 3 x Female to Female Dupont cable.
Features:
- Operating Voltage: 3.5V to 5.5V
- Operating current: 0.3mA (measuring) 60uA (standby)
- Output: Serial data
- Temperature Range: -40°C to 80°C
- Humidity Range: 0% to 100%
- Resolution: Temperature and Humidity both are 16-bit
- Accuracy: ±0.5°C and ±1%
Applications
- Measure temperature and humidity
- Local Weather station
- Automatic climate control
- Environment monitoring
Â
2D – model of the sensor
Pinout of the Board:
ere are the pin definitions.
Pin | Symbol | Descriptions |
1 | VCC | Power supply (3.3V-5.5V) |
2 | GND | Ground |
3 | DOUT | Data output, connected to the pin SDA of AM2302 |
The AM2302 uses the simplified single-bus technology for communication, in which only one data line is applied for data exchange and data control in the system. In applications, an external pull-up resistor, about 5.1kΩ, is usually required. When the bus is idle, its status will switch to HIGH. The SDA is used for data communication and synchronization between the microprocessor and the AM2302. It adopts a single-bus data format, 40 bits of data in one transmission, high bit first out. The corresponding timing diagram is shown below.
The AM2302 data and signal format definition are listed below.
Name | Single-bus data and signal format |
Start signal | The microprocessor sets the SDA to LOW for a period of time (at least 800μs) [1] to inform the sensor to prepare the data. |
Response signal | The sensor sets the SDA to LOW for 80μs, and then HIGH for 80μs, to respond to the start signal. |
Data format | After receiving the start signal, the sensor reads out a string of data (40 bits) through SDA, High bit first out. |
Humidity | The humidity resolution is 16 Bits, high bit first out; The value read out by the sensor is 10 times higher than the actual humidity. |
Temp. | The temperature resolution is 16 Bits, high bit first out; The value read out by the sensor is 10 times higher than the actual temperature.
When the MSB(Bit15) is "1", it indicates a negative temperature; When the MSB (Bit15) is "0", it indicates a positive temperature; The other bits (Bit14 ~ bit 0) indicate the detected temperature value. |
Parity bit |
Parity bit = humidity high + humidity low + temperature high + temperature low |
Circuit:
Â
Code:
For this tutorial you will need:
-
Arduino uno
-
Breadboard
-
DHT-22
Â
The Circuit
The connections are pretty easy, see the image above with the breadboard circuit schematic.
The Code
#include <DHT.h>;
//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.
}
Â