The DHT11 is a low-cost temperature and humidity sensor. This sensor uses a thermistor to measure the temperature. The word thermistor is a combination of thermal (temperature) and resistor because it is a type of resistor where the resistance is highly sensitive to temperature even more so than a normal resistor. The current temperature can be determined based on the output voltage of the thermistor.
When working with a thermistor, the first thing we need to do is to determine how to calculate the temperature based on the output voltage. With the TMP36 temperature sensor that we used with the prototype that was created in Chapter 4, Basic Prototyping, we could easily calculate the temperature based on the output voltage of the sensor with a basic formula of (voltage - 0.5) * 100.0 because it uses a solid-state technique to determine the temperature. This is not the case with a thermistor. While a linear approximation, similar to how we calculated the temperature with the TMP36 sensor, may work for a small temperature range, to get an accurate temperature measurement from a thermistor we need to determine a resistance/temperature curve for the device.
Luckily there are several libraries for the Arduino that are written to help us get an accurate temperature from the DHT11 temperature and humidity sensor. In this chapter, we will be using the Adafruit library. The DHT11 sensor will look similar to the following photograph:
With most DHT11 sensors, the pins are clearly marked as shown in the preceding photograph. The VCC pin will connect to the power rail on the breadboard, which should be connected to the 5V out pin on the Arduino. The GND pin will connect to the ground rail on the breadboard, which should be connected to the ground out pin on the Arduino. The DATA pin will connect to one of the digital pins on the Arduino.
For the project in this chapter, we will also be using a generic raindrop sensor. This sensor has two parts. The first part is the rain sensor board, which detects the rain when the water completes the circuits on the board's printed leads. This sensor board acts as a variable resistor where the amount of current increases as the board gets wetter. The second part of the raindrop sensor is the electronic printed circuit board that will determine the amount water based on the current from the sensor board.
The following photograph shows what the raindrop sensor looks like:
The +/- pins on the printed circuit board connect to the pins on the rain sensor board. On the opposite side of the printed circuit board are four pins. The VCC and GND pins will connect to the power and ground rails of the breadboard respectively. For the project in this chapter, we will use the A0 analog output pin as the output for the sensor. The A0 pin will connect directly to one of the analog in pins on the Arduino.