Raspberry Pi projects:Raspberry Pi Weather Station

Project by
Mepits

Getting accurate weather data is crucial for many people but most of such data available on the internet are may not be accurate especially when it comes to rain. It is therefore necessary for them to have a local source of accurate weather data. Storing and analyzing of this data over some period will be very helpful for them. Raspberry Pi weather station then becomes a very useful and interesting project.

Raspberry Pi

Raspberry Pi is known to many as a credit card sized computer initially built to teach computing in schools. It is though not just another computer. It can interact with the external physical environment with the help of sensors. This feature of the Pi is what we will exploit in building our own weather station.

Weather Information

In this weather station project we will deal with two key parameters in weather data – humidity and temperature.

Requirements of Raspberry-pi Weather Station.

  1. Raspberry Pi model B
  2. Adafruit Pi Cobbler breakout kit
  3. Connecting wires
  4. Half sized breadboard
  5. DHT22
  6. 4.7 k Ohm resistor

The DHT22 Sensor

                                        DTH22 Sensor

                                             Fig: - Pin diagram of DHT22 Sensor

The DHT22 sensor measures temperature and humidity, the two parameters we use in this weather station project. It uses polymer humidity capacitor for measuring humidity and the DS18B20 temperature sensor for measuring temperature. It has four pins numbered 1,2,3,4 in the pin diagram which are VDD (power supply), DATA (Sensor values), NULL (No connection) and GND (Ground). The data comprises of integral and decimal parts of both humidity and temperature values. The power supply must provide a voltage between 3.6 and 6 Volts. It can measure humidity in the full range of 0-100%RH and temperature between -40 and 125 degrees Celsius.

Steps for building your own Raspberry Pi Weather Station

Step 1:- Setting up the Pi

To set up the Pi you need to install an operating system, update the packages, and upgrade the operating system. Then, you may enable Wi-Fi and SSH and access Raspberry Pi from your PC. All the information you need can be found in the link below. Keep note of your Raspberry Pi IP address that you can get using the ‘ifconfig’ command.

https://www.mepits.com/project/228/DIY-Projects/How-to-make-a-Raspberry-Pi-Web-Server

Step 2:- Making your own Wordpress site

We can create a wordpress site to which we will upload our weather data so that it can be accessed on other devices like a smartphone. You will need to configure your Pi as a web server first. The above tutorial explains how to set up your own web server using Raspberry Pi. It mentions that the content of your website is displayed on /var/www. Change directory to enter the folder.

Command: -

 cd /var/www

Download wordpress into the folder and unzip the downloaded file.

Commands:-

wget http://wordpress.org/latest.zip

unzip latest.zip

Move the contents inside the wordpress directory now created out of it using mv and remove the empty folder using rm command.

Change the permissions for wordpress

Commands:-

sudo chown -R www-data:www-data /var/www

a2enmod rewrite

Edit the default settings for wordpress using the GNU nano text editor.

Command: -

 nano /etc/apache2/sites-available/default

Set the first two instances of AllowOverride to All. Restart apache using the command below.

Command: -

/etc/init.d/apache2 restart

From now on you will need to make changes to your mysql database. A free software tool that will help you in doing so is phpMyAdmin. Install phpMyAdmin and run it by entering the following on the address bar of your web browser.

IP_Of_Your_Pi/phpMyAdmin

Using phpMyAdmin create a SQL database named WordPressDB.

Command: -

 CREATE DATABASE WordPressDB

Enter the IP address of your Raspberry Pi on the address bar to get into the wordpress installation wizard.

Step 3:- Obtaining code for getting data from the sensor

The code is written in Python. You need to install certain packages to make it work. Install them using the commands given below.

Commands:- 

apt-get install python python-dev libmysqlclient-dev

sudo apt-get install python-setuptools

The second command installs a tool called easy_install to install python modules without any trouble. Upgrade easy_install using the command below.

Command: -

easy_install -U distribute

Install the python module MySQL-python that will help you save the weather data in your database of the weather station project.

Command: -

 easy_install MySQL-python

Now you can download the python script for interfacing the sensor using git. If you don't have git installed, use apt install to install it.

Command: -

git clone https://github.com/peterkodermac/Raspberry-Weather.git

This creates a folder Raspberry-pi Weather. Make it executable using chmod and modify getinfo.py by adding the fields like username and password of your wordpress database.

Commands:-

chmod +x /root/Raspberry-Weather/

nano /root/Raspberry-Weather/getInfo.py

Enter the bcm2835-1.8 directory and build the C-library.

Commands:-

./configure

make

sudo make install

gcc Adafruit_DHT.c -l bcm2835 -std=gnu99 -o Adafruit_DHT

cd ..

Step 4:- Setting up crontab

The script for obtaining weather data is to be run frequently after a time period, say half an hour. This can be done with the help of crontab. To set up crontab you need to set your timezone using tzselect. Once you have selected your timezone open crontab using crontab -e and enter your timezone and add the line given below.

0,30 * * * * /usr/bin/python /root/Raspberry-Weather/getInfo.py

Step 5:- The weather graph

Install Raspberry Weather plugin from your Wordpress dashboard and activate it. A new icon appears on the Tiny MCE editor pressing on which adds a new line of code which is for the graph. Adjust the parameters to meet your requirements of the weather station.

Step 6:- Hardware connections

Circuit diagram

                                                                                         Fig: - Circuit diagram

After setting the hardware properly do the connections for interfacing the sensor with Raspberry Pi as given in the circuit diagram.

Step 7:- Testing

Enter the folder of the python script and run python getinfo.py. Check your database using phpMyAdmin.

User Review (0)