Real Time Internet-Broadcasting Arduino Weather Station

This page describes all you need to know about the design and coding of my weather station.
This post is in English in order to approach larger audiences, apologies to my Hebrew speaking readers.
First and foremost, this weather station relays on the great project of WX Shield. I really thank aweatherguy for his job and I hope that he won't be angry at me for raping his code ;-).

Basically, the weather station is designed using the following components and methods:
  1. A standard, basic Oregon Scientific weather station collects the weather data. Its sensors read the data and transmit it to its base.
  2. Arduino penetrates into the weather station's base and parses this data, along with data collected from an independent barometric pressure sensor
  3. Arduino sends the data to thingspeak by browsing to a URL. The data is encoded inside the URL.
  4. Thingspeak browses to another URL, which essentially fills a Google Form. The data is again encoded in the URL, but thingspeak is required since the Google URL is an HTTPS, which Arduino can't browse to.
  5. All the raw data goes to one central Google spreadsheet. A script parses the data and copies each reading to its appropriate separate spreadsheet.
  6. A Time-Trend Chart is generated on each spreadsheet
  7. All the charts are published and presented in one central HTML page located in this Blogger blog, here.

First, a list of the hardware you'll need:

  • An Oregon Scientific weather station. I have the WMR80A which includes a rain gauge, a temperature / humidity sensor and a wind speed/direction sensor. This station seems not to be available any more. However, probably any other of their weather stations will fit and WMR88A or WMR86 seem to be good candidates. Cost: ~100$ (+ shipment to Israel ~60$).
  • Arduino Uno, or any of its China clones 
  • Arduino Ethernet shield. My code works with this shield, and won't work with the official Arduino ethernet shield which is much more expensive.
  • Arduino breakout board, if you wish to add a barometric pressure sensor, like I did
  • Barometric pressure sensor, BMP085 on a breakout board, which could be purchased from SparkFun or other vendors.(all Arduino parts should cost <40$)
The physical assembly of the station is quite simple.
The most difficult part for me was receiving the RF signals from the sensor in my Arduino unit. No matter how hard I tried utilizing the method described here, there was absolutely no signal reception in my Arduino. So instead I cheated: I unscrewed the base station of Oregon Scientific, found the RF receiver module and connected it to my Arduino's D8 input.
Apart from being simpler, this method also saves the money and the work that was spent otherwise. The disadvantage is that now Arduino is permanently connected to the base station.
This is how it looks like (the blue wire is my addition):

Find the receiver module inside the base unit by looking for part of the circuit that is connected at one end to an antenna. This module should have three pins, for supply, data and ground. Find the data pin either by inspecting the circuit or by using a voltmeter: find the two pins between which the voltage is +5 volts, these are the power and the ground respectively. The average DC voltage between the data pin the the ground should be about +2.5V (or between power and data, -2.5V respectively).
Grounds must also be shared between the base unit and Arduino, I take ground from the lowest voltage of the series batteries connection:

So after all, it looks like this:

BMP085 is connected according to the instructions in here. Here is a photo of its connection and other photos of the Arduino stack:




I use a USB cable connected to an AC to USB transformer to power the device (I noticed that if the device is not powered, there is no reception in the base unit, possibly due to pull up or pull down of D8)
So up to this point, enough with the hardware. Just place the device you built in a location where you have both a reception of the sensors and an access to your ethernet network (a.k.a next to the router).

Now to the software, which includes a C code for the Arduino sketch and a Javacript code for the server side Google Apps scripts.

First, you'll need accounts on Google and Thingspeak.
Begin from the end: create a google spreadsheet for the raw data and create a form for it. Use the method described here to understand how to fill and submit it from a URL.
An example URL will be:
https://docs.google.com/forms/d/<form key>/formResponse?ifq&submit=Submit&entry.<some number>=<data to submit>
All my spreadsheets are located here.
Create a ThingHTTP app and save its API for the Arduino sketch. My ThingHTTP looks like this:

Name:raw - ver 2014
API Key:<my Key>


URL:https://docs.google.com/forms/d/<my key>/formResponse?ifq&submit=Submit
HTTP Auth Username:
HTTP Auth Password:
Method:POST
Content Type:application/x-www-form-urlencoded
HTTP Version:1.1
Host:
Headers:
Body:&entry.<my some number>=%%t%%
Parse String:
Created:Wed, Dec 24 at 11:11 PM

The URL I browse to from Arduino is 
http://api.thingspeak.com/apps/thinghttp/send_request?api_key=<my thingHTTP key>&t=<data to submit>

The Arduino code can be found here. Feel free to play with it but remember this very important lesson I learnt: The Arduino is very low in memory. All the classes instantiated consume a big portion of the scarce 1K memory, so declare as few variables as you can. Place as much code as possible in the cloud and leave Arduino as few tasks as you can. If Arduino starts to act strangely and unpredictably, it's most probably a memory issue.
If you buy the BMP085 barometer, you should once uncomment the lines that print the calibration values to the Serial. Then plug them to the Google script.

Now we reached a point where you have all your raw data uploaded to a central Google Spreadsheet. From this point on you can do whatever you want from it. Here is a PDF explaining how to parse the data.
Note that a spreadsheet has a maximum to its capacity, and also the charts are slow when handling large amounts of data. For these reasons I took the following steps:

  1. The raw data spreadsheet is cleaned once a day
  2. The parsed data goes to different spreadsheets, by type (totally 8 spreadsheets)
  3. The data spreadsheets are updated only about once every 5 minutes
  4. The excessive columns (from columns C and on) were deleted from the spreadsheets
  5. The spreadsheets are getting archived once a year.
The functions I run on the data can be found here and are as follows:
  1. putUpdates: puts the data from Raw Data SS to the correct SS. It includes pressure calibration, adding offset to the rain reading and some more features. Triggered to run every 5 minutes.
  2. deleteOld: deletes values older than one day from the raw data SS, Triggered to run daily.
  3.  dailyEmailUpdate: sends the daily precipitation to a list of emails. Triggered to run daily at midnights.
  4. checkStationUpdates: checks that all the sensors are sending data. I they don't, sends me an email. Triggered to run every 4 hours.
  5. getLatestValues: gets the last readings of every sensor. Called from putUpdates
  6. getMaxMin: gets the extremes. Called daily.

That's it.
Good luck with your own station! It is a lot of fun :-)






אין תגובות:

הוסף רשומת תגובה