weather sensor

Weather sensors

Working with weather sensors

DHT11 or DHT22 temperature and humidity sensor are two Raspberry Pi compatible sensors. For Raspberry Pi, 3 pins on the sensor are used even if there are four pins in some models. Holding the sensor with the front side facing, the left pin needs to be connected to the RPi 3.3V pin, the right pin to the RPi Gnd pin, and the middle one (or the one next to the Vcc one in case of 4 pins) to the Raspberry Pi GPIO 4 (pin#7 on Raspberry Pi board). Make sure you connect the data pin to a 10kΩ resistor between the Vcc and the data wires

The Temp and Humidity sensor requires its own library in order to work on Raspberry Pi. It can be downloaded and installed using the following steps. The following has to be done on the terminal window of the Raspberry Pi.
First download the code from Githib:

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

cd Adafruit_Python_DHT
To update and install the python library, type the following:

Sudo python setup.py install
Sudo apt-get upadate

Sudo apt-get install build-essential python-dev python-openssl
To try the sensor, type the following in the terminal window:

cd examples

sudo ./AdafruitDHT.py 11 4  (11 is the DHT sensor type DHT11 and 4 is the GPIO number (pin#7))

This should show two readings on the screen, one for temperature and another for humidity.

A simple python code for this sensor is:

import Adafruit_DHT as dht

h,t = dht.read_retry(dht.DHT22, 4)

print ‘Temp={0:0.1f}*C Humidity={1:0.1f}%’.format(t, h)weathorrrwerrrrr.JPG