This project will guide you how to use DHT11/DHT22 Humidity & Temperature Sensor to interconnected with Arduino, The DHTXX sensors are very popular in Arduino module component. The DHT sensors are relative cheap sensors for measuring temperature and humidity.
These sensor has a chip inside that converts analog to digital conversation and spits out a digital signal with temperature and humidity, with any (MCU) micro controller these signal are ready to drive.
Electronics parts required for this project.
- Arduino UNO/MEGA/NANO
- DHT11 (DHT22 Optional)
- Breadboard
- 10K Resistor
Schematics for connecting the DHT11
1. Download the source code here
2. Unzip the DHT Library
3. Copy the extracted file to your Arduino Libray
4. Go to files / Example / DHT SENSOR LIB / DHT Tester
5. Upload the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include "DHT.h" #define DHTPIN 2 // what pin we're connected to #define DHTTYPE DHT11 // DHT 11 // #define DHTTYPE DHT22 // Uu-comment this if you want to use DHT 22 (AM2302) // #define DHTTYPE DHT21 // Un-comment this if you want to use DHT 21 (AM2301) // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); } void loop() { // Wait a few seconds between measurements. delay(2000); // Reading the temperature or humidity takes about to 250 milliseconds // Sensor readings may up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Reading the temperature as Celsius float t = dht.readTemperature(); // Reading the temperature as Fahrenheit float f = dht.readTemperature(true); // If read failed it will try again. if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("DHT Sensor Failed to read!"); return; } // Compute heat index // Must send in temp in Fahrenheit! float hi = dht.computeHeatIndex(f, h); Serial.print("Humidity : "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature : "); Serial.print(t); Serial.print(" *C "); Serial.print(f); Serial.print(" *F\t"); Serial.print("Heat index: "); Serial.print(hi); Serial.println(" *F"); } |
Temperature & Humidity Sensor With Arduino Using DHT11/DHT22
Pingback:Wiring the 14CORE 37 Sensors for Arduino & Raspberry Pi | 14Core.com