Introduction: Raspberry Pi Weather Station

Build a personal weather station with Raspberry Pi that emails you the temperature, humidity, and rainfall.

*In a couple of weeks I will be adding a barometric pressure sensor to calculate chance of rain.

Step 1: Supplies

You will need:

Raspberry Pi b and power supply

Ethernet cable

Breadboard wires

Breadboard

Humidity & Temperature module (I am using the DHT11 module)

Rain gauge (Not pictured)

Housing for your weather station (Not pictured)

Hot glue gun with glue

Drill with various bits

Step 2: Assemble the Circuit

Connect the power pin of the humidity sensor and the power for the rain gauge to the 3.3V pin of the Raspberry Pi.

Connect the ground pin of the humidity sensor to ground on the Raspberry Pi.

Connect the data pin of the humidity sensor and data wires of the rain gauge to GPIO pins (I am using GPIO pins 7,13,15,18,and 16).

Step 3: Build the Housing

Drill holes in the gauge at 1in, 1.5in, 2in, 2.5in, and at the bottom.

Drill holes in the housing for the ethernet cable, power cable, and data wires for the rain gauge and humidity sensor.

Glue the rain gauge to the back of the housing.

Thread the wires from the transistors and power out of the housing and into the rain gauge, the seal the holes with hot glue.

Put the Raspberry Pi and circuit inside the housing and connect the ethernet, power, and humidity sensor.

Power up the Raspberry Pi and connect it to the internet via ethernet cable.

Step 4: Programming the Humidity Sensor

Before we start programming, you must download the Python libraries to use the sensor. Use the command git-clone https://github.com/adafruit/Adafruit_Python_DHT.g... then, switch to that folder by using cd Adafruit_Python_DHT and run sudo apt-get install build-essential python-dev to install 2 important modules for programming the sensor. while in the Adafruit_Python_DHT folder, run sudo python setup.py install to install the libraries in python. The libraries are now installed.

We will make a demo program to test the sensor.

import Adafruit_DHT as dht

h,t = dht.read_retry(dht.DHT11, 16)

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

run this program to make sure the sensor works. If it does not work, make sure you have everything plugged in right and have all the code typed in right.

Step 5: Code

import time

import RPi.GPIO as GPIO

import Adafruit_DHT as dht

import smtplib

import os

GPIO.setmode(GPIO.BOARD)

GPIO.setup(18,GPIO.IN)

GPIO.setup(13,GPIO.IN)

GPIO.setup(15,GPIO.IN)

GPIO.setup(16,GPIO.IN)

timeset_HH = input('Enter the hour you would like to be emailed at: ') #Enter time to be emailed at in 24-hour time

timeset_MM = input('Enter the minute you would like to be emailed at: ')

mail = smtplib.SMTP('smtp.gmail.com',587) #Set up and login to email

mail.ehlo()

mail.starttls()

mail.login('your email','your password')

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

humid_temp = 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h) #Read the sensor

while True: #This loop waits until the set time to send and email

now = time.localtime()

if now.tm_hour == int(timeset_HH) and now.tm_min == int(timeset_MM):

break

else:

pass

timeout = 60 - now.tm_sec

if (GPIO.input(16)): #Read sensor and then email readings

mail.sendmail('your email','your email','2in of rain ' + humid_temp)

elif (GPIO.input(18)):

mail.sendmail('your email','your email','1.5in of rain ' + humid_temp)

elif (GPIO.input(13)):

mail.sendmail('your email','your email','1in ofrain ' + humid_temp)

elif (GPIO.input(15)):

mail.sendmail('your email','your email','.5in of rain ' + humid_temp)

else:

mail.sendmail('your email','your email','0in ofrain ' + humid_temp)

mail.close()

GPIO.cleanup()

Step 6: Test

Set up the weather station and run the program. Set the time to be emailed when prompted(Set time in 24-hour time). At the specified time, you should recieve an email. If not, make sure you entered all the email information