Wolfram Blog
Arnoud Buzing

Build Your Own Weather Station in a Snap with the Wolfram Cloud!

March 17, 2015 — Arnoud Buzing, Director of Quality and Release Management

Recently Stephen Wolfram announced the Wolfram Data Drop, which is a great new tool to upload any type of data from any type of device. I’ll show how you can use the Wolfram Data Drop with a weather station you build using some basic hardware and a few lines of code. Once completed, your device will take temperature measurements every second for 60 seconds, and upload their average value to the Wolfram Data Drop every minute. This will give you 60 data points per hour and 1,440 data points per day. With this data you can use Wolfram Programming Cloud to understand how the temperature changes over time. You can find the exact times in a given day when the temperature was the highest or lowest, when the temperature changed the fastest, and maybe even use the data to make predictions! Can you beat your local weather station and make a prediction that is better?

confused weatherman

How to build your weather station

For this experiment, you will need an Arduino Yún (or an equivalent Arduino that has wireless capability), a TMP36 temperature sensor, and a breadboard and jumper wires.

Here is the hardware diagram. Connect the 5V pin to the left pin of the TMP36 sensor, the GND pin to the right pin of the TMP36, and the A0 pin to the middle TMP36 pin:

TMP36 hardware diagram

Once everything is connected and powered up, the TMP36 sensor will send a voltage to the A0 pin. This voltage increases when the temperature goes up and decreases when the temperature goes down. So we can use the voltage reading and interpret it as a temperature. Luckily in this experiment we only needed three jumper cables.

Programming the Arduino

Now we are ready to write the Arduino code that will upload the recorded temperature data to the Wolfram Cloud. Make sure your Arduino Yún is configured to connect to the internet. Then, using the Arduino application, upload the following sketch onto your Arduino after you replace the text “YOUR_BIN_ID” with the “Short ID” of a databin that you created yourself:

arduino databin sketch

To follow along with the code, here is what it does: The process p variable is used for calling a tool called curl, which is a way to make http requests with your Arduino. In our case, we call a specific Data Drop URL, which lets you upload small bits of temperature data easily. In the loop() section of the code, you can see how the variable val is reading from the analog pin (A0), and how val is then converted from a raw reading to a temperature variable. This temperature is then added to an average variable exactly 60 times, but on the 60th time, the code will execute the block of the if statement. This code block runs the data upload code to upload the average of the 60 measurements. It also resets all the counters so that everything will start over again. Finally, at the end is a 1000-millisecond delay that will (approximately) space out your recorded temperatures by one second:

breakdown of code

To test that everything worked, you can open the Arduino serial monitor. If successful, you will see messages like the one below appear every minute or so:

open arduino serial monitor message

Now you can put your device in a weather-resistant container (I used a Hefty bag) and place it outside in a location that is shaded for most of the day (like a porch):

arduino device in weather resistant container

Analysis of the temperature data

Now we’re ready to do some interesting analysis of your temperature data! It’s best to collect at least one full day of data before analyzing it, but the code below should work for shorter time periods as well. First, we need to get the data from the databin we used to upload the temperature data. The Arduino sketch uses temperature as the URL parameter for the temperature, so we will need to use the same thing here to retrieve it. In this example, my databin has collected data for about 20 days (for your experiment, replace the text “YOUR_BIN_ID” with the bin ID shown in the output from CreateDatabin above):

tempurature data analysis

Now we will need to transform the temperature event series in a few more steps.

First, shift the series to account for the proper time zone (CST). This is done with the TimeSeriesShift command.

Next, calibrate the temperatures so they match more closely official NOAA measurements for a nearby official weather station. In my case I used an official NOAA weather station (KCMI) to calibrate my $2 TMP36 temperature sensor with the undoubtedly much more expensive and precise official sensor data. Calibration is an important step, and in this case I had to correct my data by about 5 degrees Celsius to match the official data. Another good way to calibrate your TMP36 sensor is to place it in a cup of ice water (exactly 0 degrees Celsius) and a cup of boiling water (exactly 100 degrees Celsius).

Next, define the time window of interest. In my case the starting point of reliable data was on January 22 at 9pm. You will need to change this to a date that is a good starting point for your data.

Finally, resample the data to evenly spaced periods of 15 minutes. You will quickly notice that recording data every minute will give you a massive amount of data points, and sampling it back to 15-minute intervals will still give you enough data to work with for plots that show multiple days of data.

Here is all the code we just discussed above:

adruino temperature code

At this point you can do a quick check to make sure that your temperature data is looking OK:

datalistplot for temperature with arduino

But we can make this a lot more useful and interesting. Let’s write a function that will collect a specific point of interest for each day of data, for example the min and max of this data:

function for collecting a specific point each day

The function above simply generates a new EventSeries from the given one and collects the data points that satisfy a particular function for a given day.

First let’s create a new EventSeries that contains all the daily minimum temperatures:

eventseries containing all daily min temps

And now do the same for the daily maximum temperatures:

eventseries containing daily max temps

And now we can plot the temperature data (purple) with the daily minimum temperatures (blue dots) and maximum temperatures (red dots):
temperature data for daily min and max temperatures


And that is it for this experiment! You now have a working weather station, and a dataset that is easy to analyze. By modifying the given code, you can visualize daily, weekly, or monthly averages. Or you can try to make predictions for tomorrow’s weather based on patterns you have observed in the past (and perhaps combine this data with additional weather measurements like pressure and humidity data).

Download this post as a Computable Document Format (CDF) File.

Leave a Comment

No Comments

Leave a comment


Or continue as a guest (your comment will be held for moderation):