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('https://api.thingspeak.com/channels/', ... num2str(indoorChannelID), ... '/feeds.json?metadata=true&api_key=', ... indoorChannelReadKey));
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('https://maker.ifttt.com/trigger/', 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 Hackster.io. Feel free to discuss on the MATLAB Maker Community.
要发表评论，请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。