cpe-555 final project report
TRANSCRIPT
1
CPE-555 REAL TIME
EMBEDDED SYSTEM Weather Monitoring System using
Raspberry-Pi
By: Ankit R Bhansali
Drashti Sheth
Vaibhav Jindal
May 10, 2016
Stevens Institute of Technology
2
Table of Contents Abstract .................................................................................................................. 3
Description of Components ................................................................................... 4
Ds18b20 temperature sensor…………………………………………………………………………5
DHT11 Temperature & Humidity Sensor………………………………………………………..5
BMP180 Barometer for atmosphere pressure and altitude……………………………6
Circuit Diagram……………………………………………………………………………………………………7
Configuration of Sensors……………………………………………………………………………………..8
DS18B……………………………………………………………………………………………………………8
DHT11……………………………………………………………………………………………………………8
BMP180…………………………………………………………………………………………………………9
Description of the Code ....................................................................................... 11
Testing and Results .............................................................................................. 17
References ............................................................................................................ 18
3
ABSTRACT
In this project, we have designed a Weather Monitoring System using
Raspberry Pi and breadboard for sensing Temperature, Humidity and
Pressure using various sensors.
A Twitter Account is linked with the Weather Monitoring System which
will update the Temperature, Pressure and Humidity
The sensors are integrated with GPIOs using Raspberry Pi.
4
Description of Components
Hardware components which we have used in our project are as below:
Raspberry-Pi
2- 10k ohm Resistors
Jumper wires
DS18B20 Temperature Sensor Probe
DHT11 Temperature & Humidity Sensor
BMP180 Barometer for atmosphere pressure and altitude.
5
DS18B20 Temperature Sensor:
This is the latest DS18B20 1-Wire digital temperature sensor from Maxim IC.
It Reports degrees C with 9 to 12-bit precision, -55C to 125C (+/-0.5C).
Each sensor has a unique 64-Bit Serial number etched into it - allows for a huge
number of sensors to be used on one data bus.
This is a wonderful part that is the corner stone of many data-logging and
temperature control projects.
Moreover it requires no external components.
DHT11 Temperature & Humidity Sensor:
It is the multifunctional sensor that gives you temperature and relative humidity.
Sensor uses capacitive humidity sensor and thermistor to measure surrounding air.
It provides reliable readings when environmental humidity conditions in between
20% RH and 90% RH and temperature conditions between 0 – 50 degree Celsius.
6
BMP180 Barometer for atmosphere pressure and altitude:
The BMP180 offers a pressure measuring range of 300 to 1100 hPa with an accuracy
down to 0.02 hPa in advanced resolution mode.
It’s based on piezo-resistive technology for high accuracy, ruggedness and long
term stability.
The chip only accepts 1.8V to 3.6V input voltage.
7
Circuit Diagram
We implemented circuit on Raspberry-Pi as below by connecting all sensors,
resistor using jumper wires.
8
Raspberry-Pi Layout
Configuration of Sensors
Configuring DHT11 Sensor:
Open the terminal and type the following commands:
• Take the terminal to the folder where your files are placed
• sudo su
• Python file_name.py
Configuring DS18B Sensor:
Open the command terminal and type the following commands:
• sudo modprobe w1-gpio
• Sudo moderate w1-therm
• cd/sys/bus/w1/devices
• ls
9
• cd 28**********
• cat w1_slave
Configuring BMP180 Sensor:
• Connect it to 3.3V
• Also connect the i2c pin (SDA and SCL pin) to the SDA and SCL pin of
raspberry pi.
• Open the terminal and type the following commands:-
sudo i2cdetect -y 1
In the figure below, we can see our device connected
10
11
Description of the Code
Below we have mention our python code and some of the screenshots of our code
for different sensors.
Code:
'''Rasproject:configuring the twitter part'''
#!/usr/bin/env python
import io
import numpy as np
import tweepy
import sys
import matplotlib
import random
matplotlib.use('Agg')
matplotlib.rcParams['timezone'] = 'America/New_York' # Replace with your time zone
import matplotlib.pyplot as plt
from pytz import timezone
import pytz
from matplotlib.dates import DateFormatter
from rasptemperature import read_temp
from temp import temperature
from ras1pressure import getpressure
from datetime import datetime
# Twitter API Keys
12
CONSUMER_KEY = "'OXbOgWLrKxgWeAZEGEpezDqB7'
CONSUMER_SECRET = “not-shown-for-security-reasons”
ACCESS_KEY = '52004919-g03BuUSYtQHzN1NjHt8e4vZWhgFxZtAI9cqrEJT3c'
ACCESS_SECRET = “not-shown-for-security-reasons”
# Set file paths - Don't forget trailing slash
path_data_dir = "/home/pi/pathToDataDirectory/"
path_image_dir = "/home/pi/pathToImageDirectory/"
# Read the data file
## Plot humidity graph
data = np.genfromtxt(path_data_dir+'temp1.dat', delimiter=',')
dates = matplotlib.dates.epoch2num(data[:,0])
#dateshum = matplotlib.dates.epoch2num(datahumidity[:,1])
tempdata=data[:,1]
fig, ax = plt.subplots(figsize=(6,5))
ax.plot_date( dates, tempdata, ls='-', color='blue' )
ax.xaxis.set_major_formatter( DateFormatter('%m/%d/%y %H:%M'))
ax.set_ylabel('Temperature %')
for label in ax.get_xticklabels():
label.set_rotation(60)
plt.tight_layout()
plt.savefig(path_image_dir+'tempplot.png', bbox_inches='tight')
'''## Plot temperature graph
data = np.genfromtxt( path_data_dir+'temp1.dat', delimiter=',')
13
dates = matplotlib.dates.epoch2num(data[:,0])
tempdata = data[:,1]
fig, ax = plt.subplots(figsize=(6,5))
ax.plot_date( dates, tempdata, ls='-', color='blue' )
ax.xaxis.set_major_formatter( DateFormatter('%d/%m/%y %H:%M'))
ax.set_ylabel('Temperature C')
for label in ax.get_xticklabels():
label.set_rotation(60)
plt.tight_layout()
plt.savefig(path_image_dir+'tempplot.png', bbox_inches='tight')'''
## Plot humidity graph
datahumidity = np.genfromtxt(path_data_dir+'humidity.dat', delimiter=',')
dateshum = matplotlib.dates.epoch2num(datahumidity[:,0])
tempdatahum = datahumidity[:,1]
fighum, axhum = plt.subplots(figsize=(6,5))
axhum.plot_date( dateshum, tempdatahum, ls='-', color='green' )
axhum.xaxis.set_major_formatter( DateFormatter('%m/%d/%y %H:%M'))
axhum.set_ylabel('Humidity %')
for label in axhum.get_xticklabels():
label.set_rotation(60)
plt.tight_layout()
plt.savefig(path_image_dir+'humidity.png', bbox_inches='tight')
## Plot combined graph of humidity and temperature to tweet using tweepy
figuremain = plt.figure(figsize=(8, 6), dpi=80)
ax = figuremain.add_subplot(211)
ax.plot_date( dates, tempdata, ls='-', color='blue' )
14
ax.xaxis.set_major_formatter( DateFormatter('%m/%d/%y %H:%M'))
ax.set_ylabel('Temperature C')
for label in ax.get_xticklabels():
label.set_rotation(60)
axhum = figuremain.add_subplot(212)
axhum.plot_date( dateshum, tempdatahum, ls='-', color='green' )
axhum.xaxis.set_major_formatter( DateFormatter('%m/%d/%y %H:%M'))
axhum.set_ylabel('Humidity %')
for label in axhum.get_xticklabels():
label.set_rotation(60)
plt.tight_layout()
plt.savefig(path_image_dir+'combined.png', bbox_inches='tight')
# Get latest humidity value from file
file = open(path_data_dir+'Temp1.dat', 'r')
humval = file.read()
file.close()
# Get latest humidity value from file
file = open(path_data_dir+'humidity_val.dat', 'r')
humval = file.read()
file.close()
## Tweet or Print!
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
15
tz = timezone("America/New_York")
ftime = datetime.now()
finaltime = tz.localize(ftime)
photo_path = path_image_dir+'combined.png'
cel = read_temp()[0]
temp = u"City:%.2f\u2103 | "%cel
status = "Hoboken:"+str(temperature)+" Humidity "+humval+"% - (EST)
"+finaltime.strftime('%m/%d/%Y %H:%M:%S')+" | Atmospheric pressure: "+getpressure()
status = status.encode('utf-8')
api.update_with_media(photo_path, status=status)
#print status
The code for Temperature sensor DS18B20
16
The code for temperature sensor DHT11:
The Code for pressure and altitude sensor BMP180
17
Testing and Results
These are screenshots of our testing and results. Here after running our code
and giving commands, we get results on our twitter account as you can see in
above pictures. We get temperature and humidity graph at particular time and also
values of pressure and altitude.
We have also attached our project working video with this. Here is the link where
you can watch video:
https://drive.google.com/a/stevens.edu/folderview?id=0ByPZz2nIbJrpWEpsb
kdFaFo5WVE&usp=sharing
18
References
https://bhavyanshu.me/tutorials/circuit-diagram-and-code-snippet-of-my-
weather-monitoring-system/08/12/2015