The DHT11 sensor is bigger than the SHT11 module, yet still fairly small: 12 mm (~0.5”) wide by 15. 5 mm (~0.6”) tall by 5. 5 mm (~0.2”) thick, and has four
breadboard-friendly pins spaced on 2. 54 mm (0.1”)
centers. Only three of the four pins are used as shown in
Figure 1. If you explore eBay for a few minutes, you’ll find
dozens of pre-built modules like the one shown in Figure
2, which is what I used for my experiments. It includes the
DHT11, a bypass cap, and a pull-up on the data line.
Connecting to the DHT11/22 is very easy: We need
power and a single free I/O pin. From the host side, the
I/O pin is used to trigger the sensor. From the sensor side,
this pin is used to respond to the host through a
specialized serial protocol. As both sides can control the
data line, it is configured as open-collector/open-drain;
that is, a pull-up is required to take the line high. When
the host wants a new reading, it will pull the data line low.
It then releases the pin by changing to input mode to
receive a data stream that contains the humidity and
Figure 3 shows the basic connections if you’re going
the DIY route. Most of the sensors I’ve seen suggest they
run from 3. 5 to 5. 5 volts, so I use 5V for my setup. The
4.7K pull-up is also connected to 5V. If you’re new to the
Propeller, this connection to 5V may seem problematic.
It’s not. The 4.7K pull-up limits the current into the I/O pin
to a safe level. Figure 4 diagrams the transaction elements
on the data line. The thin black line denotes control by the
pull-up; the blue line is the host pulling the data line low;
Trigger: At the beginning of each transaction, the host
will pull the data line low for at least 18 ms, then release
the data line to the pull-up. This trigger condition brings
the sensor out of its sleep state.
Wake: If all is well, the sensor will wake and respond
within 20 to 40 microseconds.
Response: The sensor will pull the data line low for 80
microseconds, then release it to the pull-up for another 80
More Hot & Sticky
Last time we were together, I shared my
summertime adventure to Alaska which
included catching salmon and halibut in the
waters off of Seward, and dining on that
fish with fresh vegetables from my brother-in-law's greenhouse. You don't get closer to
the earth than that! In my desire to design
and build a greenhouse controller for Lew, I
wrote some code for the SHT11
humidity/temperature sensor. It's a nice
sensor, but it's expensive. On the other end
of the price/performance scale is the
DHT11. It doesn't have the range or
accuracy of its cousin, but it comes with a
user-friendly price-tag: about $5 from US
vendors, and cheaper than that from a host
of eBay vendors. The DHT11 (and slightly
more accurate DHT22) uses a one-wire
protocol, so we'll write a driver for that and
have another tool in the box for humidity
and temperature measurement.
■ BY JON MCPHALEN THE SPIN ZONE
18 March 2016
■ FIGURE 1.
■ FIGURE 2. DHT11 sensor module.