ThingSpeak IoT Blog

Learn How to Build a Condition Monitoring IoT System

Douglas Mawrey created a Smart Humidity Sensor using ThingSpeak to collect data, MATLAB to analyze the data, and IFTTT to send push notifications for certain conditions. This project uses the outdoor temperature to determine the ideal indoor humidity and inform you about the room’s comfort. The data and condition results are displayed on Douglas’ public ThingSpeak channel 418058. This project is a good starting point to see the power of the MATLAB integration on ThingSpeak and how to perform real-time condition monitoring.

Setting up the Sensor

This project uses the ESP-based NodeMCU as an IoT gateway to forward sensor data to ThingSpeak. The NodeMCU is essentially a microcontroller and a Wi-Fi device that costs less than $10 US. The humidity sensor that is used in this project is the DHT11. This a very common sensor used to monitor temperature and humidity. The sensor either comes in a 4 pin or 3 pin package. The NodeMCU is programmed with the Arduino IDE using the code in Douglas’ tutorial or GitHub.

Using ThingSpeak Metadata

Douglas uses the metadata setting within a ThingSpeak channel to store condition ranges. This allows you to adjust settings in your online analytics code without redeploying new code. Each ThingSpeak channel has a metadata setting. You can store arbitrary text data that can be used in your MATLAB Analysis code. To load your channel’s metadata into MATLAB, use the webread function and add metadata=true to the ThingSpeak API Read Data request.

indoorChannelData = webread(strcat('', ...
                                    num2str(indoorChannelID), ...
                                    '/feeds.json?metadata=true&api_key=', ...

Using MATLAB for Condition Monitoring

Douglas uses MATLAB on ThingSpeak to determine the proper condition. This is a common requirement in complex IoT systems. This example could be a good starting point for building a condition monitoring system for industrial maintenance applications. You use MATLAB to determine the target humidity using a polynomial fit over the lookup data.

lookupFit = polyfit(humidityLookup(:, 1), humidityLookup(:, 2), length(humidityLookup) - 1);
optimalHumidity = polyval(lookupFit, curTempOut);

humidityDiff = curHumidity - optimalHumidity;

Using IFTTT for Alerts

Often you want to get notifications when a certain condition is met. Douglas shows you how to use IFTTT to send push notification directly to your phone. In this project, MATLAB is determining the condition and then interfaces with the IFTTT API to send the push notification. To send push notifications via IFTTT, use the webwrite function in MATLAB.

webwrite(strcat('', makerEvent, ...
                '/with/key/', makerKey), ...
                'value1', stateMsg, ...
                'value2', char(timeSinceChange, 'hh:mm'));

All of the MATLAB code can be deployed on ThingSpeak and scheduled to be executed periodically without having this on your desktop computer. The complete Smart Humidity Sensor project tutorial is available on Feel free to discuss on the MATLAB Maker Community.

What is a Bomb Cyclone? Use ThingSpeak and MATLAB to Figure it Out.

Social media is blowing up the term bomb cyclone. The term is everywhere from Twitter to 24/7 news coverage of the storm hitting the East Coast of the United States. The technical term for a bomb cyclone is bombogenesis which is the combination of “bomb” and “cyclogenesis.” Or, you could call it an explosive cyclogenesis to grab views to your blog.

A storm undergoes bombogenesis when its central low pressure drops at least 24 millibars in 24 hours, according to the National Oceanic and Atmospheric Administration (NOAA).

At the MathWorks headquarters in Natick, MA we have a weather station sending data to ThingSpeak for the past several years. Here’s what the weather station looks like on a better day.

Not many interesting events emerge from the data, but with something called a bomb cyclone, Rob Purser decided to take a closer look using MATLAB. Our weather station on ThingSpeak channel 12397 collects temperature, humidity, and pressure data. By taking a look at this MATLAB plot of the pressure analyzed over 24 hours, you will see the pressure drops at least 24 millibars in 24 hours and in fact over 40 millibars. This storm definitely fits its name of explosive cyclogenesis.

Have a look at the raw data from ThingSpeak and see if you can determine the bomb cyclone event. In MATLAB, use thingSpeakRead via the ThingSpeak Support Toolbox. We documented the process of analyzing the weather station data using MATLAB on Just follow the steps using MATLAB or MATLAB Online, to discover some interesting results.

Stay warm.

Learn How to Build a Custom Android App for a ThingSpeak IoT Project

ThingSpeak has APIs for collecting data produced by sensors and APIs for reading that data from applications. Think of an IoT project as two parts. One part of the project is where you need to program a thing to send data. And, the second part is where you want to see that data. ThingSpeak sits in the middle and makes it handy to do both, as Marcelo Rovai points out. Once you have a system like Marcelo’s set up, you can take advantage of integrated online MATLAB Analytics.

Marcelo has put together a great tutorial that uses ThingSpeak in the middle to collect data from sensors and then display the sensor readings on a custom Android app running on a mobile phone. He uses the MIT App Inventor to create a custom Android app to see the sensor data and status of the system. This project uses easily accessible hardware to build a proof-of-concept IoT system to monitor air temperature, humidity, soil temperature, soil humidity, and luminosity. Other people could modify this project with different sensors or actuators and build something for their own purposes or build a prototype for your next meeting at work.

Check out the full project tutorial on Arduino Project Hub and Instructables. Marcelo provides all of the parts, code, and instructions to make your own prototype IoT system monitored and controlled by a mobile app.

Subscribe to ThingSpeak IoT Data using MQTT

The ThingSpeak IoT service now supports MQTT subscriptions to receive instant updates when a ThingSpeak channel gets updated. MQTT is a powerful standard for IoT systems. ThingSpeak enables clients to update and receive updates from channel feeds via the ThingSpeak MQTT broker. MQTT is a publish/subscribe communication protocol that uses TCP/IP sockets or WebSockets. MQTT over WebSockets can be secured with SSL. A client device connects to the MQTT broker and can publish to a channel or subscribe to updates from that channel.


We also published a new File Exchange submission that allows you to publish and subscribe using MQTT within MATLAB. Download and install MQTT in MATLAB to be able to connect to ThingSpeak’s MQTT server or connect to other standard MQTT brokers such as AWS IoT. Using this Add-On in MATLAB allows you to define custom functions to evaluate on receiving messages streaming over subscribed topics.

ThingSpeak MQTT Examples

View our ThingSpeak MQTT documentation to learn more about MQTT support on ThingSpeak, and find examples for Arduino, Particle, and Raspberry Pi.

Collecting Resting Heart Rate Data Using ThingSpeak With a $5 Wi-Fi Device

Naman Chauhan from SRM University created a proof-of-concept project that measures your resting heart rate and sends the data for analysis via a $5 Wi-Fi device. The project is fully documented with the source code on either Hackaday or Hackster.

Naman uses an Arduino for processing the heartbeat data and turns the data into heartbeats per minute. Then, periodically, the device sends the data to ThingSpeak for data storage and data analysis using MATLAB. The heart rate monitor is connected to the internet using DFROBOT’s ESP8266 Wi-Fi Bee. The Wi-Fi Bee turns serial data-to-Wi-Fi.

This heart rate monitor sensor is a pulse sensor which is developed based on PPG techniques. This is a simple and low-cost optical technique that can be used to detect blood volume changing in the microvascular bed of tissues. It is relatively easy to detect the pulsatile component of the cardiac cycle according to this theory.

To build your own, check out Naman’s tutorial on either Hackaday or Hackster.