Vadim Tabakman

Jump to bottom

DHT11 Temperature and Humidity Sensor

I think after doing the Hello World example with a Raspberry Pi and getting an LED to light up, the next thing to do is work on an Input sensor.  The DHT11 Temperature and Humidity sensor was the obvious target.

It has 3 pins that I plugged into my breadboard.

1. Gnd - I connected that to the - line on the breadboard

2. Data - I connected that to GPIO026

3. VCC - I connected to the + line on the breadboard

As soon as I did that, a light lit up on the sensor.  That means I've connected it correctly.. Right?? haha.

Next step was to get some Python code that can talk to the sensor.  You are probably wondering why "get" and not just write it myself.  Firstly, I'm still learning about all this sensors/GPIO stuff and at the same time, I'm learning Python.

A huge thanks goes out to Darius Juodokas (netikras) from Lithuania.  I grabbed his code from GitHub.

I had to change it a little to display the temp in Fahrenheit, but I was pleasantly surprised at the fact that it just worked.

Results

When you run it, it goes and gets the data from the sensor around 1,000 times, then calculates averages.  This should get rid of any anomalous readings.

The output looks like this :

H: 18%

T: 69.8F

Now you know what I have my office set to.

note:  there is also some text "Hello World" that pops up.  That's just for me.. feel free to get rid of that.

Downloads

Download the DHT11Sensor.py script - this is zipped.  So unzip it when you want to run it.  To run it :

python DHT11Sensor.py

Posted by Vadim Tabakman Tuesday, January 17, 2017 12:07:00 PM Categories: DHT11 Humidity Python Raspberry PI Temperature

Comments

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register