Cambien
Cambien
MECHANICAL SCHOOL
DEPARTMENT MECHATRONICS
SENSOR DHT11
Instructor: Dr. Tran Van Huong
Ha Noi - 2024
Contents
Chapter 1: Introduction..................................................................................2
1. Definition..................................................................................2
2. Technical specifications..........................................................5
Overview........................................................................................5
Detailed Specifications:.................................................................5
3. Structure..................................................................................6
Operating Principle.....................................................................15
Typical application......................................................................19
Voltage..........................................................................................22
Functions of pins:........................................................................26
1|P a g e
Chapter 1: Introduction
1. Definition
This DFRobot DHT11 Temperature & Humidity Sensor features a
temperature & humidity sensor complex with a calibrated digital signal
output. By using the exclusive digital-signal-acquisition technique and
temperature & humidity sensing technology, it ensures high reliability and
excellent long-term stability.
Figure 1.1a.
2|P a g e
Figure 1.1b.
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:
Figure 1.1c.
3|P a g e
This sensor includes a resistive-type humidity measurement component
and an NTC temperature measurement component, and connects to a high
performance 8-bit microcontroller, offering excellent quality, fast response,
anti-interference ability and cost-effectiveness.
Figure 1.1d.
2. Technical specifications
Overview
4|P a g e
Detailed Specifications:
5|P a g e
3. Structure
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.
With the plastic housing removed, you can see the electrodes applied to
the substrate
Figure 1.3a.
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
6|P a g e
Figure 1.3b.
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.
Figure 1.3c.
Single-bus data format is used for communication and synchronization
between UNO and DHT11 sensor. One communication process is about 4ms.
Data consists of decimal and integral parts. A complete data transmission is
40bit, and the sensor sends higher data bit first. Data format: 8bit integral RH
data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data +
8bit check sum. 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".
7|P a g e
Figure 1.3d.
The DHT11 sensor consists of a capacitive humidity sensing element
and a thermistor to measure temperature. The capacitive humidity sensor has
two electrodes with a moisture-holding substrate serving as the dielectric
between them. Changes in capacitance occur with variations in humidity
levels. An IC measures and processes these changed resistance values and
converts them into a digital format.
To measure temperature, the sensor uses a thermistor with a negative
temperature coefficient, which reduces its resistance value as the temperature
increases. To achieve a higher resistance value even for the smallest
temperature changes, the thermistor is typically made of semiconductor
ceramics or polymers.
Chapter 2: Application of sensor
1. General introduction and practical application
What is Arduino, and why did we choose it as the solution for our
laboratory temperature monitoring system? In the simplest terms, Arduino is a
8|P a g e
microcontroller board and an open-source electronics platform, primarily
based on the AVR ATMEGA328P microcontroller. A standout feature of
Arduino is its highly user-friendly development environment, with a
programming language that can be quickly learned even by those with little
knowledge of electronics and programming. Notably, the cost of using
Arduino is very low, and its open-source nature—from hardware to software
—makes it advantageous compared to similar applications.
As a result, Arduino is not only widely applied around the world but is
also increasingly popular in Vietnam, especially in agriculture and industrial
production. This solution is favored by a diverse range of users, from students
and beginners exploring the application of technology in industrial and
agricultural production, to scientists and innovators developing smart
technology products.
9|P a g e
Figure 2.1b. Early warning to avoid fire and explosion
10 | P a g e
This feature allows for both real-time monitoring and adjustment, as
well as storing essential data for research and tracking purposes. Additionally,
the system can be connected to smartphones or computers, enabling easy
control and the ability to integrate additional accessories or devices to meet
specific needs.
11 | P a g e
Chapter 3: Choose the right equipment
1. Temperature sensor DHT11
12 | P a g e
Active voltage 3-5V (DC)
Consumed current 2.5 mA
Area of temper sensor 0-50°C
Size 15.5mm x 12mm x 5.5mm
Max fluency 1Hz means 1s the sensor takes a sample once
Max distance 20m
VCC pin: This is the power supply pin for the sensor. Although the
supply voltage ranges from 3V to 5V, it is recommended to use a 5V
power supply because, with a 5V power source, the sensor range can be
extended up to 20 meters. For a 3V power supply, the cable length
should not exceed 1 meter; otherwise, voltage drop along the wire will
lead to measurement inaccuracies.
DATA pin: This pin is used for communication between the sensor and
the microcontroller.
GND pin: This pin is connected to the ground.
N/C pin: Not connected.
Operating Principle
13 | P a g e
To measure temperature, these sensors use an NTC thermistor or
temperature sensor. The term "NTC" stands for "Negative Temperature
Coefficient," which means the resistance decreases as the temperature
increases, and vice versa.
14 | P a g e
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.
15 | P a g e
For Humidity Measurement, it uses a capacitive humidity sensor, which
has two electrodes and a substrate material in between.
The substrate material is used for holding the moisture on its surface.
As moisture content changes in our environment, they get saturated on
the substrate material, which in turn changes the resistance between
electrodes.
This change in electrode resistivity is then calibrated using the humidity
coefficient (saved in OTP memory) and the final relative humidity
value is released.
16 | P a g e
8 bits representing the integer part of the temperature
This value is like 8 bit checksum and hence the data received is valid.
Now to get the humidity and temperature values, just convert the binary data
to decimal data.
17 | P a g e
Typical application
Figure 3.1f.
18 | P a g e
A pull-up resistance of 5k ohm is recommended to place at the Data Pin
of the DHT11 sensor.
At normal conditions, the data pin of DHT11 remains at the HIGH
voltage level and the sensor remains in low power consumption mode.
To receive data from the DHT11 sensor, the microcontroller should
make the Data Pin low for at least 18us, so that the sensor could sense
it.
Once the DHT11 sensor senses the low signal at the Data Pin, it
changes its state from low power consumption mode to running
mode and waits for the Data Pin to get HIGH.
As the Data Pin gets HIGH again by the microcontroller, DHT11 sends
out the 40-bit calibrated output value serially.
After sending the data, DHT11 returns to low power consumption
mode and waits for the next command from the microcontroller.
The microcontroller has to wait for 20-40us to get a response from the
DHT11 sensor.
2. Arduino UNO R3
19 | P a g e
Microcontroller ATmega328 (8bit)
Active voltage 5V DC
Fluency 16 MHz
Current consumption 30mA
Advise voltage 7-12V DC
Limit voltage 6-20V DC
Digital I/O pins 14 (6 pins PWM)
Analog pins 6 (resolution 10bit)
Max current per pin I/O 30 mA
Out max current (5V) 500 mA
Out max current (3.3V) 50 mA
Cache flash 32 KB (0,5KB use for bootloader)
SRAM 2 KB
EEPROM 1 KB
20 | P a g e
Figure 3.2b. Details of the pins of arduino
Voltage
The Arduino UNO can be powered with 5V through the USB port or
via an external power source with a recommended voltage of 7-12V DC and a
limit of 6-20V. Typically, using a 9V battery is the most reasonable option if
USB power is not available. Supplying power beyond the upper limit will
damage the Arduino UNO.
GND (Ground): The negative terminal of the power supply for the
Arduino UNO. When using devices with separate power sources, these
GND pins must be connected together.
21 | P a g e
5V: Provides a 5V output voltage. The maximum allowable current on
this pin is 500mA.
IOREF: This pin allows you to measure the operating voltage of the
microcontroller on the Arduino UNO, which is always 5V. However,
you should not use this pin to draw 5V power, as it is not intended for
power supply purposes.
22 | P a g e
Figure 3.2c. The input and output pins of arduino
The Arduino UNO has 14 digital pins for reading or outputting signals.
They operate at two voltage levels: 0V and 5V, with a maximum input/output
current of 40mA per pin. Each pin has built-in pull-up resistors in the
ATmega328 microcontroller (these resistors are disabled by default). Some
digital pins have special functions as follows:
Serial Pins: 0 (RX) and 1 (TX): Used for transmitting (TX) and
receiving (RX) TTL Serial data. The Arduino UNO can communicate
with other devices through these pins. Bluetooth connections, for
instance, are essentially wireless Serial connections. If Serial
communication is not needed, it is recommended not to use these two
pins unnecessarily.
PWM Pins (~): 3, 5, 6, 9, 10, and 11: These allow for 8-bit PWM
output (values from 0 to 28−1, corresponding to 0V to 5V) using the
analogWrite() function. Simply put, these pins can output adjustable
voltages between 0V and 5V, instead of being fixed at either 0V or 5V
like the other pins.
SPI Communication Pins: 10 (SS), 11 (MOSI), 12 (MISO), 13
(SCK): In addition to their general-purpose functions, these four pins
are used for data transmission with other devices via the SPI protocol.
LED 13: The Arduino UNO has an orange LED labeled "L." When the
Reset button is pressed, this LED blinks as an indicator. It is connected
to pin 13. If this pin is used by the user, the LED will light up.
The Arduino UNO also has 6 analog pins (A0 to A5) providing 10-bit
resolution signals (0 to 210-1) for reading voltage values within the range of
0V to 5V. Using the AREF pin on the board, you can supply a reference
voltage for the analog pins. For example, if you supply 2.5V to the AREF
pin, the analog pins can measure voltages in the range of 0V to 2.5V with the
23 | P a g e
same 10-bit resolution. Additionally, the Arduino UNO features A4 (SDA)
and A5 (SCL) pins, which support I2C/TWI communication with other
devices.
3. Screen LCD 16x2
LCD display devices are used in many microcontroller applications and
offer various advantages that make them stand out compared to other display
devices. They can display a wide range of characters in a clear and intuitive
manner (letters, numbers, and graphic symbols, etc.), can be easily integrated
into application circuits in different ways, require minimal system resources,
and are cost-effective.
The 16×2 LCD has 16 pins, including 8 data pins (D0 – D7) and 3
control pins (RS, RW, E).
The remaining 5 pins are used to supply power and backlight for the
16×2 LCD.
24 | P a g e
They also help configure the LCD in read or write mode.
The 16×2 LCD can be used in either 4-bit or 8-bit mode, depending on
the application being developed..
Functions of pins:
25 | P a g e
+ Logic "1": The bus DB0-DB7 will connect to the data
register (DR) inside the LCD.
5 RW The Read/Write (R/W) pin: Connect the R/W pin to
logic "0" to set the LCD in write mode, or connect it to
logic "1" to set the LCD in read mode.
6 E The Enable (E) pin: After the signals are placed on the
bus DB0-DB7, the commands are accepted only when a
pulse is sent on the E pin.
+ In write mode: Data on the bus will be accepted by
the LCD into its internal register when a high-to-low
transition is detected on the E pin..
+ In read mode: Data will be output from the LCD to
DB0-DB7 when a low-to-high transition is detected on
the E pin, and the LCD will hold the data on the bus until
the E pin goes low.
7- DB0 - DB7 The eight data lines are used for communication with the
14 MPU. There are two modes for using these eight data
lines: + 8-bit mode: Data is transmitted over all 8 lines,
with the MSB being DB7.
+ 4-bit mode: Data is transmitted over 4 lines from DB4
to DB7, with the MSB being DB7
15 A VCC for the backlight
16 C GND for the backlight
26 | P a g e
Chapter 4: Device connection and simulation
Figure 4.1a.
Pin 2 (Arduino) connects to the signal pin (pin 2) of the DHT11.
VCC pin (DHT11) connects to the 5V pin (Arduino).
GND pin (DHT11) connects to the GND pin (Arduino).
VCC pin (LCD16x2) connects to the 5V pin (Arduino).
GND pin (LCD16x2) connects to the GND pin (Arduino).
SDA pin (LCD16x2) connects to pin A4 (Arduino).
SCL pin (LCD16x2) connects to pin A5 (Arduino).
Figure 4.1b.
27 | P a g e
Chapter 5: Code for project
The provided code demonstrates how to read data from a DHT11
temperature and humidity sensor and display it on an I2C LCD screen using
an Arduino. Below is the step-by-step explanation of the code:
#include <SimpleDHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
SimpleDHT.h: A library for working with DHT11/DHT22 sensors to
read temperature and humidity data.
Wire.h: Used to communicate with I2C devices.
LiquidCrystal_I2C.h: A library for controlling I2C-based LCDs.
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);
pinDHT11: Specifies the pin connected to the DATA pin of the
DHT11 sensor (pin 2 in this case).
dht11: Creates an instance of the SimpleDHT11 object to interface
with the sensor.
LiquidCrystal_I2C lcd(0x27, 16, 2);
0x27: The I2C address of the LCD module. This may vary depending
on the LCD hardware.
16, 2: Specifies that the LCD has 16 columns and 2 rows.
void setup()
{
Serial.begin(115200);
28 | P a g e
}
Starts the Serial communication at 115200 baud rate, which is used for
debugging and printing messages to the Serial Monitor.
void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT11...");
Prints a separator (====) and a message indicating the sampling
process of the DHT11 sensor.
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) !=
SimpleDHTErrSuccess)
{
Serial.print("Read DHT11 failed, err=");
Serial.println(err);delay(1000);
return;
}
temperature and humidity store the readings from the DHT11 sensor.
dht11.read(): Reads temperature and humidity. It returns
SimpleDHTErrSuccess if successful.
If the reading fails, an error message is displayed, and the loop exits
using return.
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
29 | P a g e
lcd.print("tempature ");
lcd.print((int)temperature);
lcd.setCursor(0, 1);
lcd.print("humidity ");
lcd.print((int)humidity);
lcd.begin(): Initializes the LCD.
lcd.backlight(): Turns on the LCD backlight.
Displays "temperature" and its value on the first row of the LCD.
Displays "humidity" and its value on the second row of the LCD.
delay (1000);
}
Wait for 1 second (1000 milliseconds) before taking the next reading.
1. Temperature:
30 | P a g e
n
Average: A =
∑ Ai = ❑
i=1 10
n
√
n
( A¿¿ i− A ¿)
Standard deviation: σ = ∑ n
¿¿ =
i=1
2. Humidity:
20
Average: A =
∑ Ai = ❑
i=1 10
10
√
n
( A¿¿ i− A ¿)
Standard deviation: σ = ∑ n
¿¿ =
i=1
Conclusion:
Temperature:
Average value: °C
Standard deviation: °C
The noise level is low, indicating that DHT11 operates stably in a
consistent environment.
Humidity:
Average value: %RH
Standard deviation: %RH
The noise level is also low and within the acceptable range.
31 | P a g e
32 | P a g e
33 | P a g e