Create your own weather station integrated with Wolfram Cloud

Original author: Arnoud Buzing
  • Transfer
Recently, Stephen Wolfram announced the Wolfram Data Drop service , which is a great tool for downloading any type of data from any device. I will show how you can use Wolfram Data Drop with a home-made weather station, to create which we need only simple hardware and a few lines of code. This weather station will take temperature measurements every second, and every minute will upload the average value for that minute to Wolfram Data Drop. Thus, 60 points will be obtained on the temperature – time graph every hour, 1440 points per day. Using this data and Wolfram Programming Cloud, you can study temperature changes over time. For example, you can find out how many times a day the temperature reached certain minimum and maximum values ​​when the temperature changed most rapidly. Using this data, you can even make forecasts. Perhaps someone can even make more accurate predictions than the local weather station!

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_1.png

How to build your own weather station


For this experiment you will need:

1) Arduino Yún (or equivalent, but always with Wi-Fi);

2) temperature sensor TMP36 ;

3) breadboard and wires.

Here is the assembly diagram. Connect 5V to the left terminal of TMP36, ground to the right terminal of TMP36, and A0 to the middle terminal of TMP36.

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_2.png

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_3.gif

As soon as everything is connected and turned on, the sensor begins to transmit voltage to pin A0. If the temperature rises, then the voltage rises, and if the temperature drops, then the voltage, respectively, also drops. Thus, we can take stress indicators and interpret them as temperature. Fortunately, in this experiment we only need three small wires, which avoids the situation as in the picture below with this unfortunate one:

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_4.gif

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_5.gif

Arduino Programming


Now we are ready to write a code for Arduino that will load the recorded temperature data onto the Wolfram Cloud. Make sure your Arduino Yun is configured to connect to the Internet . Then, using the Arduino application, upload the following code to Arduino after replacing the text “YOUR_BIN_ID” with “Short ID”, which is displayed as the result of the CreateDatabin [] function.

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_6.png

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_7.gif

A little clarification as to what the code does: the p variable is used to invoke a tool called curl that allows you to create HTTP requests with Arduino.

In our case, we set a specific URL for Wolfram Data Drop, which allows you to load temperature data . In the loop () loop , which can be seen in the code, you can observe how the variableval is read from the analog input (A0), and how val is then converted from initial values ​​to temperature temperature .

This temperature was then added to the mean average exactly 60 times, but at the 60th time the program calculates the second block with If [].

This code block initializes a data loading code that sends an average value of 60 measurements.

It also resets all counters, so that everything starts again.

This is followed by a 1000-millisecond delay, which will order the data recorded per second:

#include < Bridge.h >
  Process p;
int val, count;
float voltage, temperature, average;
void setup () {
   count = 0;
   average = 0;
   Bridge.begin ();
   Serial.begin (9600);
  }
void loop () {
   val = analogRead (0);
   voltage = val * 5.0;
   voltage = voltage/1024.0;
   temperature = (voltage - 0.5)*100;
   average += temperature;
   count++;
   if ( count > 59 ) {
      p.begin ("/usr/bin/curl");
      p.addParameter ("--insecure");
      p.addParameter ("--location");
      p.addParameter ("https://datadrop.wolframcloud.com/api/v1.0/Add?bin=YOUR_BIN_ID&temperature=" + String (average/60));
      p.run ();
      while (p.available () > 0) {
         char c = p.read ();
         Serial.print (c);
        }
       Serial.println ();
      Serial.flush ();
      count = 0;
      average = 0;
     }
    delay (1000);
  }

To make sure everything works, you can open the built-in Arduino monitor; in case everything goes as it should, you will see messages like the one below that will appear every minute (or so):

<|"Message" -> "The data was successfully added.", "Bin" -> "DD7051e03ace9-a194-44c1-9864-8fcef8ea9af3", "Data" -> <|"temperature" -> "34"|>, "Timestamp" -> {2015, 2, 9, 16, 18, 39.99526`8.354583502904967}, "Information" -> {"EntryCount" -> 1, "LatestTimestamp" -> 3632487520, "Size" -> 288}|>

Now it's time to put our device in something tight (in my case, the Hefty bag), and put it in a place that is in the shade all day (for example, on the veranda):

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_8.gif

Temperature Data Analysis


Now we are ready to do some interesting things with the obtained temperature data. It is best to collect data at least one day before you begin the analysis, but the code allows you to work with less data. First we need to get the data from the databin, which we used to load the temperature data.

The Arduino program passes the temperature as a URL parameter, which we use in our program. In my example, the databin collected data for 20 days (for the experiment, you need to replace “YOUR_BIN_ID” with the bin ID that was obtained as a result of CreateDatabin earlier:

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_9.gif

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_10.gif

Now we need to convert the temperature data (temperature event series) using a few more steps.

Firstly, throughTimeSeriesShift needs to enter time zone data.

Next, calibrate the sensor based on data from the nearest major weather stations. Personally, I calibrated my two-dollar TMP36, relying on data from one of the weather stations of the National Oceanic and Atmospheric Administration (NOAA KCMI), where incomparably more expensive and accurate equipment is located. Calibration is a very important step; As a result of calibration, I had to correct my data by about 5 degrees so that they corresponded to the official ones. There is another good way to calibrate: place the sensor in ice water with a temperature of 0 degrees, and then in a glass of boiling water (100 degrees), and adjust the data.

Next, you need to select the time interval of interest. In my case, the reference point is January 22 at 9 a.m. You, accordingly, should replace this date with that which corresponds to the beginning of your measurements.

Finally, you should repartition the data into intervals of 15 minutes, that is, we will use 15 times fewer points for construction. The fact is that this data will be quite enough to work with intervals that are measured in days.

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_11.gif

Here you can make a quick check to see if the temperature data looks correct:

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_12.png

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_13.gif

The work with the data does not end there, and we can do very interesting and useful things using them. You can write a function that will collect the minimum / maximum temperature values ​​for each specific day, or any other noteworthy values:

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_14.png

The function presented below creates a new series of events ( EventSeries ) from the given one and collects those points that satisfy a certain function for a given day.

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_15.png

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_16.gif

Now you can do the same for daily maximums:

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_17.png

Build-Your-Own-Weather-Station-in-a-Snap-with-the-Wolfram-Cloud_18.gif

Now we can display the temperature data (purple) on a chart with daily highs (red dots) and minimums (blue dots):

Build-your-own-weather-station-in-a-snap-with-the-wolfram-cloud_19.png

Graphics: Temperature (° C) in Savoy, Illinois

Conclusion


Now we have our own working weather station and incoming data that can be easily analyzed. By changing the presented code, you can visualize daily, weekly or monthly average temperature values. You can also try to predict the temperature for tomorrow, based on previously observed dependencies and, possibly, combining temperature data with some additional ones: humidity, pressure and the like.

Arnoud Buzing, Build Your Own Weather Station in a Snap with the Wolfram Cloud! ".
You can download the translation in the form of a Mathematica document, which contains all the code used in the article here .
I express my deep gratitude to Kirill Guzenko for help with the translation.

Also popular now: