{"id":2298,"date":"2018-02-22T11:00:49","date_gmt":"2018-02-22T16:00:49","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=2298"},"modified":"2018-02-22T11:02:45","modified_gmt":"2018-02-22T16:02:45","slug":"learn-how-to-build-a-condition-monitoring-iot-system","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2018\/02\/22\/learn-how-to-build-a-condition-monitoring-iot-system\/","title":{"rendered":"Learn How to Build a Condition Monitoring IoT System"},"content":{"rendered":"

Douglas Mawrey<\/a> created a Smart Humidity Sensor<\/a> 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<\/a>. 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.<\/p>\n

\"\"<\/a><\/p>\n

Setting up the Sensor<\/h3>\n

This project uses the ESP-based NodeMCU as an IoT gateway to forward sensor data to ThingSpeak. The NodeMCU<\/a> is essentially a microcontroller and a Wi-Fi device that costs less than $10 US. The humidity\u00a0sensor 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<\/a>\u00a0or GitHub<\/a>.<\/p>\n

\"\"<\/a><\/p>\n

Using ThingSpeak Metadata<\/h3>\n

Douglas uses the metadata setting\u00a0within 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\u00a0text data that can be used in your MATLAB Analysis code. To load your channel’s metadata into MATLAB, use the webread\u00a0<\/em>function and add metadata=true to the ThingSpeak API Read Data<\/a> request.<\/p>\n

indoorChannelData<\/span> =<\/span> webread<\/span>(<\/span>strcat<\/span>(<\/span>'https:\/\/api.thingspeak.com\/channels\/'<\/span>,<\/span> ...<\/span>\r\n<\/span>                                    num2str<\/span>(<\/span>indoorChannelID<\/span>),<\/span> ...<\/span>\r\n<\/span>                                    '\/feeds.json?metadata=true&api_key='<\/span>,<\/span> ...<\/span>\r\n<\/span>                                    indoorChannelReadKey<\/span>));<\/span><\/span><\/pre>\n

Using MATLAB for Condition Monitoring<\/h3>\n

Douglas\u00a0uses MATLAB on ThingSpeak to determine the proper condition. This is a common requirement in complex\u00a0IoT 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.<\/p>\n

lookupFit<\/span> =<\/span> polyfit<\/span>(<\/span>humidityLookup<\/span>(:,<\/span> 1<\/span>),<\/span> humidityLookup<\/span>(:,<\/span> 2<\/span>),<\/span> length<\/span>(<\/span>humidityLookup<\/span>)<\/span> -<\/span> 1<\/span>);<\/span>\r\n<\/span>optimalHumidity<\/span> =<\/span> polyval<\/span>(<\/span>lookupFit<\/span>,<\/span> curTempOut<\/span>);<\/span>\r\n<\/span>\r\n<\/span>humidityDiff<\/span> =<\/span> curHumidity<\/span> -<\/span> optimalHumidity<\/span>;<\/span><\/span><\/pre>\n

Using IFTTT for Alerts<\/h3>\n

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\u00a0function in MATLAB.<\/p>\n

webwrite<\/span>(<\/span>strcat<\/span>(<\/span>'https:\/\/maker.ifttt.com\/trigger\/'<\/span>,<\/span> makerEvent<\/span>,<\/span> ...<\/span>\r\n<\/span>                '\/with\/key\/'<\/span>,<\/span> makerKey<\/span>),<\/span> ...<\/span>\r\n<\/span>                'value1'<\/span>,<\/span> stateMsg<\/span>,<\/span> ...<\/span>\r\n<\/span>                'value2'<\/span>,<\/span> char<\/span>(<\/span>timeSinceChange<\/span>,<\/span> 'hh:mm'<\/span>));<\/span><\/span><\/pre>\n

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\u00a0on Hackster.io<\/a>. Feel free to discuss on the MATLAB Maker Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

\"\"<\/div>\n

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… read more >><\/a><\/p>\n","protected":false},"author":148,"featured_media":2304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[258,256,3],"tags":[14,210,189,126,260,60,23,209,8],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/2298"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/comments?post=2298"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/2298\/revisions"}],"predecessor-version":[{"id":2314,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/2298\/revisions\/2314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media\/2304"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=2298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=2298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=2298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}