Temperature/Humidity Notifications with DHT11

Hi,
this project aim to use DHT11 sensor to check every hour temperature and humidity and send it through email.

This is DHT11:

you can buy it on amazon (click here).

what we need?:
  • DHT11 sensor
  • some cables
  • a resistor between 4.7K and 10K 
 ok, place dht11 on breadboard, then follow this connection:

breadboard negative rail -> GND pin on Raspberry GPIO
breadboard positive rail -> 3.3V pin on Raspberry GPIO
pin 4 of DHT11 -> breadboard negative rail
pin 3 of DHT11 is not connected
pin 2 of DHT11 -> Raspberry GPIO25
pin 1 of DHT11 -> breadboard positive rail
place resistor on rail with pin 2 of DHT11 and positive rail

this schema explains better:




then we need to download ADAFRUIT python library to use DHT11:

if you use git:

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

then enter in folder and from terminal write:
 
sudo python setup.py install
 
Ok this code is based on adafruit example but i removed input args (becouse we are now working only with DHT11 an not DHT22 or AM2302)
This is the code:


import sys
import time
import Adafruit_DHT


now = time.strftime("%c")

sensor = 11
pin = 25

humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

# Un-comment the line below to convert the temperature to Fahrenheit.
# temperature = temperature * 9/5.0 + 32

if humidity is not None and temperature is not None:
    print now + ' - '+ 'Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity)
else:
    print 'Failed to get reading. Try again!'
    sys.exit(1)



now it's time to schedule the sensor.

on Raspberry execute
crontab -e

and add the following line

0 * * * * sudo /home/pi/<pathtoproject>/TemperatureHumidity.py  | mail -s "<mail object>" your@email.com

the result is this:



with this line we are telling to our favourite OS (Linux) to execute python script every hour and send output through email.





stay tuned for the next project!!

Download all codes of this blog from github https://github.com/colino/RaspberryProjects

Commenti