PSoC5LP Lab 12: DHT11/22, RHT03 Temperature and Humidity Sensor (1-Wire)

Objective

  • Understanding Sensor Specifications: Learn the operating voltage, current, output data format, measurement ranges, resolution, accuracy, and sampling rates of the DHT11, DHT22, and RHT03 sensors.
  • Implementing 1-Wire Communication: Gain proficiency in the maxdetect 1-Wire communication protocol used by these sensors, including initialization, data transfer, and timing requirements.
  • Practical Application: Apply the knowledge gained to interface these sensors with the PSoC5LP microcontroller, enabling accurate temperature and humidity measurements in embedded systems.

Overview

DHT11, DHT22, and RHT03 Sensors

These digital temperature and humidity sensors are commonly used in environmental monitoring projects due to their simplicity and affordability. Although they share similarities, each has unique characteristics:

DHT11 Sensor

DHT11 Sensor

Specification:

  • Operating Voltage: 3.5V ~ 5.5V
  • Operating Current: 0.3mA (measuring), 60μA (Standby)
  • Output: 1-Wire Serial Data
  • Temperature Range: 0ºC ~ 50ºC
  • Humidity Range: 20% ~ 90%
  • Resolution: Temperature and Humidity both are 16-bit
  • Accuracy: ±1ºC and ±1%
  • Sampling Rate: 1 reading every 2 seconds
DHT11Temperature Sensor Pinout2 DHT11Temperature Sensor Pinout
DHT11 - Temperature and Humidity Sensor DHT11 Sensor Pinout

Communication Protocol for DHT Series Sensors

The DHT11, DHT22, and RHT03 use the maxdetect 1-Wire communication protocol. Here is an outline of this protocol:

  • Data Line: A single data line is used for communication, where the sensor and microcontroller take turns pulling the line high and low to signal start and data bits.
  • Communication Steps:
    • Initialization: The microcontroller sends a start signal by pulling the data line low for a specified period.
    • Response: The sensor responds with an acknowledgment and then begins sending data.
    • Data Transfer: Temperature and humidity data are transmitted as 40-bit messages (8 bits each for humidity, humidity decimal, temperature, temperature decimal, and a checksum).
  • Timing Sensitive: The protocol is highly sensitive to timing; thus, precise microcontroller timing (delay functions) is crucial.

The DHT11 sensor is a cost-effective, entry-level sensor that measures temperature from 0 to 50°C with an accuracy of ±2°C and humidity from 20% to 90% with ±5% accuracy. It has a resolution of 1°C and 1% RH, updating approximately once per second. This sensor is well-suited for basic applications and hobby projects where precise readings aren't critical, though it has a limited temperature and humidity range.

The DHT22 offers an extended temperature range from -40 to 80°C and improved accuracy, ±0.5°C for temperature and ±2% for humidity, covering 0% to 100% RH. It has a finer resolution of 0.1°C and 0.1% RH, though it updates every two seconds. The DHT22 is ideal for environmental monitoring applications where higher precision and a broader range are required, though it is slightly more expensive than the DHT11.

The RHT03 (also known as AM2302) is very similar to the DHT22, with the same range, accuracy, and resolution for both temperature and humidity, covering -40 to 80°C and 0% to 100% RH with ±0.5°C and ±2% accuracy, respectively. It also has a 0.1°C and 0.1% RH resolution and updates every two seconds. Like the DHT22, the RHT03 is a reliable choice for applications needing precise environmental readings and is preferred in projects where accuracy and stability are essential.

In summary, the DHT11 is best for simple, low-cost applications, while the DHT22 and RHT03 provide more precise and broader-range measurements, making them suitable for more demanding temperature and humidity monitoring needs.

Required Reading Material

Required Components

Circuit / Schematic

Procedure

Creating a New Project

  1. Launch PSoC Creator.
  2. Got to File ➤ Open Project ➤ Project/Workspace.
  3. Open the PSoC5LP workspace in the EE4450 folder.
  4. After PSoC Creator opens the workspace, right-click on Workspace 'PSoC5LP' in the Workspace Explorer and select Add ➤ New Project….
  5. Select the correct PSoC5LP device model number, use the "Empty schematic" template, and enter the project name 12_Maxdetect1Wire.

Adding PSoC Creator Components

Open the "TopDesign.cysch" Schematic File, add the following components:

  • Add a Digital Output Pin:
    1. Similarly, go to the Ports and Pins catalog.
    2. Drag and drop the Digital Output Pin onto the schematic.
  • Add a Character LCD component:
    1. Navigate to the Display catalog in the component selection panel.
    2. Drag and drop the PSoCCreator icon Catalog 4 Character LCD onto the schematic.

Configure the Components

  1. Config the Digital Output Pin (Pin_1):
    • Click on the Pin_1 component in the schematic.
    • Rename the component to Wire1 to represent its connection to the 1-wire sensor.
    • Uncheck the box for ☐ HW connection to disable the hardware connection. This step ensures that the pin will be controlled manually in the software.
    • Change the Drive Mode to the Open drain, drive low mode.
    Pin Wire1 s
  2. Config the Character LCD (LCD_Char_1):
    • Click on the LCD_Char_1 component in the schematic.
    • Rename the component to LCD for clarity and ease of identification.
    CharacterLCD LCD s

The new TopDesign.cysch file is shown below:

TopDesign

Pin Assignment

DevicePort.PinDirectionDrive Mode

Building the code and Programming

Using the provided firmware code, implement the following functionality:

  • Check the temperature and humidity from the sensor every 5 seconds.
    • If Maxdetect_1Wire_Read() returns false, display 1-Wire Error on the LCD screen.
    • If Maxdetect_1Wire_Read() returns true, display the raw sensor data in hexadecimal format on the screen.
    • If a checksum error occurs, display ChkSum Error on the screen.
    • If no errors occur:
      • Display the temperature in Celsius (°C) and Fahrenheit (°F) on the LCD screen.
      • Display the humidity percentage on the LCD screen.
  • Example LCD Screen Layouts as below:

    LCD Display 01 LCD Display 02 LCD Display 03

© 2024 Air Supply Information Center (Air Supply BBS)