The measurement of temperature and related environmental properties is a common task, and there are many different types of sensors available for measuring these properties, including thermistors (a temperature-dependent resistor), sophisticated breakout modules that connect via SPI and I2C, and sensor varieties such as the DHT11 or DHT22 sensors, which we will be using for our example.
All sensors have their relative strengths and weaknesses when it comes to accuracy, response times (how fast we can rapidly get data from them), and cost.
DHT sensors, as illustrated in Figure 9.1, are inexpensive, durable, and easy to use:
The DHT11 is a very common low-cost sensor. The DHT22 is its higher-accuracy cousin. Both are pin-compatible and will be suitable for our example. The pinouts of these sensors as illustrated in the preceding figure are as follows:
- Vcc: 3- to 5-volt power source...