Overview
In This Tutorial, I Will Show You How The Dht11 Sensor Measure Humidity And Temperature I Will Also Explain Some Example codes for How To Interfacing The DHT11 Sensor With Arduino And Some other Controller.
This DHT11 Sensor It’s Perfect for Making A Remote Weather Station IS Measures The Tempare And Humdity But Is Slow Compare To The DHT22 Sensor.
I will just Show The Few Points of The DHT11 Sensor
- Operating Voltage :- 3V To 5.5V
- Temperature Range :- 0-50 °C
- Temperature Accuracy :- ±4% °C
- Humidity Range:- 20-80%
- Humidity Accuracy:- ±6% °C
I will Just Give The Link to DHT11 Sensor Datasheet
DHT11 Vs DHT22
DHT11 Sensor | DHT22 Sensor |
Voltage - 3 to 5V power and I/O | Voltage -3 to 5V power and I/O |
Temperature Range - 0 to 50°C with ± 2°C accuracy | Temperature Range - -40 to 80°C with ± 0.5°C accuracy |
Humidity Range -20 to 80% with 5% accuracy | Humidity Range - 0 to 100% with 2 to 5% accuracy |
Sampling Rate - 1Hz (Once every second) | Sampling Rate -0.5Hz (Once every two seconds) |
Price - Low | Price - High |
DHT11 And DHT22 Pinout
PCB Design
Wiring Diagram of DHT11 And DHT22 With Arduino
Library Installation
Just Download The DHT.h Library
Display Reading Is Serial Monitor
If You Used The Code Then Connected The DHT11 Sensor PIN Number D4
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 |
#include <dht.h> #define dataPin 4 dht DHT; void setup() { Serial.begin(9600); } void loop() { int readData = DHT.read22(dataPin); float t = DHT.temperature; float h = DHT.humidity; Serial.print("Temperature = "); Serial.print(t); Serial.print(" "); Serial.print((char)176); Serial.print("C | "); Serial.print((t * 9.0) / 5.0 + 32.0); Serial.print(" "); Serial.print((char)176); Serial.println("F "); Serial.print("Humidity = "); Serial.print(h); Serial.println(" % "); Serial.println(""); delay(3000); } |
Display Reading In LCD Display
If You Used The Code Then Connected The DHT11 Sensor PIN Number D4
And 16×2 LCD Display Will Be connected To Pin Number D12,D11,D10,D9,D8,D7
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 |
#include <LiquidCrystal.h> #include <dht.h> #define dataPin 4 LiquidCrystal lcd(12, 11, 10, 9, 8, 7); dht DHT; bool showcelciusorfarenheit = false; void setup() { lcd.begin(16,2); } void loop() { int readData = DHT.read22(dataPin); float t = DHT.temperature; float h = DHT.humidity; lcd.setCursor(0,0); lcd.print("Temp.: "); if(showcelciusorfarenheit) { lcd.print(t); lcd.print(" "); lcd.print((char)223); lcd.print("C"); showcelciusorfarenheit = false; } else { lcd.print((t * 9.0) / 5.0 + 32.0); lcd.print(" "); lcd.print((char)223); lcd.print("F"); showcelciusorfarenheit = true; } lcd.setCursor(0,1); lcd.print("Humi.: "); lcd.print(h); lcd.print(" %"); delay(3000); } |
Code With Oled Display
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
#include "DHT.h" #define DHT11Pin 4 #define DHTType DHT11 #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> DHT HT(DHT11Pin,DHTType); float humi; float tempC; float tempF; #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Serial.begin(9600); HT.begin(); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 Allocation Failed")); for(;;); } display.display(); delay(1000); display.clearDisplay(); } void loop() { delay(1000); humi = HT.readHumidity(); tempC = HT.readTemperature(); tempF = HT.readTemperature(true); Serial.print("Humidity:"); Serial.print(humi,0); Serial.print("%"); Serial.print(" Temperature:"); Serial.print(tempC,1); Serial.print("C ~ "); Serial.print(tempF,1); Serial.println("F"); display.clearDisplay(); oledDisplayHeader(); oledDisplay(3,5,28,humi,"%"); oledDisplay(2,70,16,tempC,"C"); oledDisplay(2,70,44,tempF,"F"); display.display(); } void oledDisplayHeader(){ display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.print("Humidity"); display.setCursor(60, 0); display.print("Temperature"); } void oledDisplay(int size, int x,int y, float value, String unit){ int charLen=12; int xo=x+charLen*3.2; int xunit=x+charLen*3.6; int xval = x; display.setTextSize(size); display.setTextColor(WHITE); if (unit=="%"){ display.setCursor(x, y); display.print(value,0); display.print(unit); } else { if (value>99){ xval=x; } else { xval=x+charLen; } display.setCursor(xval, y); display.print(value,0); display.drawCircle(xo, y+2, 2, WHITE); display.setCursor(xunit, y); display.print(unit); } } |
If You are Interested In More Projects Then Plz Check Out