, ,

Connect a DHT11 Temperature/Humidity sensor to a Raspberry Pi

At GCITS we’re getting familiar with the Internet of Things (IoT). To start with, we’re connecting sensors to the cloud to make use of the real time data.

As a quick test, we want to connect a temperature sensor in our office to our dashboard in Power BI. The first step is to get a reading from the temperature sensor via the Raspberry Pi.

I had a bit of trouble getting this working using the some of the suggested wiring diagrams (it may just be an issue with my breadboard) so I’m posting this here in case it helps someone else.

You will need:

  • Raspberry Pi running Raspbian
  • A Breadboard
  • Assorted wires
  • 10k ohm resistor
  • DHT11 Temperature/Humidity Sensor

Wire it all up

First step is to wire up your Raspberry Pi to the DHT11 temperature sensor.

Here’s a drawing of my wiring, as well as two photos that should make it clear.

DHT11 Wiring Diagram
Raspberry Pi Wiring
DHT11 Wiring On Breadboard

 

Set up your Raspberry Pi

Once you’re all set, you’ll need to install a library to easily pull data from the sensor. I’m getting started with Python, so I’m using the Python library provided by Adafruit. I found some great instructions in this PDF: https://learn.adafruit.com/downloads/pdf/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging.pdf

I’ll summarise it here:

Open the terminal on your Raspberry Pi and run the following commands:

git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT

This will clone the Adafruit Python Library to your Pi

To make sure you have the correct dependencies to use the library, you’ll also need to run these commands:

sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl

Next you’ll need to install the library we cloned earlier:

sudo python setup.py install

To confirm that you’ve successfully installed the library, test the sensor by navigating to the Examples folder and running the test python script:

cd examples
sudo ./AdafruitDHT.py 11 4

This tests pin GPIO 4 for the DHT11 sensor and returns the temperature and humidity values.
Temperature and Humidity Results
Temperature Outside

 

As you can see, the result seems to be pretty accurate.

The parameters at the end can be modified to suit your setup. If you’re using the DHT22 sensor, replace 11 with 22 , or if you’re using another GPIO pin, substitute 4 for the appropriate GPIO pin number.

For example, sudo ./AdafruitDHT.py 22 17 refers to a DHT22 on GPIO17

Stay tuned for future posts on how we’ll connect this data to the cloud and Power BI!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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