DHT11 Sensor

The DHT11 humidity and temperature sensor is an economical peripheral manufactured by D-Robotics UK (www.droboticsonline.com ). It is capable of measuring relative humidity between 20 and 90% RH within the operating temperature range of 0 to 50°C with an

  • PDF / 398,870 Bytes
  • 20 Pages / 439.37 x 666.142 pts Page_size
  • 41 Downloads / 251 Views

DOWNLOAD

REPORT


DHT11 Sensor The DHT11 humidity and temperature sensor is an economical peripheral manufactured by D-Robotics UK (www.droboticsonline.com). It is capable of measuring relative humidity between 20 and 90% RH within the operating temperature range of 0 to 50°C with an accuracy of ±5% RH. Temperature is also measured in the range of 0 to 50°C with an accuracy of ±2°C. Both values are returned with 8-bit resolution. This assignment is a challenge for a Linux application because of the signal timing constraints being accommodated. After the Pi initiates the sensor, the first event to be measured occurs within about 12 μs, for example. This requires some special handling. Direct GPIO access is used for this project since the sysfs driver is simply unable to cope with the rate of events involved.

Characteristics The signaling used by the DHT sensor is similar to the 1-Wire protocol but the response times differ. Additionally, there is no device serial number support. These factors make the device incompatible with the 1-Wire drivers within the Linux kernel. Figure 22-1 shows a DHT11 sensor sitting on a breadboard.

© Warren Gay 2018 W. Gay, Advanced Raspberry Pi, https://doi.org/10.1007/978-1-4842-3948-3_22

399

Chapter 22

DHT11 Sensor

Figure 22-1.  DHT11 sensor front view (left), rear view (right). Pin 1 is the leftmost pin facing the front of the package (left photo). The DHT11 sensor requires a power supply unlike many 1-Wire peripherals. The datasheet states that the DHT11 can be powered by a range of 3.3 to 5.5 V (this can also be seen on the back of the device in Figure 22-1). Powering it from the Raspberry Pi’s 3.3 V source keeps the signal levels within a safe range for GPIO. The device draws between 0.5 and 2.5 mA. Its standby current is stated as 100 to 150 μA, for those concerned about battery life.

400

Chapter 22

DHT11 Sensor

Circuit Figure 22-2 shows the general circuit connections between the Raspberry Pi and the DHT11 sensor. Pin 4 connects to the common ground, while pin 1 goes to the 3.3 V supply. Pin 2 is the signal pin, which communicates with a chosen GPIO pin. The program listing for dht11.c is configured to use GPIO 22. This can be overridden on the command line.

Figure 22-2.  DHT11 circuit When the Pi is listening on the GPIO pin and the DHT11 is not sending data, the line will float. For this reason, R1 is used to pull the line up to a level of 3.3 V. The datasheet recommends a 5 kΩ resistor for the purpose (a more common 4.7 kohm resistor can be substituted safely). This presents less than 1 mA of load on either the GPIO pin or the sensor when active. The datasheet also states that the 5 kohm resistor should be suitable for cable runs of up to 20 meters.

401

Chapter 22

DHT11 Sensor

Protocol The sensor speaks only when prodded by the master (Raspberry Pi). The master must first make a request on the bus and wait for the sensor to respond. The DHT sensor responds with 40 bits of information, 8 of which are a checksum.

Overall Protocol The overall signal protocol works like this: