Hardware – CY8CKIT-062-WIFI-BT/CY8CKIT-062-BLE/CY8CPROTO-063-BLE
Software/IDE – PSoC Creator 4.3 and PDL 3.1.1
DHT-11 is a popular sensor to measure temperature and humidity. The sensor is manufactured by many companies one of which is Adafruit and the Adafruit sensor can be found here. This blog provides 2 ways to interface DHT-11 with PSoC 6 one using the interrupts and the other without. The PSoC Creator projects for the two applications are attached as part of this blog.
Working of DHT-11 Sensor:
DHT-11 is a single wire digital humidity and temperature sensor, which provides humidity and temperature values serially with one-wire protocol. DHT11 sensor provides relative humidity value in percentage (20 to 90% RH) and temperature values in degree Celsius (0 to 50 °C). DHT11 sensor uses a resistive humidity measurement component and NTC temperature measurement component.
The sensor has 3 pins – Vcc, Data, Gnd. The operating voltage of the sensor is 3.3V to 5V and thus Vcc is connected to 3.3V and Gnd to Ground of the kit. Data pin acts as the asynchronous interface between the sensor and the PSoC device. The Data pin should be configured as a bidirectional pin with drive mode set as Resistive Pull Up. The communication protocol followed by the sensor is asynchronous with a START condition, ACKNOWLEDGEMENT and 5 bytes of Data.
The 5 bytes contain the following data –
Byte 1 - Humidity (whole number part)
Byte 2 - Humidity (fractional part)
Byte 3 - Temperature (whole number part)
Byte 4 - Temperature (fractional part)
Byte 5 - Checksum
1. START – Start condition is sent by the PSoC 6 device. An 18 ms low pulse is sent to the sensor.
Figure 1: Communication protocol of sensor
2. ACKNOWLEDGMENT – The sensor detects the low pulse from the MCU and sends an acknowledgment signal by pulling the Data line low for approximately 54 us. The sensor then sends a logic high for about 80 us and then starts sending Data to the PSoC MCU.
3. DATA – Data is sent serially in terms of bits. Bit-level logic is represented as follows,
40 bits are sent in a similar way after which the communication terminates. The last byte contains the checksum and needs to be verified to ensure that the data received is valid. The checksum is obtained by simply adding the first 4 bytes.
Figure 2: Bit 0
Figure 3: Bit 1
Comparison of the two approaches: