Skip to content
Home » Dht11 Sensor Arduino Code | How To Program For Dht11 Temperature Sensor

Dht11 Sensor Arduino Code | How To Program For Dht11 Temperature Sensor

DHT11 Temperature & Humidity sensor with Arduino - Tutorial

Introduction: DHT11 With Arduino

DHT11 is a sensor capable of detecting moisture and ambient air temperature with digital calibration of output. Level of accuracy for humidity of approximately 5% RH and the accuracy of the temperature is approximately 2’C. DHT11 uses a Single-Wire Two-Way communication line, which is one pin that is used for 2 pieces of communication in turn.

Here is the tutorial of DHT11 with Arduino.

Lời kết

Qua bài hôm nay các bạn biết cách làm thế nào để đọc một cảm biến nhiệt độ, độ ẩm DHT11, và hiểu hơn về cách giao tiếp của chúng.

Để nhận được nhiều kiến thức mới các bạn Đăng ký để nhận được thông báo sớm nhất.

Tham gia Cộng đồng Arduino KIT để cùng nhau thảo luận và chia sẽ kiến thức về lập trình Arduino.

Nếu các bạn thấy bài viết bổ ích nhớ Like và Share cho mọi người cùng đọc nhé.

Chúc các bạn thành công.

Trân trọng.

The DHT11 humidity and temperature sensor makes it really easy to add humidity and temperature data to your DIY electronics projects. It’s perfect for remote weather stations, home environmental control systems, and farm or garden monitoring systems.

In this tutorial, I’ll first go into a little background about humidity, then I’ll explain how the DHT11 measures humidity. After that, I’ll show you how to connect the DHT11 to an Arduino and give you some example code so you can use the DHT11 in your own projects.

Watch the video for this tutorial here:

Here are the ranges and accuracy of the DHT11:

  • Humidity Range: 20-90% RH
  • Humidity Accuracy: ±5% RH
  • Temperature Range: 0-50 °C
  • Temperature Accuracy: ±2% °C
  • Operating Voltage: 3V to 5.5V

The DHT11 Datasheet:

DHT11 Temperature & Humidity sensor with Arduino - Tutorial
DHT11 Temperature & Humidity sensor with Arduino – Tutorial

Arduino Example 1 – Displaying Readings on Serial Monitor

After installing the library, copy and paste this sketch into the Arduino IDE.

The following test sketch will print the temperature and relative humidity values to the serial monitor. Try out the sketch, and then we’ll go over it in more detail.


#include

// Include library #define outPin 8 // Defines pin number to which the sensor is connected dht DHT; // Creates a DHT object void setup() { Serial.begin(9600); } void loop() { int readData = DHT.read11(outPin); float t = DHT.temperature; // Read temperature float h = DHT.humidity; // Read humidity Serial.print("Temperature = "); Serial.print(t); Serial.print("°C | "); Serial.print((t*9.0)/5.0+32.0); // Convert celsius to fahrenheit Serial.println("°F "); Serial.print("Humidity = "); Serial.print(h); Serial.println("% "); Serial.println(""); delay(2000); // wait two seconds }

After uploading the sketch, you should see the following output on the serial monitor.

Code Explanation:

The sketch begins by including the DHT library. Following that, we specify the Arduino pin number to which our sensor’s Data pin is connected and create a

DHT

object.


#include

#define outPin 8 dht DHT;

In the setup, we initialize the serial communication.


void setup() { Serial.begin(9600); }

In the loop, we use the

read11()

function to read the DHT11 module. This function takes as a parameter the sensor’s Data pin number.


int readData = DHT.read11(outPin);

We can now retrieve the humidity and temperature values by accessing the DHT object’s properties using dot notation.


float t = DHT.temperature; // Read temperature float h = DHT.humidity; // Read humidity

The DHT object returns the temperature in degrees Celsius (°C). It is easy to convert to Fahrenheit (°F) using the following formula:

T(°F) = T(°C) × 9/5 + 32


Serial.print((t * 9.0) / 5.0 + 32.0);

Code mẫu

#include “DHT.h” const int DHTPIN = 4; const int DHTTYPE = DHT11; DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); Serial.print(“Nhiet do: “); Serial.println(t); Serial.print(“Do am: “); Serial.println(h); Serial.println(); delay(1000); }

Giải thích code

Khai báo chân kết nối cho cảm biến DHT ở đây mình dùng chân D4 trên Arduino Uno.

const int DHTPIN = 4; const int DHTTYPE = DHT11;

Thư viện DHT.h được khai báo sử dụng cho 2 loại cảm biến là DHT11 và DHT22.

Trong bài viết mình giới thiệu cảm biến nhiệt độ, độ ẩm DHT11, nên chúng ta cần phải khai báo là DHTTYPE là DHT11.

float h = dht.readHumidity(); // Đọc giá trị nhiệt độ từ cảm biến float t = dht.readTemperature(); // Đọc giá trị độ ẩm từ cảm biến

Ở trên là hai biến đọc giá trị nhiệt độ và độ ẩm.

Serial.print(“Nhiet do: “); Serial.println(t); Serial.print(“Do am: “); Serial.println(h);

In giá trị nhiệt độ, độ ẩm lên màn hình (Serial Monitor).

  • Để hiểu hơn về hàm Serial.print() và Serial.println() các bạn xem bài viết ở đây nhé:Xem ngay.

Chúng ta tiến hành Upload chương trình và bật Serial Monitor lên để xem kết quả nhé.

DHT11 temperature and humidity sensor with Arduino [code explained] | Arduino tutorial 15
DHT11 temperature and humidity sensor with Arduino [code explained] | Arduino tutorial 15

Display Humidity and Temperature on the Serial Monitor

Before you can use the DHT11 on the Arduino, you’ll need to install the DHTLib library. It has all the functions needed to get the humidity and temperature readings from the sensor. It’s easy to install, just download the DHTLib.zip file below and open up the Arduino IDE. Then go to Sketch>Include Library>Add .ZIP Library and select the DHTLib.zip file.

After it’s installed, upload this example program to the Arduino and open the serial monitor:


#include

dht DHT; #define DHT11_PIN 7 void setup(){ Serial.begin(9600); } void loop(){ int chk = DHT.read11(DHT11_PIN); Serial.print("Temperature = "); Serial.println(DHT.temperature); Serial.print("Humidity = "); Serial.println(DHT.humidity); delay(1000); }

You should see the humidity and temperature readings displayed at one second intervals.

If you don’t want to use pin 7 for the data signal, you can change the pin number in line 5 where it says

#define DHT11_PIN 7

.

Cảm biến nhiệt độ, độ ẩm DHT11

Cảm biến độ ẩm và nhiệt độ DHT11 là cảm biến rất thông dụng hiện nay vì chi phí rẻ và rất dễ lấy dữ liệu thông qua chuẩn giao tiếp 1 wire.

Chuẩn giao tiếp 1 wire là dùng 1 chân Digital để truyền dữ liệu.

Bộ tiền xử lý tín hiệu được tích hợp trong cảm biến giúp bạn có thể đọc dữ liệu chính xác mà không phải qua bất kỳ tính toán nào.

Thông số kỹ thuật của cảm biến:

  • Điện áp hoạt động: 3V – 5V (DC)
  • Dãi độ ẩm hoạt động: 20% – 90% RH, sai số ±5%RH
  • Dãi nhiệt độ hoạt động: 0°C ~ 50°C, sai số ±2°C
  • Khoảng cách truyển tối đa: 20m

Các bạn download và cài đặt thư viện hỗ trợ sử dụng DHT11: Tại đây

How to Use a DHT11 Humidity Sensor on the Arduino - Ultimate Guide to the Arduino #38
How to Use a DHT11 Humidity Sensor on the Arduino – Ultimate Guide to the Arduino #38

Arduino Code – DHT11

Quick Steps
  • Connect Arduino to PC via USB cable
  • Open Arduino IDE, select the right board and port
  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
  • Search “DHT”, then find the DHT sensor library by Adafruit
  • Click Install button to install the library.
  • You will be asked for intalling some other library dependencies
  • Click Install All button to install all library dependencies.
  • Copy the above code corresponding to the sensor you have and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Make enviroment around sensor hotter or colder
  • See the result on Serial Monitor.

Installing DHT library

The DHT sensors has their own proprietary single-wire data transfer protocol. This protocol requires precise timing. We don’t have to worry too much about this, though, because we’ll be using the DHTlib library, which handles almost everything.

To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the libraries index and update the list of installed libraries.

Filter your search by entering ‘dhtlib’.There should only be a single entry. Click on that and then choose Install.

DHT11 Sensor Module with Arduino Temperature and Humidity
DHT11 Sensor Module with Arduino Temperature and Humidity

Inside the DHT11 Sensor

If you remove the sensor’s casing, you will find an NTC thermistor and a humidity sensing component inside.

The humidity sensing component has two electrodes with a moisture-holding substrate (usually a salt or conductive plastic polymer) in between.

As the humidity rises, the substrate absorbs water vapor, resulting in the release of ions and a decrease in the resistance between the two electrodes.

This change in resistance is proportional to the humidity, which can be measured to estimate relative humidity.

DHt11 also includes a NTC thermistor for measuring temperature. A thermistor is a type of resistor whose resistance varies with temperature.

Technically, all resistors are thermistors in the sense that their resistance changes slightly with temperature, but this change is typically very small and difficult to measure. Thermistors are designed so that their resistance changes dramatically with temperature (by 100 ohms or more per degree). The term “NTC” stands for “Negative Temperature Coefficient,” which means that resistance decreases as temperature rises.

The sensor also includes an 8-bit SOIC-14 packaged IC. This IC measures and processes the analog signal using stored calibration coefficients, converts the analog signal to digital, and outputs a digital signal containing the temperature and humidity.

Arduino Example 2 – Displaying Readings on LCD

If you’re constructing your own incubator or a similar project, you’ll need a 16×2 character LCD rather than a serial monitor to display the current temperature and humidity levels. So, in this example, we’ll also connect the LCD to the Arduino in addition to the DHT11 module.

This is what the output looks like.

If you are unfamiliar with 16×2 character LCDs, consider reading the tutorial below.

SUGGESTED READING

Wiring

Following that, connect the LCD as shown below.

Arduino Code

The sketch below will display the temperature and relative humidity values on the 16×2 character LCD. This sketch is similar to the previous one, except that the values are printed on the LCD.


#include // Include LiquidCrystal Library #include

#define outPin 8 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Create an LCD object. dht DHT; // Create a DHT object void setup() { lcd.begin(16,2); // Initialize the LCD } void loop() { int readData = DHT.read11(outPin); float t = DHT.temperature; float h = DHT.humidity; lcd.setCursor(0,0); lcd.print("Temp.: "); lcd.print(t); lcd.print((char)223); //shows degrees character lcd.print("C"); lcd.setCursor(0,1); lcd.print("Humi.: "); lcd.print(h); lcd.print("%"); delay(2000); }

Components and supplies

SSD1306 OLED 128X64 0.96 inch – I2C

DHT11 Temperature & Humidity Sensor (3 pins)

Jumper wires (generic)

Solderless Breadboard Half Size

Arduino UNO

Apps and platforms

Arduino IDE

Project description

Code

weather station code

c_cpp

1#include “DHT.h” 2#define DHT11Pin 2 3#define DHTType DHT11 4//OLED 5#include

6#include

7#include

8 9DHT HT(DHT11Pin,DHTType); 10float humi; 11float tempC; 12float tempF; 13 14//OLED define 15#define SCREEN_WIDTH 128 // OLED display width, in pixels 16#define SCREEN_HEIGHT 64 // OLED display height, in pixels 17// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 18Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); 19 20void setup() { 21 Serial.begin(9600); 22 //For DHT11 23 HT.begin(); 24 //For OLED I2C 25 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128×64 26 Serial.println(F(“SSD1306 allocation failed”)); 27 for(;;); 28 } 29 display.display(); //Display logo 30 delay(1000); 31 display.clearDisplay(); 32} 33 34void loop() { 35 delay(1000); 36 humi = HT.readHumidity(); 37 tempC = HT.readTemperature(); 38 tempF = HT.readTemperature(true); 39 40 Serial.print(“Humidity:”); 41 Serial.print(humi,0); 42 Serial.print(“%”); 43 Serial.print(” Temperature:”); 44 Serial.print(tempC,1); 45 Serial.print(“C ~ “); 46 Serial.print(tempF,1); 47 Serial.println(“F”); 48 49 display.clearDisplay(); 50 oledDisplayHeader(); 51 52 53 oledDisplay(3,5,28,humi,”%”); 54 oledDisplay(2,70,16,tempC,”C”); 55 oledDisplay(2,70,44,tempF,”F”); 56 57 display.display(); 58 59} 60void oledDisplayHeader(){ 61 display.setTextSize(1); 62 display.setTextColor(WHITE); 63 display.setCursor(0, 0); 64 display.print(“Humidity”); 65 display.setCursor(60, 0); 66 display.print(“Temperature”); 67} 68void oledDisplay(int size, int x,int y, float value, String unit){ 69 int charLen=12; 70 int xo=x+charLen*3.2; 71 int xunit=x+charLen*3.6; 72 int xval = x; 73 display.setTextSize(size); 74 display.setTextColor(WHITE); 75 76 if (unit==”%”){ 77 display.setCursor(x, y); 78 display.print(value,0); 79 display.print(unit); 80 } else { 81 if (value>99){ 82 xval=x; 83 } else { 84 xval=x+charLen; 85 } 86 display.setCursor(xval, y); 87 display.print(value,0); 88 display.drawCircle(xo, y+2, 2, WHITE); // print degree symbols ( ) 89 display.setCursor(xunit, y); 90 display.print(unit); 91 } 92 93} 94


weather station code

c_cpp

1#include “DHT.h” 2#define DHT11Pin 2 3#define DHTType DHT11 4//OLED 5#include

6#include

7#include

8 9DHT HT(DHT11Pin,DHTType); 10float humi; 11float tempC; 12float tempF; 13 14//OLED define 15#define SCREEN_WIDTH 128 // OLED display width, in pixels 16#define SCREEN_HEIGHT 64 // OLED display height, in pixels 17// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 18Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); 19 20void setup() { 21 Serial.begin(9600); 22 //For DHT11 23 HT.begin(); 24 //For OLED I2C 25 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128×64 26 Serial.println(F(“SSD1306 allocation failed”)); 27 for(;;); 28 } 29 display.display(); //Display logo 30 delay(1000); 31 display.clearDisplay(); 32} 33 34void loop() { 35 delay(1000); 36 humi = HT.readHumidity(); 37 tempC = HT.readTemperature(); 38 tempF = HT.readTemperature(true); 39 40 Serial.print(“Humidity:”); 41 Serial.print(humi,0); 42 Serial.print(“%”); 43 Serial.print(” Temperature:”); 44 Serial.print(tempC,1); 45 Serial.print(“C ~ “); 46 Serial.print(tempF,1); 47 Serial.println(“F”); 48 49 display.clearDisplay(); 50 oledDisplayHeader(); 51 52 53 oledDisplay(3,5,28,humi,”%”); 54 oledDisplay(2,70,16,tempC,”C”); 55 oledDisplay(2,70,44,tempF,”F”); 56 57 display.display(); 58 59} 60void oledDisplayHeader(){ 61 display.setTextSize(1); 62 display.setTextColor(WHITE); 63 display.setCursor(0, 0); 64 display.print(“Humidity”); 65 display.setCursor(60, 0); 66 display.print(“Temperature”); 67} 68void oledDisplay(int size, int x,int y, float value, String unit){ 69 int charLen=12; 70 int xo=x+charLen*3.2; 71 int xunit=x+charLen*3.6; 72 int xval = x; 73 display.setTextSize(size); 74 display.setTextColor(WHITE); 75 76 if (unit==”%”){ 77 display.setCursor(x, y); 78 display.print(value,0); 79 display.print(unit); 80 } else { 81 if (value>99){ 82 xval=x; 83 } else { 84 xval=x+charLen; 85 } 86 display.setCursor(xval, y); 87 display.print(value,0); 88 display.drawCircle(xo, y+2, 2, WHITE); // print degree symbols ( ) 89 display.setCursor(xunit, y); 90 display.print(unit); 91 } 92 93} 94


Downloadable files

Weather station schematic

Weather station schematic

Comments

Only logged in users can leave comments

herolivechannel

0 Followers

0 Projects

Table of contents

Intro

Arduino – DHT11

In this tutorial, we are going to learn:

  • How to connect DHT11 sensor to Arduino
  • How to connect DHT11 module to Arduino
  • How to program Arduino to read temperature and humidity value from DHT11 sensor and module
Arduino Tutorial 50: How to Connect and Use the DHT11 Temperature and Humidity Sensor
Arduino Tutorial 50: How to Connect and Use the DHT11 Temperature and Humidity Sensor

Display Humidity and Temperature on an LCD

A nice way to display the humidity and temperature readings is on a 16X2 LCD. To do this, first follow our tutorial on How to Set Up an LCD Display on an Arduino, then upload this code to the Arduino:


#include

#include LiquidCrystal lcd(12, 11, 5, 4, 3, 2); dht DHT; #define DHT11_PIN 7 void setup(){ lcd.begin(16, 2); } void loop(){ int chk = DHT.read11(DHT11_PIN); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(DHT.temperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0,1); lcd.print("Humidity: "); lcd.print(DHT.humidity); lcd.print("%"); delay(1000); }

What is Relative Humidity?

The DHT11 measures relative humidity. Relative humidity is the amount of water vapor in air vs. the saturation point of water vapor in air. At the saturation point, water vapor starts to condense and accumulate on surfaces forming dew.

The saturation point changes with air temperature. Cold air can hold less water vapor before it becomes saturated, and hot air can hold more water vapor before it becomes saturated.

The formula to calculate relative humidity is:

Relative humidity is expressed as a percentage. At 100% RH, condensation occurs, and at 0% RH, the air is completely dry.

DHT11 Temperature and humidity sensor using arduino with LCD disply tutorial
DHT11 Temperature and humidity sensor using arduino with LCD disply tutorial

About DHT11 Temperature and Humidity Sensor

DHT11
Operating Voltage 3 to 5V
Temperature Range 0°C to 50°C
Temperature Accuracy ± 2°C
Humidity Range 20% to 80%
Humidity Accuracy 5%
Reading Rate 1Hz (once every second)

Pinout

DHT11 has two forms: sensor and module.

DHT11 sensor has four pins:

  • GND pin: needs to be connected to GND (0V)
  • VCC pin: needs to be connected to VCC (5V, or 3.3V)
  • DATA pin: the pin is used to communicate between the sensor and Arduino
  • NC pin: Not connected, we can ignore this pin

DHT11 module has three pins:

  • GND pin: needs to be connected to GND (0V)
  • VCC pin: needs to be connected to VCC (5V, or 3.3V)
  • DATA pin: the pin is used to communicate between the sensor and Arduino

Some manufacturers provide DHT11 sensor in module form with three pins: GND, VCC and DATA pins (or alternatively: -, +, and OUT pins).

Wiring Diagram

In sensor form, A resistor from 5K to 10K Ohms is required to keep the data line high and in order to enable the communication between the DHT11 sensor and the Arduino

Arduino – DHT11 Sensor Wiring

This image is created using Fritzing. Click to enlarge image

Arduino – DHT11 Module Wiring

Most of DHT11 sensor modules have a built-in resistor, so you don’t need to add it. it saves us some wiring or soldering works.

This image is created using Fritzing. Click to enlarge image

dht11 temperature & humidity sensor with arduino
dht11 temperature & humidity sensor with arduino

Step 3: Code

#include

dht DHT11;

#define DHT11_PIN A0

void setup() {

Serial.begin(9600);

Serial.println(“DHT11 SFE Electronics”);

void loop() {

int chk = DHT11.read11(DHT11_PIN);

Serial.print(” Humidity ” );

Serial.print(DHT11.humidity, 1);

Serial.print(” “);

Serial.print(” Temparature “);

Serial.println(DHT11.temperature, 1);

delay(2000);

Want to keep a log of the climate in your greenhouse, build a humidor control system, or track temperature and humidity data for a weather station project? AOSONG’s DHT11 Temperature and Humidity sensor module could be the perfect fit for you!

This sensor is factory-calibrated and does not require any external components to function. With just a few connections and a bit of Arduino code, you can begin measuring relative humidity and temperature right away.

DHT11 Module Hardware Overview

At the heart of the module is the digital temperature and humidity sensor manufactured by AOSONG – DHT11.

DHT11 Sensor

DHT11 can measure temperature from 0°C to 50°C with a ±2.0°C accuracy, and humidity from 20 to 80% with a 5% accuracy.

Note that the DHT11 has a sampling rate of 1Hz, which means it can provide new data once every second.

Supporting Circuitry

The module includes all of the necessary supporting circuitry, so it can be used straight out of the box.

DHT11 sensors typically require an external 10K pull-up resistor on the output pin for proper communication between the sensor and the Arduino. However, because the module already includes a pull-up resistor, you do not need to add one.

The module also includes a decoupling capacitor for filtering power supply noise.

DHT11 and DHT22 Sensor Using with Arduino
DHT11 and DHT22 Sensor Using with Arduino

How the DHT11 Measures Humidity and Temperature

The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity sensing component is a moisture holding substrate with electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.

The DHT11 measures temperature with a surface mounted NTC temperature sensor (thermistor) built into the unit. To learn more about how thermistors work and how to use them on the Arduino, check out our Arduino Thermistor Temperature Sensor Tutorial.

With the plastic housing removed, you can see the electrodes applied to the substrate:

An IC mounted on the back of the unit converts the resistance measurement to relative humidity. It also stores the calibration coefficients, and controls the data signal transmission between the DHT11 and the Arduino:

The DHT11 uses just one signal wire to transmit data to the Arduino. Power comes from separate 5V and ground wires. A 10K Ohm pull-up resistor is needed between the signal line and 5V line to make sure the signal level stays high by default (see the datasheet for more info).

There are two different versions of the DHT11 you might come across. One type has four pins, and the other type has three pins and is mounted to a small PCB. The PCB mounted version is nice because it includes a surface mounted 10K Ohm pull up resistor for the signal line. Here are the pin outs for both versions:

Using the Data in Other Programs

What if you don’t want to output the actual humidity and temperature readings, but need them to calculate or control other things? The code below is the bare minimum needed to initialize the sensor. You can add this to existing programs and use

DHT.humidity

and

DHT.temperature

as variables in any function.


#include

dht DHT; #define DHT11_PIN 7 void setup(){ } void loop(){ int chk = DHT.read11(DHT11_PIN); delay(1000); }

To see an example of using the DHT11 sensor outputs as variables in other functions, check out our article How to Set Up an Ultrasonic Range Finder on an Arduino, where we use the

DHT.humidity

and

DHT.temperature

variables in a formula that improves the accuracy of an ultrasonic range finder.

You can watch how to set up the DHT11 and see how it works in this video:

If you have any questions about how to set up the DHT11 humidity and temperature sensor on your Arduino, just leave a comment below and I will try to answer it… And if you like our tutorials, please subscribe! Also, feel free to share this if you know anyone else that might find it helpful!

DHT11 Module features a temperature & humidity sensor complex with a calibrated digital signal output. The exclusive digital-signal-acquisition technique and temperature & humidity sensing technology ensure high reliability and excellent long-term stability. This sensor includes an NTC for temperature measurement and a resistive-type humidity measurement component for humidity measurement. These are connected to a high-performance 8-bit microcontroller, offering excellent quality, fast response, anti-interference ability, and cost-effectiveness.

DHT11 Module Pinout

The DHT11 module has a total of 3 pins. In which two are for power and one is for communication. The pinout of a DHT11 Sensor module is as follows:

DATA Data pin for 1-wire communication.

GND Ground Connected to Ground pin of the Arduino.

VCC Provides power for the module, Connect to the 5V pin of the Arduino.

DHT11 Module Parts

The DHT11 module has only a very low number of parts that includes the DHT11, pullup resistor, bypass capacitor, and power led with a current limiting resistor.

DHT11 Module Circuit Diagram

The schematic diagram for the DHT11 module is given below. As mentioned earlier, the board has a very low components count. The VCC and GND are directly connected to the DHT11 and a pullup resistor is added to the DATA pin. Sufficient filtering is provided with the tantalum and multilayer capacitors. An LED with a current limit resistor is used as a power indicator.

Commonly Asked Questions about DHT11 Sensor

What does a DHT11 do?

The DHT11 is a basic, ultra-low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and sends data through a 1-wire protocol.

How accurate is DHT11?

DHT11 can measure temperature from 0-50⁰C with a 2% accuracy and relative humidity from 20-80% with an accuracy of 5%.

Is the DHT11 waterproof?

No. It’s not waterproof.

What’s the sampling rate of a DHT11 sensor?

DHT11 has a sampling rate of 1Hz.

How does DHT11 Work?

As already mentioned, DHT11 has an NTC thermistor and humidity sensing components. When the temperature changes, the resistance of the NTC also changes. This change in resistance is measured and the temperature is calculated from it. We have already discussed how to use the NTC thermistor with Arduino.

The humidity sensing component consists of a moisture-holding substrate sandwiched in between two electrodes. When the substrate absorbs water content, the resistance between the two electrodes decreases. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes. This change in resistance is measured with the onboard MCU’s ADC and the relative humidity is calculated.

Each DHT11 element is strictly calibrated in the laboratory which is extremely accurate in humidity calibration. The calibration coefficients are stored as programmes in the OTP memory, which are used by the sensor’s internal signal detecting process.

DHT11 1-Wire Communication Protocol

Single-bus data format is used for communication and synchronization between MCU and DHT11 sensor. One communication process is about 4ms. Data consists of decimal and integral parts. Complete data transmission is 40bit, and the sensor sends higher data bit first. Data format is as follows: 8bit integral RH data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data + 8bit checksum. If the data transmission is right, the check-sum should be the last 8bit of “8bit integral RH data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data”.

When MCU sends a start signal, DHT11 changes from the low-power-consumption mode to the running mode, waiting for MCU to complete the start signal. Once it is completed, DHT11 sends a response signal of 40-bit data that include the relative humidity and temperature information to the MCU. Users can choose to collect (read) some data. Without the start signal from MCU, DHT11 will not give the response signal to MCU. Once data is collected, DHT11 will change to the low power-consumption mode until it receives a start signal from MCU again.

The above image shows the communication timing diagram.

Circuit Diagram for Interfacing DHT11 Sensor with Arduino

Now that we have completely understood how a DHT11 Sensor works, we can connect all the required wires to Arduino and write the code to get all the data out from the sensor. The following image shows the circuit diagram for interfacing the DHT11 sensor module with Arduino.

Connections are pretty simple and only require three wires. Connect the VCC and GND of the module to the 5V and GND pins of the Arduino. Then connect the DATA pin to the Arduino’s digital pin 2. We communicate with DHT11 through this pin.

Arduino DHT11 Code for Interfacing the Sensor Module

Now let’s look at the code for interfacing the DHT11 sensor. For that first install the Adafruit’s DHT sensor library and Adafruit Unified Sensor Driver through the library manager. Then create a blank sketch and paste the code at the end of this article into it.

#include

#include

#include

#define DHTTYPE DHT11 // DHT 11 #define DHTPIN 2 DHT_Unified dht(DHTPIN, DHTTYPE); uint32_t delayMS;


In the starting, we have included all the necessary libraries and defined the sensor type as DHT11 and the sensor pin as digital pin 2. And then created an instance for the DHT library. Also created a variable to declare the minimum delay.

void setup() { Serial.begin(9600); dht.begin(); sensor_t sensor; delayMS = sensor.min_delay / 1000; }

In the setup function, we have initialized serial communication and the DHT library. Then the minimum delay for the data refresh.

void loop() { sensors_event_t event; dht.temperature().getEvent(&event); Serial.print(F(“Temperature: “)); Serial.print(event.temperature); Serial.println(F(“°C”)); dht.humidity().getEvent(&event); Serial.print(F(“Humidity: “)); Serial.print(event.relative_humidity); Serial.println(F(“%”)); delay(delayMS); }

In the loop function, we have created an event and using this event the temperature and humidity data is read from the DHT11 sensor. Then this value is printed to the serial monitor. The below GIF shows the DHT11 interface.

Projects using DHT11 Sensor

There are some interesting projects done with the DHT11 Sensor. If you want to know more about those topics, links are given below.

In this project, we will measure Humidity, Temperature and Pressure parameters and display them on the web server, which makes it a IoT based Weather Station where the weather conditions can be monitored from anywhere using the Internet.

In this project, we are going to make a small Automatic Temperature Control Circuit that could minimize the electricity charges by varying the AC temperature automatically based on the Room’s temperature.

In this project, we are going to build a temperature-controlled fan using Arduino. With this circuit, we will be able to adjust the fan speed in our home or office according to the room temperature and also show the temperature and fan speed changes on a 16×2 LCD display.

Supporting Files

#include

#include

#include

#define DHTTYPE DHT11 // DHT 11

#define DHTPIN 2

DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

void setup() {

Serial.begin(9600);

dht.begin();

sensor_t sensor;

delayMS = sensor.min_delay / 1000;

void loop()

sensors_event_t event;

dht.temperature().getEvent(&event);

Serial.print(F(“Temperature: “));

Serial.print(event.temperature);

Serial.println(F(“°C”));

dht.humidity().getEvent(&event);

Serial.print(F(“Humidity: “));

Serial.print(event.relative_humidity);

Serial.println(F(“%”));

delay(delayMS);

🌡️🌤️Arduino Weather Station ll DHT 11 Temperature Humidity Sensor in tamil
🌡️🌤️Arduino Weather Station ll DHT 11 Temperature Humidity Sensor in tamil

Components and supplies

DHT22 Temperature Sensor

DHT11 Temperature & Humidity Sensor (4 pins)

DHT11 Temperature & Humidity Sensor (3 pins)

Jumper wires (generic)

Arduino UNO

Breadboard (generic)

Apps and platforms

Arduino IDE

Project description

Code

DHT11 Library

Don’t forget to add this library to the Arduino IDE.

DHT11.ino

arduino

The code for receiving the data from the DHT11 and printing it out on the serial monitor.

DHT11 Library

Don’t forget to add this library to the Arduino IDE.

Downloadable files

Schematics

Schematics

Schematics

Schematics

Comments

Only logged in users can leave comments

arcaegecengiz

0 Followers

0 Projects

Table of contents

Intro

59

Đọc nhiệt độ, độ ẩm (DHT11) sử dụng Arduino Uno

Cảm biến nhiệt độ, độ ẩm DHT11 là gì?

Ứng dụng trong thực tế ra sao?

Cảm biến dùng chuẩn giao tiếp gì?

Là những câu hỏi mà những ai mới nhập môn đều muốn biết.

Qua bài viết hôm này chúng ta cùng nhau tìm hiểu nhé.

How To Program For DHT11 Temperature Sensor

Programming for both sensors is similar. There is only one line of code different.

  • Include the library:
  • Define the Arduino pin connected to DHT sensor:
  • Declare DHT11 object
  • Initialize the sensor:
  • Read humidity:
  • Read temperature in Celsius:
  • Read temperature in Fahrenheit:
How to use ESP8266 NodeMCU with DHT11 Temperature and Humidity Sensor
How to use ESP8266 NodeMCU with DHT11 Temperature and Humidity Sensor

Sơ đồ đấu nối

Arduino Uno Cảm biến nhiệt độ, độ ẩm DHT11
5V VCC
GND GND
D4 DATA

Các linh kiện cần thiết cho dự án:

Tên linh kiện Số lượng Shopee
Arduino Uno R3 Mua ngay
Dây cáp nạp Mua ngay
Cảm biến nhiệt độ, độ ẩm DHT11 Mua ngay
Breadboard (Board Test) Mua ngay
Dây cắm (Đực – Đực) Mua ngay

Bạn sẽ học được gì

  • Có kiến thức cơ bản về Robotics
  • Chế tạo Robot dò đường thông minh
  • Đánh thức nhà khoa học bên trong bạn
  • Tìm hiểu thêm về Robotics, các thuật toán Robot tự động
  • Kiến thức nền tảng để chế tạo các máy móc tự động phục vụ đời sống sinh hoạt, lao động sản xuất
  • Kiến thức để chế tạo sản phẩm, tham gia các cuộc thi khoa học công nghệ trong nước và quốc tế

DHT11 Module Pinout

The DHT11 module is relatively simple to connect. There are only three pins:

+ (VCC) pin provides power to the sensor. Despite the fact that the supply voltage of the module ranges from 3.3V to 5.5V, a 5V supply is recommended. With a 5V power supply, the sensor can be placed up to 20 meters away. With 3.3V supply voltage, the sensor can be placed just 1 meter away; otherwise, the line voltage drop will cause measurement errors.

Out pin is used for communication between the sensor and the microcontroller.

– (GND) is the ground pin.

DHT 11 sensor with relay control
DHT 11 sensor with relay control

Keywords searched by users: dht11 sensor arduino code

How To Connect Dht11 Sensor With Arduino Uno - Hackster.Io
How To Connect Dht11 Sensor With Arduino Uno – Hackster.Io
Dht11 Sensor Module With Arduino Temperature And Humidity - Youtube
Dht11 Sensor Module With Arduino Temperature And Humidity – Youtube
How To Use A Dht11 Humidity Sensor On The Arduino - Ultimate Guide To The  Arduino #38 - Youtube
How To Use A Dht11 Humidity Sensor On The Arduino – Ultimate Guide To The Arduino #38 – Youtube
Dht11/Dht22 Sensor With Arduino Tutorial (2 Examples)
Dht11/Dht22 Sensor With Arduino Tutorial (2 Examples)
Dht11 Arduino Interfacing - The Engineering Projects
Dht11 Arduino Interfacing – The Engineering Projects
Dht11/Dht22 Sensor With Arduino | Random Nerd Tutorials
Dht11/Dht22 Sensor With Arduino | Random Nerd Tutorials
In-Depth: Interfacing Dht11 And Dht22 Sensors With Arduino
In-Depth: Interfacing Dht11 And Dht22 Sensors With Arduino
Arduino - Cooling System Using Dht Sensor | Arduino Tutorial
Arduino – Cooling System Using Dht Sensor | Arduino Tutorial
Arduino Dht11 Sensor Interfacing With Arduino Uno | Arduino
Arduino Dht11 Sensor Interfacing With Arduino Uno | Arduino
How To Interface Dht11 Temperature And Humidity Sensor With Arduino Nano
How To Interface Dht11 Temperature And Humidity Sensor With Arduino Nano
Dht11 Humidity And Temperature Sensor On Arduino With Lcd
Dht11 Humidity And Temperature Sensor On Arduino With Lcd
Interface Dht11 Sensor With Arduino And Lcd - Iot Projects Ideas
Interface Dht11 Sensor With Arduino And Lcd – Iot Projects Ideas
In-Depth: Interface Dht11 Module With Arduino
In-Depth: Interface Dht11 Module With Arduino
Dht11/Dht22 Sensor With Arduino | Random Nerd Tutorials
Dht11/Dht22 Sensor With Arduino | Random Nerd Tutorials
Interfacing Dht11 With Arduino | Dht11 Temperature And Humidity Sensor  Arduino Code » Electroduino
Interfacing Dht11 With Arduino | Dht11 Temperature And Humidity Sensor Arduino Code » Electroduino

See more here: kientrucannam.vn

Leave a Reply

Your email address will not be published. Required fields are marked *