Introduction: PiWeather1.0

Picture of PiWeather1.0

The piWeather 1.0 is raspberry pi weather station with a nice to have dashboard.

The sensors included are:

  • -BMP280 (barometric sensor) for temperature and air pressure
  • -Light dependant resistor for luminosity
  • -DHT11 humidity sensor
  • -MH-RD for rain detect.

all data is logged every minute into a database. On the graph page you'll find the measurements of the day. You can switch easily to see the weekly or monthly graphs. Each bar is representing the average measurement of the day.

For those who love to see more technical details, on the sensor page you'll find an image of each sensor with a link to its datasheet.

On the settings page you can set warnings for each sensor. When a sensor's value is below or above the range you've set, you'll get a warning by email. It will resend you a mail when the value is back to normal.

##########################################################################################

Some software updates will be provided in the future:

  • The settings of the camera will be configured that you can set a trigger parameter. The settings now are currently not working.
  • The RGB-leds will be adjustable from the website so you can easily change the color or when they go on.
  • The database program is not protected against SQL-injection. (if your network is safe and updated there shouldn't be any problem)
  • the code is a bit messy. I'll rewrite and optimize the code.

Feel free to change anything that fits your needs.

##########################################################################################
Questions or problems? Don't hesitate to contact me or leave a message below. Happy building! :)

Step 1: Collecting the Parts We Need

Picture of Collecting the Parts We Need

For this project I've used:

  • tiny breadboard
  • raspberry pi 3 39.20€
  • two 2RGB-leds 4.95€
  • DHT-11 temperature & humidity sensor 1.5€
  • BMP280 barometric sensor 1€
  • MH-RD rain detect sensor 0.50€
  • LDR 0.4€
  • MCP3008 3€
  • 1 4.5 Ohm resistor 0.01€
  • 1 10 kOhm resistor 0.01€
  • pi camera module 31.95€
  • some jumpwire cables 3.09€ (together with tiny breadboard)

TOTAL COST: <85€

All the parts I've used are available on the internet. There are cheap and not hard to find.

For the frame I've used an inox plate and welded into some pyramid construction. In the last steps I'll reveal how it's made. But again for those who aren't that good with welding or never done that before, you can always create a frame with other materials that fits the design you love. I've used inox as material because its quite heavy so the wind won't blow the weatherstation away. Inox is also rust-proof which means it's quite durable. The only problem is, inox is an metal. And yes you've got it right metal means conducting electricity. So I had to make sure every sensor, wire was isolated from the frame.

Step 2: Wiring

Picture of Wiring

After we've collected the parts we need, we'll go on to the next step.

The first image is a reference of the GPIO pin numbering. The second img is an electronic schema and the third one is an image of the fritzing breadboard schema.

Let's start with the DHT11-humidity sensor (blue color). This sensor has 4 pins but only 3 of them are in use. The first pin needs to be connected to the 3.3V. The second pin must be connected to pin GPIO14 and it also needs power from the 3.3V make sure you put at least a 4.7Kohm resistor in between. The third pin is not in use and the fourth one needs to be connected to the GND.

Our next sensor is the BMP280. This sensor works with I2C protocol, if you don't know what that means don't worry the code is written and will still work :).

The first pin of the BMP280 is VCC and must be connected to 3.3V. The next pin is GND and should be connected to GND. The pin SCL and SDA needs to be wired up to respectively to GPIO5 and GPIO3. The two remaining pins are also connected to GND.

So far so good.

The next sensor is the LDR. Because a raspberry pi can't read analog values we need a converter (mcp3008) that will help the raspberry pi. We start by connecting the LDR to 3.3V, then we take the other leg of the sensor and place a 10Kohm resistor. The resistor needs to be connected to GND. Don't forget to put a cable between the LDR and the resistor. That cable should go to CH0(=first pin) of the mcp3008. (see picture 4)

To connect the raindrop module we have to connect the first pin (AO) to ch1 of the mcp3008, that's the channel next to our LDR. The second pin of the raindrop module is the DO, we don't need it so we'll not connect it. Next pin is a GND pin and the last one needs to be connected to 3.3V.

Now we'll add the camera. On our raspberry pi we find two ports. One is for the display, the other (next to the Ethernet port) is for the camera. open the port by pulling the lip towards the ceiling. Now place the camera into the port. Make sure the shiny connectors are facing away the Ethernet port. Pull the plastic lip back down. Check if the camera is secured into the port otherwise redo this step.

[optional]

I've added two RGB-leds parallel so when it dark my weatherstation lights up. I've haven't used resistors because my leds have built-in resistors. The red pin is connected to GPIO pin 13 green to GPIO pin 19 and blue to GPIO pin 26. The 4pin is for GND.

Now we're done with the wiring we can move up to the next step :D

Step 3: Getting Mysql on the Pi and Get the Code

Picture of Getting Mysql on the Pi and Get the Code

The next step is to install Mysql properly. Without mysql the program will not run or crash.

When you're logged into the pi (default user: pi & passwd: raspberry) type in the following command:

sudo apt-get update && sudo apt-get upgrade this command update your pi.

When the pi is ready, install the mysql-server with the following command:

sudo apt-get install mysql-server

Beside the mysql server, we also need a client which can be installed with this command:

sudo apt-get install mysql-client

The code I'm using is written in python and for that we also need a python-mysql connector. Type in the next command:

sudo apt-get install python3-mysql.connector

next we go into Mysql with the following command:

mysql -uroot -p

enter a password.

Now we're logged in as root user and we'll create a new user for our database

CREATE USER 'yourname'@'%' IDENTIFIED BY 'password';

The next step is to give the user all privileges:

GRANT ALL PRIVILEGES ON *.* TO 'yourname'@'%' WITH GRANT OPTION

after that press CRTL + C to quit mysql. Then type in:

mysql u[username] -p

we're now logged in with the user we've just created. Type in the following command to create the scheme: [MAKE SURE THAT YOU USE THE CORRECT NAME 'piWeather']

CREATE SCHEMA piWeather;

now go to my github (link below) and open the file piWeather.sql. Copy the text in the file and go back to the terminal where mysql is running. Paste all the text into the terminal (right-mouse-click). Pres ENTER. Mysql is now updating the piWeather database. Exit Mysql by pressing CRTL + C. go back to the main folder with cd ~.

We are done with the My-SQL installation :D

Now we're ready to get our code from github. Please visit this link:

https://github.com/mirificus/piWeather/tree/master... and click on the green button "clone or download"

copy the link and go back the the terminal of the raspberry pi.

type the following line in the terminal:

git clone https://github.com/mirificus/piWeather.git

now press the command: ls The terminal should now print a directory named "piWeather.

Type: cd piWeather to get into that directory.

I strongly recommend that you give all the .py files permissions to run and start at boot. We can achieve that with the following command:

sudo chmod +u piWheater.py 

and so one, untill you've done every .py file.

Step 4: Run Scripts at Boot

Picture of Run Scripts at Boot

Now we've given permission to the files, we've to make them run at boot. We'll start with the main file named piWeather.py,

type:

cd /etc/init.d 		--> this command will bring you to the init.d folder.<br>

followed by:

sudo nano weatherstation 	--> this command will make a new file<br>

Now type in the text you see in the second image. MAKE SURE YOU'VE CHANGED THE PATH TO THE FILE it should be something like this /piWeather/piWeather.py (if you've installed the code in the main folder)

After that close the file with:

CRTL + O and then press Y followed by ENTER

Now the file is saved, we need to make it executable with the following command:

sudo chmod +x /etc/init.d/weatherstation

In order to make the program run at start up, it's necessary to run this command:

sudo update-rc.d /etc/init.d/weatherstation defaults

our next command will ensure our other scripts are running. Type in the next command:

sudo crontab -e

type in the end of the document the following commands:

@reboot sudo python3 /ThePathToTheFile/rgbled.py
@reboot sudo python3 /ThePathToTheFile/writeDataIntoDb.py
@reboot sudo python3 /ThePathToTheFile/mail.py

The first will light up the weatherstation, the second will write data into the database and the third will check if a warning message must be sent to your email address if necessary. Close the file by typing in:

CRTL + O and then press Y followed by ENTER

To make sure the warning mails will be sent to the right emailadres type in:

sudo nano /piWeather/mail.py

Now we're in the mail.py file and change youremail@therestofyourmail.com to your email. Once that's done, close the file by typing in:

CRTL + O and then press Y followed by ENTER

Now restart your raspberry pi and check if you access the webserver.

sudo reboot -n

To access the webserver you'll have to type in the browser the ip of the pi followed by :5000 which means port 5000. If you don't know the IP of the pi you can type in the terminal "ifconfig" or "wpa_cli status".

If you don't know how to connect your pi to wifi please check out this helpful video on youtube:

Step 5: Building the Frame

Picture of Building the Frame

you can skip this step if you've build your own shelter for the pi and its wiring. Be aware that my frame is build out of a metal which means it conducts electricity !!

I started with an inox plate and cut out 4 triangles. Next I've cut out the border of each triangle. The border will be used as skeleton for the whole construction.

Take the four borders and bring them together so they'll take a shape of a pyramid. After welding the four borders together I've added 3strokes to the bottom of the borders. The strokes can hold a plate that will fit as foundation.

Once the skeleton is done, take the 4 triangles and cut them into strips. Now welder the strips under an angle of 30degrees. I suggest you start from the bottom and end at the top.

After the shelter is build we can go on and place the raspberry pi and the wiring. I started with the LRD. I taped off the two legs of the sensor so electricity won't conduct via the inox. Then I used two thermoplastic connectors the wire the LDR on the breadboard.

The next step I did was taping of the leds. I used super glue to make sure the leds will stick to the ceiling of the pyramid.

The last hard part is placing the rain detect module sensor on the pyramid. I've used again super glue but only on the black borders of the sensor otherwise the sensor will "detect" rain that isn't there.

Comments

DIY Hacks and How Tos (author)2017-06-18

Cool. I like the pyramid shaped design.

Thank a lot, I'm glad you like it. Feel free to ask if you need help :)

About This Instructable

690views

23favorites

License:

Bio: I'm a 23years old student with a passion for IT
More by TimothyVanhee:PiWeather1.0
Add instructable to: