Sub topic 1
What Temperature and Relative Humidity Measure
Prerequisites
This chapter assumes you can upload a sketch, open the Serial Monitor, place parts on a breadboard, and use float values in C++. You should also know the setup() and loop() structure of an Arduino sketch.
What temperature and relative humidity measure
Temperature measures how fast the air's molecules move. It is reported in degrees Celsius (°C) or Fahrenheit (°F). Relative humidity (RH) measures how much water vapor the air holds compared with the maximum it could hold at that temperature, shown as a percentage. Warm air can hold more vapor, so heating air lowers its RH even when the water content stays the same. The two readings are linked, so read them together.
Meet the DHT11 and DHT22
The DHT11 and DHT22 are low-cost digital sensors. Each one contains a humidity element and a temperature element, plus a chip that converts both readings to digital data.
| Sensor | Temperature range | Temperature accuracy | Humidity range | Humidity accuracy |
|---|---|---|---|---|
| DHT11 | 0 to 50 °C | ±2 °C | 20 to 80 % RH | ±5 % RH |
| DHT22 | -40 to 80 °C | ±0.5 °C | 0 to 100 % RH | ±2 % RH |
Wiring the sensor to the Arduino
Connect three pins. Connect VCC to 5V, GND to GND, and the data pin to a digital pin such as D2. Place a 10 kΩ pull-up resistor between the data pin and VCC. The resistor holds the data line high while the sensor is idle.
How the sensor sends data over one wire
The sensor uses a single data line for both requests and replies. The Arduino pulls the line low to start a reading. The sensor then sends 40 bits: 16 bits of humidity, 16 bits of temperature, and an 8-bit checksum. Each bit is a high pulse. A short pulse means 0, and a long pulse means 1. The checksum lets the code detect corrupted data.
Exercise
The sensor sends 40 bits per reading. How many bytes is that, and which byte holds the checksum?
Show answer
40 bits is 5 bytes. The fifth byte is the checksum. It equals the sum of the first four bytes, keeping only the low 8 bits.