Sensor

๐ŸŒก๏ธ DHTโ€‘11 Temperature and Humidity Sensor

๐Ÿ“Œ Description

The DHTโ€‘11 is a digital sensor that measures temperature and humidity. Itโ€™s simple, inexpensive, and widely used in beginner projects. The sensor sends data in digital form, making it easy for microcontrollers to read.

๐ŸŽฏ Use

In our projects, the DHTโ€‘11 is used to:

  • Monitor room temperature and humidity.
  • Trigger fans or heaters when conditions change.
  • Collect environmental data for smart robots or IoT systems.

๐Ÿ‘‰ Think of the DHTโ€‘11 as the robotโ€™s weather station โ€” it tells the robot how hot and humid the environment is.

Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
  • Supply voltage: 3.3V/5V
  • Connection: PH2.0 terminal wire
  • Installation method: double screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine
import dhtx
import time

while True:
    print(dhtx.DHT11(17).temperature(), end="")   # Read temperature
    print('โ„ƒ    ', end="")                        # Print unit
    print(dhtx.DHT11(17).humidity(), end="")      # Read humidity
    print('%  ')                                  # Print unit
    time.sleep_ms(200)                            # Wait 0.2 seconds

Step by Step

  1. import machine, dhtx, time โ†’ Tools for pins, DHTโ€‘11 driver, and timing.
  2. dhtx.DHT11(17) โ†’ Initializes the DHTโ€‘11 sensor on pin 17.
  3. .temperature() โ†’ Reads the temperature in Celsius.
  4. .humidity() โ†’ Reads the humidity percentage.
  5. print(...) โ†’ Displays the values with units (โ„ƒ and %).
  6. time.sleep_ms(200) โ†’ Adds a short delay before the next reading.

๐Ÿ‘‰ Together, this program prints the temperature and humidity every 0.2 seconds.


โœ… Conclusion of the Test

  • If the program prints temperature (โ„ƒ) and humidity (%) values that change with the environment, the sensor is working correctly.
  • This test shows how the robot can measure environmental conditions and report them digitally.
  • Later, the DHTโ€‘11 could be used to control fans, activate humidifiers, or log data for smart monitoring systems.
On this page