Integrated digital temperature and humidity sensor temperature and humidity sensor is DHT11 comprising a calibrated digital signal output, commonly used in the HVAC, automotive, dehumidifier, automatic control and other fields. This introduction DHT11 drive, collected through a serial printer temperature and humidity data.
Introduction 1. DHT11
DHT11 is an integral digital temperature and humidity sensor, comprising an inner resistive element and measuring a wet NTC temperature measurement element, and is connected to a high-performance 8-bit microcontroller. Requiring only a simple circuit, the local real-time acquisition of temperature and humidity can. DHT11 and simple microcontroller and the single communication bus, only one I / O port. Internal temperature and humidity sensor 40Bit be passed to a microcontroller data, using the checksum data verification manner, effectively ensure the accuracy of data transmission.
DHT11 technical parameters as follows:
- Operating voltage: 3.3V-5.5V
- Current: 0.5mA average
- Output: single wire digital signal
- Measurement range: Humidity 20-95% RH, temperature 0-50 ℃
- Accuracy: Humidity ± 5%, ± 2 ℃ temperature
- Resolution: 1% humidity, temperature 1 ℃
DHT11 pin arrangement, the aperture upward, left to right VCC, Dout, NC, GND.
DHT11 circuit connection, the pull-up resistor is usually outside the data pin, as follows DHT11 modules:
2. Install the driver library
Click on "Project" in the Arduino IDE - the "load library" - "management library" enter "dht11", will see a lot of libraries, can choose to install their own use under the circumstances. Select the second article "DHT sensor library" to install.
To use the "DHT sensor library," we have to download and install "Adafruit_Sensor" It should be noted that this library is not found in the database management, we directly on Github Download .
After downloading the archive, click on the "project" in the IDE - "load library" - "add a .ZIP Library", navigate to just download the compressed package to install.
3. Experimental Materials
- Uno R3 Development Board
- Supporting USB data cable
- Bread plate and supporting cables
- DHT11 sensor module
4. Experimental Procedure
1. The schematic circuit diagram of a building.
DHT11 single bus connection is very simple, the module VCC, GND are connected to the 3.3V development board, the GND any number, module development board DATA pin connector pins connecting the digital pin 2 herein.
Principle is shown below:
Physical connection is shown below:
2. Create a new sketch, the following code replacement copies of the automatically generated code and save it.
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 test");
dht.begin();
}
void loop() {
float h = dht.readHumidity();//读湿度
float t = dht.readTemperature();//读温度(摄氏度)
Serial.print("Humidity:");
Serial.print(h);
Serial.print("% Temperature:");
Serial.print(t);
Serial.println("℃");
delay(2000);
}
3. Development Board connector, and set the port number corresponding to the type of boards, for download.
The experimental results
Open serial monitor, to be consistent with the baud rate setting program can be seen spaced to print the temperature and humidity data collected.
Focus on micro-channel public number: TonyCode
the Arduino learning exchange group: 868 283 450
More, I welcome the attention of the public number. Sweep the micro-channel to follow the Fanger Wei code: