

You can use them to capture the temperature of your Pi when its in an enclosure in the hot summer heat, or you can use it to check on the temperature of room in your house when you’re out of town. There are so many possible uses for these sensors. If you did everything correctly, you’ll start seeing the temperature and humidity reported on the terminal window every 3 seconds. To run your code, enter python3 mydht11.py and press enter. Print("Temp=%".format(temperature, humidity)) If humidity is not None and temperature is not None: Humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN) Lastly, since the DHT11 and DHT22 can only be checked a maximum of once per second, we use the system time.sleep function two pause three seconds between checks. If it it failed we let you know to check your wiring. If it worked, we print the temperature and humidity to the screen. The “while True:” line will force everything indented after to run in an infinite loop.įirst, we capture the temperature and humidity to two aptly named variables, and then use an IF statement to check to see if it worked.
PULL THE PIN CHALLENGE 22 CODE
This line defines the sensor object we will use, and the next line is a variable that defines the GPIO pin we are using.Īnd finally the code loop that goes next. The first section of code imports the DHT library from Adafruit and the system time library. This is some very basic code written in Python. Now let’s take a look at the code we’re going to use.
PULL THE PIN CHALLENGE 22 INSTALL
Sudo python3 -m pip install -upgrade pip setuptools wheel Sudo apt-get install python3-dev python3-pip These will install PIP and other utilities you may need. You can fix that by running the following commands. Note: If you run into problems with the above command, you may not have PIP installed on your Pi. This is done by entering the following command: Next thing we need to do is install the DHT python library. RELATED: DHT11 Sensor Wiki Page Python Code for Raspberry Pi DHT11/DHT22 ( NOTE: Some cost reduced modules do not include this LED.) If you wired everything up correctly, you’ll see a red LED glowing on the DHT11 module.

PULL THE PIN CHALLENGE 22 SOFTWARE
The DHT11 and DHT22 are fundamentally the same from a wiring and software perspective.


Especially to keep tabs on how hot your Raspberry Pi is, if its in a non-ventilated box in the summer heat. Using the DHT11 temperature sensor with the Raspberry Pi is a great way to get temperature and humidity readings in your projects. In this tutorial, we’re going to cover using the the DHT11 (or DHT22) temperature and humidity sensor with the Raspberry Pi.
