Objective
Use the DHT22 sensor to measure temperature and humidity levels in an environment and display the results using an Arduino board.
Required Components
- DHT22 Sensor
- Arduino Board (e.g., Arduino Uno)
- Jumper wires
- Breadboard
- Arduino IDE (for programming)
Working Principle
The DHT22 sensor uses a capacitive humidity sensor and a thermistor to measure temperature and humidity. It outputs data in a digital signal to the Arduino for processing.
Circuit Diagram
Connect the sensor as follows:
- Connect VCC to the 5V pin on the Arduino.
- Connect GND to the GND pin on the Arduino.
- Connect the signal pin to digital pin 2 on the Arduino.
Arduino Code
#include
#define DHTPIN 2 // DHT22 connected to digital pin 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000);
}
Results
The serial monitor will display the temperature and humidity values, refreshed every 2 seconds.
Applications
- Weather monitoring stations
- Smart home climate control
- Industrial climate monitoring
Conclusion
The DHT22 sensor is an excellent tool for accurately measuring temperature and humidity, suitable for a wide range of applications.