Content
Introduction
The DHT22 sensor is a versatile and low-cost device that can be used to measure temperature and humidity in a variety of applications. In this tutorial, we will show you how to connect a DHT22 sensor to an Arduino and use it to measure temperature and humidity.
Here are the specs of DHT22 from Adafruit:
- 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 80°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
Setting up DHT22
Printout of DHT22
The DHT22 sensor has four pins: VCC, GND, DATA, and NC (Not Connected).
- VCC: This pin is used to provide power to the sensor. It should be connected to a 3.3V or 5V power source depends on your board and product.
- GND: This pin is used as a reference voltage and should be connected to the ground.
- DATA: This pin is used to send and receive data from the sensor. It should be connected to a digital input pin on a microcontroller or Arduino board.
- NC: This pin is not connected and should not be used.
First, you will need to gather the necessary materials:
- An Arduino board (such as an Arduino Uno)
- A DHT22 sensor
- A breadboard and jumper wires
- A 10K resistor
Next, connect the DHT22 sensor to the Arduino as follows:
- Connect the VCC pin on the DHT22 to 3.3V or 5V on the Arduino
- Connect the GND pin on the DHT22 to GND on the Arduino
- Connect the DATA pin on the DHT22 to pin 2 on the Arduino
- Connect a 10K resistor between the VCC and DATA pins on the DHT22
Using DHT22 in Arduino IDE
Once your hardware is set up, you can use the following code to read temperature and humidity data from the DHT22 sensor:
#include <dht.h>
#define DHT22_PIN 2
#define DHTTYPE DHT22
DHT dht(DHT22_PIN, DHTTYPE);
void setup() {
Serial.begin(9600);
pinMode(DHT22_PIN, INPUT);
dht.begin();
}
void loop() {
Serial.print("Temperature: ");
Serial.print(dht.readTemperature()); // Read Temperature from DHT22.
Serial.print("°C ");
Serial.print("Humidity: ");
Serial.print(dht.readHumidity(); //Read Humidity from DHT22.
Serial.println("% ");
delay(2000); //Read the data every 2 seconds.
}
Upload the code to your Arduino board, and open the Serial Monitor. You should see temperature and humidity readings being printed every 2 seconds.
Example of DHT22
These are just a few examples of the many projects that can be built using the DHT22 sensor. The sensor is very versatile and can be used in many different applications where temperature and humidity measurement is required.
- Weather Station: You can use a DHT22 sensor to measure temperature and humidity outside and display the data on a web page or an LCD screen. This is a simple project that can be built with an Arduino and a Wi-Fi module.
- Greenhouse Controller: By measuring the temperature and humidity inside a greenhouse, you can use a DHT22 sensor and an Arduino to control the ventilation and irrigation systems. This will help you maintain optimal conditions for your plants.
- Home Automation: You can use a DHT22 sensor to measure the temperature and humidity inside your home and send the data to a smart home hub. This will allow you to monitor the indoor climate and make adjustments to your heating and cooling systems.
- Humidor controller: You can use a DHT22 sensor to measure the humidity inside a humidor and control a humidifier or dehumidifier to keep the humidity at the optimal level for storing cigars.
- Smart Thermostat: You can use a DHT22 sensor to measure the temperature inside a room, and use this data to adjust a thermostat to maintain a desired temperature.
- Plant Monitor Project: DHT22 is used for collecting temperature and humidity.
Conclusion
With a DHT22 sensor and an Arduino, you can easily measure temperature and humidity in your projects. Whether you’re building a weather station, a humidor, or a greenhouse controller, the DHT22 is a great choice for your sensing needs.