This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Calculate Wind Chill and Update Channel

The MATLAB Analysis and MATLAB Visualizations apps in ThingSpeak™ let you pick from a selection of code templates as a starting point for building your own project. This example uses a code template to demonstrate how to read data from a public channel, analyze the data, and schedule the code to run at regular intervals. This example uses data from ThingSpeak channel 12397, which collects temperature and wind speed from an Arduino-based weather station in Natick, MA, to determine wind chill.

Create a Channel

Sign in to ThingSpeak to create a private channel to record and plot temperature, wind speed, and wind chill. Go to the Channels tab, and select My Channels. Click New Channel. Select the corresponding check box and enter these channel setting values:

  • Name: Wind Chill Measurement

  • Field 1: Temperature (F)

  • Field 2: Wind Speed (mph)

  • Field 3: Wind Chill (F)

Click Save Channel.

Analyze and Write Your Data

To analyze data from a public channel and write it to your private channel, you write a MATLAB® script using the code template provided. The weather station in Natick collects weather-related data and sends the results to a public ThingSpeak channel. You can access the live weather station data to calculate the wind chill and automatically graph it.

  1. Navigate to the Apps tab, and select MATLAB Analysis. Click New, choose the Calculate wind chill and update channel option, and click Create.

  2. The MATLAB Code field is prepopulated with the code to analyze and write data. Replace the given values for writeChID and writeAPIKey with your channel settings. You can find the channel ID and API Key under the Channel Info panel on the right side of the page. Since this channel is private, specify the API Key.

    readChID = 12397;
    % Replace [] with your channel ID
    writeChID = [];
    % Enter your Write API Key between the ''
    writeAPIKey = '';

  3. Use the thingSpeakRead function to retrieve the latest temperature and wind speed reading from fields 4 and 2, respectively, in the weather station channel. This function records the timestamp as well.

    [temp,time] = thingSpeakRead(readChID,'Fields',4);
    windSpeed = thingSpeakRead(readChID,'Fields',2);
  4. Calculate and display wind chill temperature from the values obtained in the previous step. Wind chill is used as a measure of the air temperature, taking into account the cooling effects of wind on human skin. It is only valid when the air temperature is less than 50 degrees Fahrenheit and the wind speed is greater than 3 miles per hour. This example uses the formula found on the National Weather Service website to calculate wind chill.

    windChill = 35.74 + (0.06215*temp) - (35.75*windSpeed^0.16) + (0.4275*temp*windSpeed^0.16);
    display(windChill,'Wind Chill');
  5. Write the two measured values and the calculated value to fields 1, 2, and 3 in your private ThingSpeak channel.

  6. Execute your code by clicking Save and Run. Each of the three charts in your ThingSpeak channel is populated with a single point. You can access your channel by clicking the channel link in the Channel Info panel on the right side of the page.

Schedule Code

You can use the TimeControl app to set your code to run at regular intervals. By doing so, you generate a continuous plot of wind chill over time in your ThingSpeak channel.

  1. On the page with your MATLAB code, scroll to the bottom, and open the TimeControl app settings.

  2. Name your new TimeControl Wind Chill Control. Set Frequency to Recurring and Recurrence to Minute. Select 30 in the Every — minutes dropdown list.

  3. Set Action to MATLAB Analysis and Code to execute to Calculate wind chill and update channel.

  4. Click Save TimeControl.


Setting up a TimeControl to write data to your channel uses available messages on your ThingSpeak account. This action can eventually exhaust available messages, which results in rejection of channel feed updates.

The three charts in your ThingSpeak channel now update with a new wind chill value every 30 minutes.

See Also


Related Examples

More About

Was this topic helpful?