End Presentation

Lecture 4: DHT11 Temperature and Humidity Sensor

CSC 321: Embedded Sysytem

First Semester 2020/2021


TWiki Slide Show
Next
The DHT11

PINOUT:

The DHT11 has only

3 pins:

  • Vcc
  • Ground
  • one data pin

dht11.jpg

The DHT11 is a basic, low-cost digital temperature and humidity sensor.

It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and

spits out a digital signal on the data pin (no analog input pins needed).

Its fairly simple to use, but requires careful timing to grab data.

The only real downside of this sensor is you can only get new data from it once every 2 seconds.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 25





















TWiki Slide Show
Next
A single GPIO pin
We have seen how we can drive an LED from a single GPIO pin

programmed as output pin or how we can read its state

through another GPIO pin, programmed as input pin.

Can one do more with a single pin?

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 25





















TWiki Slide Show
Next
Serial Protocol
How can we, with a single pin

  • initiate a measurement
  • read humidity and temperature data
  • make sure the data are correct?
The answer is: a serial protocol
and the DHT11 implements its own serial protocol

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 25





















TWiki Slide Show
Next
Reading and understanding the data sheet
Let’s have a look at the DHT11 data sheet:

Most of the following information is just a copy from the data sheet.

dht11_features.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 25





















TWiki Slide Show
Next
How does a resistive humidity measurement work?
resistiveHumiMeas.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 25





















TWiki Slide Show
Next
Resistive Humidity Measurement(2)
  • Variations in relative humidity produce changes variations
    of resistivity,which is measured.
  • The resistance of certain hygroscopic materials such as
    hygroscopic salts have such a property
  • These materials are mounted as thin films on
    the substrate with metal contacts
  • The devices can be very small

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 25





















TWiki Slide Show
Next
The NTC Thermistor
ntcThermistor.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 25





















TWiki Slide Show
Next
A processor on chip
In order to convert these measurements into numeric values

and send them to the end user through a serial protocol,

a preprogrammed micro-controller must be implemented on the chip.

In the case of the DHT11 this is an 8 bit micro-controller,

which does the conversion into binary and which creates the serial protocol

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 25





















TWiki Slide Show
Next
Text from the data sheet
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. Each DHT11 element is strictly calibrated in the laboratory that is extremely accurate on humidity calibration.

The calibration coefficients are stored as programmes in the OTP memory, which are used by the sensor’s internal signal detecting process.

The single-wire serial interface makes system integration quick and easy. Its small size, low power consumption and

up-to-20 meter signal transmission making it the best choice for various applications, including those most demanding ones.

The component is 4-pin single row pin package.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 25





















TWiki Slide Show
Next
Measurement Precision
dht11Specs.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 25





















TWiki Slide Show
Next
How to connect the device
connections.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 25





















TWiki Slide Show
Next
Powering the device
As we can see from the specs below, the DHT11 power line

can be directly connected to the cobbler 3.3V (or the 5V) line

dht11_power.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 25





















TWiki Slide Show
Next
Single Wire two way interface
dht11_comm.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 25





















TWiki Slide Show
Next
Overall Communication Process
Communication Format can be seperated into three stages

1) Request
2) Response
3) Data Reading

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 25





















TWiki Slide Show
Next
Request Reading
dht11_request.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 25





















TWiki Slide Show
Next
What does this mean for our program?
We must:
  • Program the GPIO pin onto which we connected our DHT11 as output
  • We must pull this line done (send a login level zero) and
    keep it low for a minimum of 18 ms
  • We must pull it high again and wait for another 20-40 μs
  • Finally we must re-program the pin as input and wait for the DHT11 to respond.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 16 of 25





















TWiki Slide Show
Next
Response from DHT11
dht11_response.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 17 of 25





















TWiki Slide Show
Next

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 18 of 25





















TWiki Slide Show
Next
Data Reading
dht11_datareading.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 19 of 25





















TWiki Slide Show
Next
Logic Analyzer
dht11_logic.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 20 of 25





















TWiki Slide Show
Next
What the user of the device wants
The user of the device would like to have a library which hides

all these details. He wants functions to

  • Send request
  • Read response
  • Read each data segment and save it to a buffer
  • Sum the segments and check if the result is the same as CheckSum
  • If the CheckSum is correct, the values are correct so we can use them. If CheckSum is wrong we discard the packet.

    To read the data bits can use a counter and start count uSeconds of High level. For counts > 24uS we replace with bit '1'. For counts <=24 we replace with bit'0'

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 21 of 25





















TWiki Slide Show
Next
Reading the final data
The dht11 library uses a custom 1-wire protocol to get the measurements from the sensor.

The payload consists of a humidity value, a temperature value and a checksum.

Then measure and read their values with:

  • measure()
  • temperature()
  • humidity() 

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 22 of 25





















TWiki Slide Show
Next
Starting the measurement
The data pin has to be programmed as output
d = dht.DHT11(machine.Pin(16))

And read data as

d.measure()
d.temperature() # eg. 23.6 (°C)
d.humidity()    # eg. 41.3 (% RH)
 

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 23 of 25





















TWiki Slide Show
Next

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 24 of 25





















TWiki Slide Show
Next

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 25 of 25





















First slide Previous End Presentation






























-- Isaac Armah-Mensah - 2021-05-27

Comments


I Attachment History Action Size Date Who Comment
JPEGjpg dht11.jpg r1 manage 55.2 K 2021-05-27 - 04:43 IsaacArmahMensah  
PNGpng dht11_bitidentify.png r1 manage 314.1 K 2021-05-27 - 05:16 IsaacArmahMensah  
PNGpng dht11_comm.png r1 manage 147.9 K 2021-05-27 - 05:01 IsaacArmahMensah  
PNGpng dht11_datareading.png r1 manage 213.5 K 2021-05-27 - 05:15 IsaacArmahMensah  
PNGpng dht11_endframe.png r1 manage 334.8 K 2021-05-27 - 05:16 IsaacArmahMensah  
PNGpng dht11_features.png r1 manage 102.8 K 2021-05-27 - 05:01 IsaacArmahMensah  
PNGpng dht11_logic.png r1 manage 701.8 K 2021-05-27 - 05:15 IsaacArmahMensah  
PNGpng dht11_power.png r1 manage 64.7 K 2021-05-27 - 05:01 IsaacArmahMensah  
PNGpng dht11_request.png r1 manage 469.7 K 2021-05-27 - 05:16 IsaacArmahMensah  
PNGpng dht11_response.png r1 manage 436.0 K 2021-05-27 - 05:16 IsaacArmahMensah  

This topic: IoT_Course_English > WebHome > Slides > TemperatureAndHumidityWithDHT11
Topic revision: r1 - 2021-05-27 - IsaacArmahMensah
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback