DHT11
Component | DHT11 |
Type | Sensor |
Function | Measure temperature and humidity |
Introduction
The DHT11 is a low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on the data pin. The sensor is commonly used in weather stations, home automation systems, and other environmental monitoring applications.
Pin Description
The DHT11 sensor has four pins: VCC, Data, NC (not connected), and GND. The VCC pin is connected to the power supply (3.3V to 5V), the GND pin is connected to ground, and the Data pin is connected to a digital pin on a microcontroller. The sensor communicates with the microcontroller using a single-wire protocol.
Code Example
The following code example demonstrates how to read the temperature and humidity values from the DHT11 sensor using an Arduino board.
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 |
|
(This example uses the DHT library to read the temperature and humidity values from the sensor. The values are then printed to the serial port. You can view the output using the Serial Monitor in the Arduino IDE. Make sure to install the DHT library before using this code example. You can find the library in the Arduino Library Manager.)