Chuyển tới nội dung
Home » Arduino Temperature Sensor Dht11 | Arduino Example 2 – Displaying Readings On Lcd

Arduino Temperature Sensor Dht11 | Arduino Example 2 – Displaying Readings On Lcd

DHT11 Temperature & Humidity sensor with Arduino - Tutorial

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!

Step 4: Well Done!

You have successfully completed one more Arduino “How to” tutorial and you learned how to use the DHT-11 sensor.

I hope you liked this, let me know in the comments. There will be more of them, so make sure to click Follow button!

IoT – Internet of Things

Artificial Intelligence

Single Board Computer

STEM EDUCATION

Mạch điện – Module

  • Mạch thu phát sóng RF
  • Màn hình LCD
  • Mạch điều khiển động cơ
  • Điều khiển & Bàn phím & Joystick
  • Dimmer & phát xung PWM
  • Giao tiếp & Chuyển đổi
  • Âm thanh & Khuếch đại Amply
  • Đóng ngắt & Relay
  • Nguồn xung & Giảm, tăng áp & Sạc pin
  • Thời gian & Hiển thị & Còi, Buzzer
  • Kit phát triển & Mạch nạp
  • Đế chuyển Adapter

Cảm biến – Sensor

  • Ánh sáng & Âm thanh & Màu sắc
  • Chuyển động & Rung
  • Đo Dòng điện & Điện thế
  • Dò line & Encoder & Vận tốc
  • Gia tốc & Góc nghiêng & La bàn
  • Sinh học & Môi trường
  • Hình ảnh & Barcode, QR
  • Từ trường & Kim loại & Điện dung
  • Nhiệt độ & Độ ẩm & Mưa
  • Áp suất & Lưu lượng & Cân nặng
  • Khoảng cách & Vật cản & Radar
  • Sò nóng lạnh Peltier

Robot – Điều khiển

  • Khung Robot
  • Phụ kiện Robot
  • Bánh xe
  • Động cơ
  • Động cơ bơm, thổi & Van điện từ
  • Mạch điều khiển Động cơ
  • Pin & Sạc
  • Pin Năng Lượng Mặt Trời Solar Panel
  • Máy in 3D & CNC Mini

Phụ kiện và dụng cụ

Thương hiệu phân phối

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 Temperature & Humidity sensor with Arduino - Tutorial
DHT11 Temperature & Humidity sensor with Arduino – Tutorial

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ế

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:

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 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);

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 temperature and humidity sensor with Arduino [code explained] | Arduino tutorial 15
DHT11 temperature and humidity sensor with Arduino [code explained] | Arduino tutorial 15

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.

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); }

How to Set Up the DHT11 Humidity and Temperature Sensor on an Arduino
How to Set Up the DHT11 Humidity and Temperature Sensor on an Arduino

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é.

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); }

Get Started in Electronics #9 - Using the DHT11 Humidity & Temp Sensor
Get Started in Electronics #9 – Using the DHT11 Humidity & Temp Sensor

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é.

Introduction: How to Use the DHT-11 Sensor- Arduino Tutorial

The DHT-11 is a digital-output relative humidity and temperature sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air. Compared to the DHT22, this sensor is less precise, less accurate and works in a smaller range of temperature and humidity, but its smaller and less expensive.

Technical details:

  • Power: 3-5V
  • Current: 2.5mA
  • Humidity: 20-95%, ±5% accuracy
  • Temperature: 0 to 50°C, ±2°C accuracy

You can find DHT-22 tutorialhere.

In this tutorial you will learn how to use this sensor with Arduino uno. The room temperature & humidity will be printed to serial monitor.

So, let’s get started!

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

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

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

.

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

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.

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.

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

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:

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.

Arduino Weather Station || dht11 Temperature & Humidity sensor
Arduino Weather Station || dht11 Temperature & Humidity sensor

Keywords searched by users: arduino temperature sensor dht11

Arduino Dht11 Sensor Interfacing With Arduino Uno | Arduino
Arduino Dht11 Sensor Interfacing With Arduino Uno | Arduino
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
Using Dht11 | Arduino Project Hub
Using Dht11 | Arduino Project Hub
How To Set Up The Dht11 Humidity And Temperature Sensor On An Arduino -  Youtube
How To Set Up The Dht11 Humidity And Temperature Sensor On An Arduino – Youtube
Dht11 Humidity And Temperature Sensor On Arduino With Lcd
Dht11 Humidity And Temperature Sensor On Arduino With Lcd
Dht11 Digital Temperature And Humidity Sensor Dht11 Module For Arduino
Dht11 Digital Temperature And Humidity Sensor Dht11 Module For Arduino
Dht11 Temperature And Humidity Sensor Interfacing With Arduino - Embedded  Laboratory
Dht11 Temperature And Humidity Sensor Interfacing With Arduino – Embedded Laboratory
Arduino - Temperature Humidity Sensor | Arduino Tutorial
Arduino – Temperature Humidity Sensor | Arduino Tutorial
Humidity And Temperature Sensor Dht 11 With Arduino Tutorial
Humidity And Temperature Sensor Dht 11 With Arduino Tutorial
In-Depth: Interface Dht11 Module With Arduino
In-Depth: Interface Dht11 Module With Arduino
Dht11 Temperature And Relative Humidity Sensor Module For Arduino Diy Kit  (3) : Amazon.In: Industrial & Scientific
Dht11 Temperature And Relative Humidity Sensor Module For Arduino Diy Kit (3) : Amazon.In: Industrial & Scientific
How To Interface Humidity And Temperature (Dht11) Sensor To Arduino And  Including Dht11 Library. - Instructables
How To Interface Humidity And Temperature (Dht11) Sensor To Arduino And Including Dht11 Library. – Instructables
Arduino Dht11 Sensor Interfacing - Temperature And Humidity Measurement –  Quartzcomponents
Arduino Dht11 Sensor Interfacing – Temperature And Humidity Measurement – Quartzcomponents
Dht11 Sensor Module With Arduino Temperature And Humidity - Youtube
Dht11 Sensor Module With Arduino Temperature And Humidity – Youtube
How To Set Up The Dht11 Humidity And Temperature Sensor With Arduino -
How To Set Up The Dht11 Humidity And Temperature Sensor With Arduino –
Dht11 Humidity And Temperature Sensor On Arduino With Lcd
Dht11 Humidity And Temperature Sensor On Arduino With Lcd
Arduino Dht11 Sensor Interfacing With Arduino Uno | Arduino
Arduino Dht11 Sensor Interfacing With Arduino Uno | Arduino
How To Connect Dht11 Sensor With Arduino Uno - Hackster.Io
How To Connect Dht11 Sensor With Arduino Uno – Hackster.Io
Arduino - Cooling System Using Dht Sensor | Arduino Tutorial
Arduino – Cooling System Using Dht Sensor | Arduino Tutorial

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *