DHT11 Digital Temperature and Humidity Sensor

### Lesson Plan: Using the DHT11 Digital Temperature and Humidity Sensor with the Raspberry Pi Pico WH

**Introduction**

Hey team! Today, we’re diving into the world of environmental sensing with the DHT11 Digital Temperature and Humidity Sensor. This little sensor is a powerhouse when it comes to measuring the temperature and humidity of your surroundings. It’s perfect for projects that need to monitor environmental conditions, like weather stations or smart home systems. Ready to add some science to your surroundings? Let’s get started!

**Learning Objectives**

By the end of this lesson, you’ll be able to connect and use the DHT11 sensor with your Raspberry Pi Pico WH. You’ll learn to read temperature and humidity data from the sensor and display it. This skill is essential for creating projects that monitor and respond to environmental changes. Ready to get some data? Let’s dive in!

**Materials Needed**

For this adventure, you’ll need a Raspberry Pi Pico WH, a DHT11 Digital Temperature and Humidity Sensor, a breadboard, jumper wires, a Micro USB cable, and your computer with a MicroPython IDE. These tools will help you capture and display environmental data with the DHT11 sensor.

**Background Information**

The DHT11 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and provides a digital signal on the data pin (no analog input pins needed). The sensor is easy to use but requires precise timing to read the data. Don’t worry, we’ll handle that in our code!

**Circuit Diagram**

Before we build the circuit, let’s visualize it. The DHT11 sensor has four pins: VCC, GND, DATA, and NC (not connected). We’ll connect VCC to the 3.3V pin on the Raspberry Pi Pico, GND to ground, and DATA to a GPIO pin (let’s use GP15).

**Step-by-Step Instructions**

Let’s get building! Start by placing the DHT11 sensor on the breadboard. Connect the VCC pin of the sensor to the 3.3V pin on the Raspberry Pi Pico. Next, connect the GND pin of the sensor to a ground pin on the Raspberry Pi Pico. Connect the DATA pin to GP15 on the Raspberry Pi Pico using a jumper wire.

Once your circuit is set up, connect the Raspberry Pi Pico to your computer using the Micro USB cable. Open your MicroPython IDE, and let’s get ready to code.

**Sample Code**

Time to write some code to read the temperature and humidity data from the DHT11 sensor. Copy and paste the following code into your IDE and upload it to the Raspberry Pi Pico WH.

“`python
import dht
from machine import Pin
from time import sleep

# Initialize the DHT11 sensor
sensor = dht.DHT11(Pin(15))

while True:
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print(‘Temperature: {}°C, Humidity: {}%’.format(temp, hum))
except OSError as e:
print(‘Failed to read sensor.’)

sleep(2)
“`

This code sets up the DHT11 sensor, reads the temperature and humidity data, and prints the values to the console. It continuously updates the readings every two seconds, giving you real-time environmental data.

**Testing and Troubleshooting**

Upload the code and watch the magic happen. You should see the temperature and humidity readings printed to the console. If it’s not working, double-check your connections and make sure the sensor is correctly placed. Verify that the code is correctly uploaded to the Raspberry Pi Pico WH. Still having trouble? Take a deep breath and check your setup again. You’re on the right track!

**Applications and Extensions**

Now that you’ve got the basics down, let’s get creative. Try using the sensor to trigger an alarm if the temperature or humidity goes beyond a certain threshold. Or, display the readings on an LCD screen for a mini weather station. The possibilities are endless, and the DHT11 sensor is your gateway to creating responsive projects that interact with their environment.

**Summary and Review**

Fantastic job! You’ve just mastered using the DHT11 Digital Temperature and Humidity Sensor with the Raspberry Pi Pico WH and MicroPython. You learned how to connect the sensor, read temperature and humidity data, and display the readings. These skills are crucial for building projects that monitor and respond to environmental conditions. Keep experimenting, keep building, and most importantly, have fun!

Remember, the best way to learn is by doing, so keep exploring the amazing world of electronics. Happy building, and as always, stay curious!

Post a comment

Leave a Comment

Your email address will not be published. Required fields are marked *