Temperature sensor

One of the things I always wanted to do with my solar rig is to correlate temperature with energy output. For that, I got one of these:


DHT11 temperature and Humidity Sensor – 77 cents on AliExpress.

It is REALLY simple.

Pin 1 3.3V
Pin 2 Signal+10k ohm resistor to 3.3v
Pin 3 Nothing
Pin 4 Ground

It is said that it can withstand 5.5v – with me it didn’t work.

If it helps, that’s how I have it, but I use GPIO4. It’s the same. Circuito-Raspberry-Pi-DHT112.png

IMG_2863.JPGThis is my Pi2 connected to the Solar Panels.

In order to read it, I cloned Adafruit’s git repo and installed it

git clone https://github.com/adafruit/Adafruit_Python_DHT
cd Adafruit_Python_DHT
sudo python setup.py install

I needed to upgrade Raspian from Wheezy to Jessie (which I should have done a long time ago anyway) in order for the code to run without root. After that, the code is this:

import sys
import Adafruit_DHT

humidity, temperature = Adafruit_DHT.read_retry(11, 4)
print 'Temp: {0:0.1f} C Humidity: {1:0.1f} %'.format(temperature, humidity)

And that’s it. I run this on my cron script that sends this data to initialstate.com:



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s