ThingSpeak IoT Blog

IoT Day is the Day to Learn About Our New MATLAB Analytics Features

April 9th is IoT Day! We are celebrating by announcing new IoT Analytic features. All ThingSpeak users now have access to the new features of MATLAB R2017a. In ThingSpeak you can analyze and visualize your data using the power of MATLAB. With the latest updates you can visualize your IoT data as a heatmap and analyze large sets of time-stamped data using a tall timetable.

In the latest update, we have added many new analytics features perfect for IoT data:

  • isoutlier / filloutliers: To find outliers in your data, use the isoutlier function. To replace outliers with alternative values, use the filloutliers function.
  • smoothdata: Smoothing noisy data is now possible with the smoothdata function. For example, smoothdata(A,’movmedian’) smooths data with a moving-window median.
  • fillmissing: Filling missing data using a moving mean or moving median option is now available with the fillmissing function.

Smooth Weather Data

At our headquarters in Natick, MA, we have a weather station sending data to ThingSpeak channel 12397. We use ThingSpeak to collect raw temperature, humidity, wind, and rain data. We use MATLAB to analyze and visualize the data so we can use it for forecasting plant harvesting and building weather models. Learn how to build your own weather station at and learn how to analyze the weather data using MATLAB with the source code on File Exchange.

Often you want to process the raw data by removing outliers and smoothing the data. This helps if you are building a predictive model and to better visualize the data. The common IoT analytics workflow is to read in raw data, synchronize the data in time, detect and remove outlier values, smooth the data, and visualize the data. This example works on ThingSpeak, MATLAB Online, and desktop MATLAB.

Read historic weather data

[weather,channelInfo] = thingSpeakRead(12397,...
'DateRange',[datetime('Feb 04, 2016'),datetime('Feb 10, 2016')],...

Convert to timetable

weather = table2timetable(weather);

Smooth the data

First, resample the timetable using the retime function so the times and data are uniformly spaced on the minute.

wdata = retime(weather(:,{'Humidity','TemperatureF'}),'minutely','linear');

Smooth the data using a moving median and compare this to the original data. There are a number of moving statistics functions for vectors and matrices like movmean, movmedian, etc and also the smoothdata function which also works on timetables and uses the RowTimes as the sample points. Moving median is the default and other options are available.

smdata = smoothdata(wdata);

Visualize the original and smoothed temperature data on a plot

legend('Raw Data','Smooth Data')
ylabel('Temperature (\circF)')
title('Temperature Over Time')

Smooth Weather Data

Have a happy IoT Day and we hope that you understand your IoT data a littler more by using MATLAB Analytics on ThingSpeak. I would like to thank Heather Gorr for helping me put together the example MATLAB code. Cheers!

Build IoT Projects on Arduino Day Using MATLAB and ThingSpeak

April 1st is Arduino Day, no joke! For in person events near you, check out the Arduino Day website. If you have been kicking around an idea about a project to build, this is a great time to try to get it done and share it with others from around the world. We provide some great tools to build projects that use Arduino.

MathWorks Arduino Resources

Maybe it’s time to build your version of a MATLAB and Arduino powered dartboard.

We hope you build some awesome projects using Arduino, MATLAB, Simulink, and ThingSpeak on Arduino Day!

Building a Dynamic and Self-organizing Network of Devices

Anders Sollander, a principal technical consultant at MathWorks, and his team put together a project to determine what demo was the most popular at one of our demo showcases. Anders made an assumption that if your demo was popular, you would have a lot of visitors. If you have a lot of visitors, your demo would be the loudest.

Anders was determined to measure sound from over 20 demo stations at the same time and figure out who the the winner is. This turns out to be a complicated challenge and he used our tools such as MATLAB, Simulink, and ThingSpeak, to produce some interesting results. Here’s what the raw data looks like from just five sound sensor nodes at the demo stations.

The sensor nodes uses the Arduino Nano devices because they’re small, low-cost, and Simulink has an Arduino support package. Arduino Nano’s both low cost and energy efficient which is great, but it doesn’t have Wi-Fi. They connect the sensor nodes to an Internet-connected Raspberry Pi using an RF mesh network with the nRF24l01+ radio. The RF24 solution is both very cheap and energy efficient, which is valuable if you’re running them with battery power. Simulink Coder has a Raspberry Pi Support Package which simplified the workflow.

When you follow the tutorial, you are going to learn many things and experience their analytic workflow as they decide how to develop an algorithm to normalize sound levels, determine which data to send to ThingSpeak, and build visualizations to see the results of the project.

Anders also shared a library on File Exchange that allows users to communicate with RF24 chips on Raspberry Pi and Arduino boards. The library relies on the RF24Mesh library, and has S-functions that interact with the classes there. The File Exchange submission includes an example for the Arduino to read sensor data from a temperature sensor and sends it to the gateway Raspberry Pi and then sends the data to ThingSpeak. In order to download the File Exchange, you need to sign in with your MathWorks account. This would be the same account that you use on

Visit ThingSpeak Tutorials, to see the complete tutorial for Building a Dynamic and Self-organizing Network of Devices.

Cadmus Collects and Analyzes IoT Data Using MATLAB and ThingSpeak

The Internet of Things (IoT) enables power producers, public utilities, and other companies in the energy sector to collect energy power consumption data from hundreds of factories and thousands of homes in near real time. This wealth of information has opened opportunities to evaluate energy efficiency initiatives, predict power demand, and perform energy audits.

Consulting firm Cadmus provides full-spectrum energy-efficiency support services to energy utilities throughout North America. These services include studies of energy use that require extensive data collection and analysis.

To make the most of the opportunities presented by the IoT, Cadmus engineers used MATLAB® and the ThingSpeak™ IoT platform to develop a workflow for collecting, storing, analyzing, visualizing, and interpreting data from sensors in homes and businesses distributed across wide geographic areas.

“In just a few months, we implemented a new service that measures and analyzes temperature and humidity changes in dozens—and soon hundreds—of homes,” says Dave Korn, vice president of engineering at Cadmus. “Without MATLAB and ThingSpeak, we would still just be talking about it. Instead, we’re already pitching this service to utilities. That is a huge competitive advantage for our company.”


Cadmus used MATLAB and ThingSpeak to develop and deploy two systems of cloud-connected sensors for the near-real-time measurement and analysis of energy data, while establishing a workflow for rapidly implementing similar systems.

The first system, designed for an energy efficiency study of residential homes, used custom sensors to send temperature, relative humidity, and device battery voltage measurements to ThingSpeak every five minutes. The second, designed to monitor loads of HVAC systems and large appliances, used off-the-shelf home automation hardware to send power usage data, captured at residential circuit breakers and individual outlets, every minute.

Using the ThingSpeak web application, the engineers created new channels to collect data from the sensors and to quickly verify that each new sensor added to the system was reliably sending data.

Working in MATLAB, the team analyzed the collected data, using standard statistical techniques to identify outliers and calculate means and standard deviations. For example, they calculated and plotted power load profiles by the hour and correlated the load data with weather data from an outside source.

They created a variety of data visualizations, including interactive maps, which they shared with clients and prospects.

Cadmus engineers are currently using MATLAB and Statistics and Machine Learning Toolbox™ to develop predictive algorithms based on machine learning and advanced classification and regression techniques. These algorithms are designed to predict and model load based on weather conditions and sensor data collected via ThingSpeak.


  • Market opportunity seized. “In our industry, many utilities are looking to design better energy efficiency programs and to lower the costs of those programs,” says Korn. “MATLAB and ThingSpeak enabled us to develop solutions rapidly, which meant we could capitalize on these demands this fall. Without MATLAB and ThingSpeak we would have had to wait until spring and miss numerous opportunities in the market.”
  • Development effort cut by two-thirds. “With MATLAB and ThingSpeak, our team of five engineers was collecting and analyzing data in a matter of months. We could not have met our deadlines without them,” says James Kennedy, energy analyst at Cadmus. “With other tools we would probably have needed 15 engineers to complete the work in the same time amount of time—if we could have done it at all.”
  • Sensor networks quickly deployed. “On our first project with ThingSpeak, it took just over three months to implement a network that we quickly scaled from 50 operational sensors to 500,” says Kennedy. “In a very short period we had another complete network set up and collecting data, and that one was deployed at an even faster rate than the first.”

Create a GPS Tracker with MATLAB Mobile and ThingSpeak

Takuji Fukumoto, an Application Engineer at MathWorks, shared a project with me that he created that uses capabilities of MATLAB Mobile™, MATLAB Drive™, MATLAB Online™, and ThingSpeak™. His project uses MATLAB Mobile to send its position and sensor data to ThingSpeak. He then uses MATLAB® to process the data and generate maps of his position.

You might have noticed recently on ThingSpeak that you can link your ThingSpeak user account to a MathWorks Account. By doing so, you have access to other MathWorks products and services that you can use with the same user account. MATLAB Mobile is a native Apple or Android app that allows you to evaluate MATLAB commands, create and edit files, view results, acquire data from sensors, and visualize data. MATLAB Mobile also has thingSpeakRead and thingSpeakWrite functions built-in. One exciting aspects of MATLAB Mobile is that you can capture the sensor data of the mobile device and send it to MATLAB Online.

To take the project further, you can use additional toolboxes from MathWorks to preprocess the data and do advanced mapping. Takuji demonstrates using the Signal Processing Toolbox™ to filter, down sample, and remove outliers from the incoming data from the MATLAB Mobile sensors. Using the Mapping Toolbox™, he plots the latitude and longitude of his mobile device on a WPS map and displays the map on a ThingSpeak channel.

Takuji has shared all of the source code and steps on File Exchange so you can replicate this project on your own mobile device. Check out his project on File Exchange and see his raw data and visualizations on ThingSpeak.