ThingSpeak IoT Blog

The Data Science Behind BBQ

Smoking ribs or a pork shoulder requires lots of patience and practice. When everything works, you get to enjoy an amazing dinner. When things go wrong, you end up with dry, overcooked meat that only your dog may enjoy. Here’s what great BBQ looks like from @AndreasHarsch.

My process of smoking meat, cheese, or even ice cream is to monitor only the meat temperature and the internal temperature of the smoker. When I finish a cook, I go back and try to learn from the data. I do not attempt to control the smoker using the Internet of Things, I use IoT to collect the data with ThingSpeak, analyze the data with MATLAB, and apply the insights to the next cook. The best advice that I have been given is to not change too many variables. Stick with simple rubs, the same charcoal, the same wood, the same cuts of meat, etc. Only change one variable for one cook. It takes years of trial and error before you get great at BBQ.

With the help of ThingSpeak and MATLAB, I can help you understand one of the more frustrating parts of smoking meats… the stall! The stall is a period of time where what you are cooking does not seem to be increasing in internal temperature. I used to panic during the stall and mess with the temperature by adding more charcoal or turning the vents. Overtime, I realized this is normal. No reason to panic.

Cooking is taking something cold and getting its internal temperature up to a safe level. Everything that you cook has a different target internal temperature, but generally the sweet spot is 190-205F. Smoking is about low and slow cooking. This means that you are trying to raise that internal temperature slowly with a low temperature. I use a cook temperature of 230-250F. This means that smoking takes a lot of time to properly cook. In some cases, this is two hours per pound. Things don’t change much minute to minute in a BBQ pit, so you can collect data every few minutes and still have an accurate picture of what’s happening.

Collecting Data

First, I set up a ThingSpeak channel to store my temperature data. One field is for the smoker’s temperature and field two is for the internal temperature of what I am cooking. To get the data, you have many options. I did a quick search around the internet and discovered hundreds of Arduino and ThingSpeak projects to get data from a smoker. In general you need two temperature probes that can take the heat of the smoker, connectors, an Arduino with Wi-Fi like the MKR1000.

Analyzing the Temperature Data

The first step is to read in the temperature data using MATLAB that was collected by ThingSpeak. Data on ThingSpeak is stored in a channel and identified by a channelID. If you have a private channel, you will need to supply a Read API Key to get access to the data.

smokerTT = thingSpeakRead(279400,'ReadKey','9AYZQDT1XFDM98FW','OutputFormat','timetable','NumPoints',115);

Sometimes the data from your temperature probe is noisey. This means the value that the temperature probe reports is sometimes higher or lower than the actual temperature. If you take a few samples and take a median, you get a consistent result. In MATLAB, I use smoothdata to take a moving median of my time-series sensor data.

smoothSmoker = smoothdata(smokerTT);

After I clean up the data, I want to visualize it and to see what happened. This is a good time to learn how long things actually take, so on your next cook you budget the right amount of time and don’t rush any phases.

plot(smoothSmoker.Timestamps, smoothSmoker.Variables);

I can use this data to determine how long the total cook will last and even set alerts using ThingSpeak. I tend to watch the smoker and tend the fire.


After a lot of research, I discovered what the stall is doing and why it is important to keep your patience and push forward. This is starting to sound like a metaphor for life. According to Prof. Greg Blonder, “The stall is evaporative cooling”. Prof. Greg is a physicist, entrepreneur, former Chief Technical Advisor at AT&T’s legendary Bell Labs, and regularly contributes to He likes to bust myths about barbequing and help us understand the thermodynamics of cooking. You are heating the meat slowly, but the moisuture in the meat is evapotaring at the same rate. This effect causes a stall in the temperature rise. The temperature of the meat will go up when the moisture is depleted. The stall is important to the cooking process and leads to something called the bark. This is an outer layer of the meat that is slightly thicker and less tender than the rest of the meat, but traps in lots of flavor and adds to its complexity. So, don’t rush during the stall. Keep the smoker temperature constant – avoid the temptation to turn the heat up to get through faster. And in the end, enjoy some well made BBQ with friends and family over the summer weekends and holidays.

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.”