{"id":44402,"date":"2021-05-30T18:45:39","date_gmt":"2021-05-30T10:45:39","guid":{"rendered":"\/blog\/?p=44402"},"modified":"2021-05-30T21:12:20","modified_gmt":"2021-05-30T13:12:20","slug":"learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release","status":"publish","type":"post","link":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/","title":{"rendered":"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release"},"content":{"rendered":"\n<p>And the topic of this article is<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.onebauer.media\/one\/empire-images\/features\/56aa2d18239eb8472a5060c7\/the-x-files-mulder-scully.jpg?format=jpg&amp;quality=80&amp;width=960&amp;height=540&amp;ratio=16-9&amp;resize=aspectfill\" alt=\"The X-Files: a complete history | Movies | Empire\"\/><\/figure>\n\n\n\n<p><strong>Anomalies.<\/strong> Or specifically anomaly detection for predictive maintenance. We\u2019re going to be using data from Wio Terminal built-in accelerometer, perform neural network model inference and anomaly detection on-device and then send data to <a href=\"https:\/\/blynk.io\/blog\/meet-the-new-blynk-platform\" target=\"_blank\" aria-label=\"undefined (opens in a new tab)\" rel=\"noreferrer noopener\">new version of Blynk IoT platform<\/a> with plethora of new features, which was launched these few days and fully supports Wio Terminal.<\/p>\n\n\n\n<p>For full tutorial and video demonstration, have a look at the accompanying video:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Predictive maintenance with Arduino and Edge Impulse: Why and How to?\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/gXs-h3eeT1U?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>That\u2019s WHAT, now for HOW part, let\u2019s start with an example that might be more familiar.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Anomaly detection and predictive maintenance in a nutshell<\/h3>\n\n\n\n<p>If you train a simple image recognition model to recognize let\u2019s say 5 different classes of animals (tiger, elephant, bear, snake and giraffe) and then give it an image of a person, it will make a prediction to the best of it\u2019s abilities and possibly say it\u2019s an elephant. Cue the laughter of ordinary folks, who do not really understand much about internal works of this particular model and computer vision in general.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"620\" height=\"413\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/5b8mxj.jpg\" alt=\"\" class=\"wp-image-44601\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/5b8mxj.jpg 620w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/5b8mxj-300x200.jpg 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/figure>\n\n\n\n<p> Of course, the model didn\u2019t do anything wrong &#8211; it processed the image, calculated the features present and then output classification result based on these features. Although if we plot the features from classes and cluster them, we would see that ideally the human image features are far from any class cluster and thus represent an \u201coutlier\u201d. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/datascience.foundation\/img\/pdf_images\/knowing_all_about_outliers_in_machine_learning_sample_points_in_green_are_near_to_each_other.jpg\" alt=\"Knowing all about Outliers in Machine Learning\"\/><\/figure>\n\n\n\n<p>Which of course could be just a very weird image of one of the animals, but in most of cases it\u2019s much more likely that it\u2019s an object model wasn\u2019t trained to recognize.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/encrypted-tbn0.gstatic.com\/images?q=tbn:ANd9GcTAr2q0zDcoqNtIPxeKbZvjYc2ZGRfuFmhvclffqOlBzC4HPKcLTTNSQGixg3FW_7t4t-Y&amp;usqp=CAU\" alt=\"3 Weird Dog Facts That You May Have Never Known | Internet Vibes\"\/><\/figure><\/div>\n\n\n\n<p>For computer vision and speech recognition tasks we often have \u201cbackground\u201d class to deal with this problem, which basically represents anything that is not the classes of interest. In some situations, we really just want our model to be able to interpret all the data as \u201cnormal\u201d and \u201cabnormal\u201d. It doesn\u2019t matter what are the exact characteristics of \u201cabnormal\u201d &#8211; they can be wildly different, the important thing is, if \u201cabnormal\u201d class is detected, some measures need to be implemented. What I described now is the premise behind using Machine Learning for predictive maintenance. We monitor the state of device, be it air conditioner, water pump or other machinery with sensors and based on profile of known \u201cnormal\u201d operation, trying to detect when something goes SLIGHTLY wrong, before it goes SERIOUSLY wrong.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"298\" height=\"169\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image.jpeg\" alt=\"That's weird, It totally worked with toothpicks - Bridge Collapse | Meme  Generator\" class=\"wp-image-44412\"\/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Collecting the data and training the model<\/h3>\n\n\n\n<p>For this project I installed Wio Terminal on a water pump on our office\u2019s outside patio, which has some plants and fish.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1030\" height=\"579\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007-1030x579.png\" alt=\"\" class=\"wp-image-44602\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007-1030x579.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007-300x169.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007-768x432.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007-1536x864.png 1536w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007-1024x576.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_04_2007.png 1920w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p> Then I collected two categories of samples &#8211; idle and normal operation and trained a simple model to recognize these two based on Spectral Features processing block output. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"480\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image-1-1030x480.png\" alt=\"\" class=\"wp-image-44603\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-1-1030x480.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-1-300x140.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-1-768x358.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-1-1024x477.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-1.png 1499w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"469\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image-2-1030x469.png\" alt=\"\" class=\"wp-image-44604\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-2-1030x469.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-2-300x137.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-2-768x350.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-2-1024x466.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-2.png 1478w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p>For exact parameters of processing and learning blocks, you can have a look at the <a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/studio.edgeimpulse.com\/public\/31205\/latest\" target=\"_blank\" rel=\"noreferrer noopener\">public version of the project<\/a> I shared. The only significant tweak I made was changing filter from low to high, which made the features of different classes more prominent. Distinguishing between idle and normal pump operation of course proven to be really easy. More challenging task was malfunction detection. To simulate malfunction I would take the water pump out of the tank &#8211; this basically lead to sound and vibration levels decreasing. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"579\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725-1030x579.png\" alt=\"\" class=\"wp-image-44605\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725-1030x579.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725-300x169.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725-768x432.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725-1536x864.png 1536w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725-1024x576.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/full-Time-0_19_2725.png 1920w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p>Looking at the malfunction sample, at the feature explorer on the accX RMS, accY RMS and accZ RMS axes, we see that is is halfway between idle and normal operation samples. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"608\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image-3-1030x608.png\" alt=\"\" class=\"wp-image-44606\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-3-1030x608.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-3-300x177.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-3-768x453.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-3-1536x906.png 1536w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-3-1024x604.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-3.png 1556w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p>We can use this to our advantage by training a new (second) network that creates clusters around data that we have seen before, and compares incoming data against these clusters. If the distance from a cluster is too large the sample is flagged the sample as an anomaly.<\/p>\n\n\n\n<p>After trial and error I found that very low cluster count and distance threshold of 0.5 works the best for anomaly detection, but this is very case-specific and depends on your data. One thing that helped to increase the accuracy was fixing Wio Terminal on the water pump firmly with glue &#8211; for actual device you can use screws. Before fixing firmly, Wio Terminal was wobbling randomly, which was introducing too much noise into normal operation samples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Deployment and testing<\/h3>\n\n\n\n<p>After the model is trained and tested using Live classification mode it is time to deploy it back to the device. We compile and download the Arduino library, extract it to Arduino libraries folder and then modify nano33_ble_sense_accelerometer sketch to match the accelerometer we have in Wio Terminal. For simple test we use LCD screen that lights red if anomaly is detected. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define ANOMALY_THRESHOLD 0.5\n\n\/* Includes ---------------------------------------------------------------- *\/\n#include &lt;wio_anomaly_detection_inference.h&gt;\n#include\"LIS3DHTR.h\"\n#include\"TFT_eSPI.h\"\n\nTFT_eSPI tft;\nLIS3DHTR&lt;TwoWire&gt; lis;\n\n\/* Constant defines -------------------------------------------------------- *\/\n#define CONVERT_G_TO_MS2    9.80665f\n\n\/* Private variables ------------------------------------------------------- *\/\nstatic bool debug_nn = false; \/\/ Set this to true to see e.g. features generated from the raw signal\n\n\/**\n* @brief      Arduino setup function\n*\/\nvoid setup()\n{\n    \/\/ put your setup code here, to run once:\n    Serial.begin(115200);\n    \/\/while (!Serial) {delay(10);}\n    \n    Serial.println(\"Edge Impulse Inferencing Demo\");\n    \n    tft.begin();\n    tft.setRotation(3);\n    \n    lis.begin(Wire1);\n \n    if (!lis.available()) {\n    Serial.println(\"Failed to initialize IMU!\");\n    while (1);\n    }\n    else {\n        ei_printf(\"IMU initialized\\r\\n\");\n    }\n    lis.setOutputDataRate(LIS3DHTR_DATARATE_100HZ); \/\/ Setting output data rage to 25Hz, can be set up tp 5kHz \n    lis.setFullScaleRange(LIS3DHTR_RANGE_16G); \/\/ Setting scale range to 2g, select from 2,4,8,16g\n   \n\n    if (EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME != 3) {\n        ei_printf(\"ERR: EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME should be equal to 3 (the 3 sensor axes)\\n\");\n        return;\n    }\n}\n\n\/**\n* @brief      Printf function uses vsnprintf and output using Arduino Serial\n*\n* @param&#91;in]  format     Variable argument list\n*\/\nvoid ei_printf(const char *format, ...) {\n   static char print_buf&#91;1024] = { 0 };\n\n   va_list args;\n   va_start(args, format);\n   int r = vsnprintf(print_buf, sizeof(print_buf), format, args);\n   va_end(args);\n\n   if (r &gt; 0) {\n       Serial.write(print_buf);\n   }\n}\n\n\/**\n* @brief      Get data and run inferencing\n*\n* @param&#91;in]  debug  Get debug info if true\n*\/\nvoid loop()\n{\n\n    ei_printf(\"Sampling...\\n\");\n\n    \/\/ Allocate a buffer here for the values we'll read from the IMU\n    float buffer&#91;EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };\n\n    for (size_t ix = 0; ix &lt; EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix += 3) {\n        \/\/ Determine the next tick (and then sleep later)\n        uint64_t next_tick = micros() + (EI_CLASSIFIER_INTERVAL_MS * 1000);\n\n        lis.getAcceleration(&amp;buffer&#91;ix], &amp;buffer&#91;ix+1], &amp;buffer&#91;ix + 2]);\n        buffer&#91;ix + 0] *= CONVERT_G_TO_MS2;\n        buffer&#91;ix + 1] *= CONVERT_G_TO_MS2;\n        buffer&#91;ix + 2] *= CONVERT_G_TO_MS2;\n\n        delayMicroseconds(next_tick - micros());\n    }\n\n    \/\/ Turn the raw buffer in a signal which we can the classify\n    signal_t signal;\n    int err = numpy::signal_from_buffer(buffer, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &amp;signal);\n    if (err != 0) {\n        ei_printf(\"Failed to create signal from buffer (%d)\\n\", err);\n        return;\n    }\n\n    \/\/ Run the classifier\n    ei_impulse_result_t result = { 0 };\n\n    err = run_classifier(&amp;signal, &amp;result, debug_nn);\n    if (err != EI_IMPULSE_OK) {\n        ei_printf(\"ERR: Failed to run classifier (%d)\\n\", err);\n        return;\n    }\n\n    \/\/ print the predictions\n    ei_printf(\"Predictions \");\n    ei_printf(\"(DSP: %d ms., Classification: %d ms., Anomaly: %d ms.)\",\n        result.timing.dsp, result.timing.classification, result.timing.anomaly);\n    ei_printf(\": \\n\");\n    for (size_t ix = 0; ix &lt; EI_CLASSIFIER_LABEL_COUNT; ix++) {\n        ei_printf(\"    %s: %.5f\\n\", result.classification&#91;ix].label, result.classification&#91;ix].value);\n    }\n#if EI_CLASSIFIER_HAS_ANOMALY == 1\n    ei_printf(\"    anomaly score: %.3f\\n\", result.anomaly);\n\n  if (result.anomaly &gt; ANOMALY_THRESHOLD)\n  {       \n    tft.fillScreen(TFT_RED);\n    tft.setFreeFont(&amp;FreeSansBoldOblique12pt7b);\n    tft.drawString(\"Anomaly detected\", 20, 80);\n    delay(1000);\n    tft.fillScreen(TFT_WHITE);\n  }\n    \n#endif\n}\n\n#if !defined(EI_CLASSIFIER_SENSOR) || EI_CLASSIFIER_SENSOR != EI_CLASSIFIER_SENSOR_ACCELEROMETER\n#error \"Invalid model for current sensor\"\n#endif<\/code><\/pre>\n\n\n\n<p>Of course, for real application, this sort of notification is not likely going to work, because there is no person to constantly watch over it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Utilizing new release of Blynk IoT platform<\/h3>\n\n\n\n<p>To make this demo useful, we\u2019re going to use brand new release of Blynk IoT platform. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"693\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/b641e2030c1c47fbc7161c98a7e5d998-1030x693.jpg\" alt=\"\" class=\"wp-image-44607\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/b641e2030c1c47fbc7161c98a7e5d998-1030x693.jpg 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/b641e2030c1c47fbc7161c98a7e5d998-300x202.jpg 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/b641e2030c1c47fbc7161c98a7e5d998-768x517.jpg 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/b641e2030c1c47fbc7161c98a7e5d998-1024x689.jpg 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/b641e2030c1c47fbc7161c98a7e5d998.jpg 1070w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p>The new version includes such features as a web dashboard to monitor devices, manage who access the data, a WI-FI manager for easy setup procedure, new approach to device model creation and others. By the time this video is published all these features should be available for general public. Go to blynk.cloud, register an account or create a new one. Then create a new template &#8211; templates are digital models of the device which can be inherited by multiple devices with similar functionality. The power of templates is an instant update of device data model no matter the size of your devices fleet.<\/p>\n\n\n\n<p>Choose Arduino Uno as hardware and Wi-Fi as connection type. Then populate Datastreams and Dashboard tabs as in the following screenshots and save the changes. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"369\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image-4-1030x369.png\" alt=\"\" class=\"wp-image-44608\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-4-1030x369.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-4-300x108.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-4-768x275.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-4-1536x551.png 1536w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-4-1024x367.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-4.png 1787w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"831\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image-5-1030x831.png\" alt=\"\" class=\"wp-image-44609\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-5-1030x831.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-5-300x242.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-5-768x620.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-5-1024x826.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-5.png 1066w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p>We\u2019re not using Metadata or Events tabs in this project. The main purpose of device template main components:<br><br>\u2022 Metadata &#8211; additional data about the device you can configure.<br>\u2022 Datastreams &#8211; an entity to define the data that flows in and out from device. Overall, it&#8217;s very similar to Virtual Pins (which can be used too).<br>\u2022 Events &#8211; a list of important alerts and notifications<br>\u2022 Web Dashboard &#8211; A set of Widgets in the Web app<br>\u2022 Mobile Dashboard&nbsp;&#8211; A set of Widgets in the Mobile app<\/p>\n\n\n\n<p>Create a new device in My Devices tab &#8211; choose the template you have created and give it a unique name.<\/p>\n\n\n\n<p>Now the web interface is ready to receive the data from our device. Download <a href=\"https:\/\/github.com\/Seeed-Studio\/Seeed_Arduino_Sketchbook\/tree\/master\/examples\/WioTerminal_TinyML_5_Anomaly_Detection\" target=\"_blank\" aria-label=\"undefined (opens in a new tab)\" rel=\"noreferrer noopener\">the example sketch<\/a> from Seeed Wio Terminal example sketches repository &#8211; besides main sketch file it also contains helper files, where Wi-Fi manager code is located. In the main sketch file, the data collection\/data processing\/inference \u00a0code we used for testing with LCD screen was moved to run_inference() function. \u00a0The class ID of the class with highest confidence (if the confidence is above set threshold) is saved inside best_result global variable and together with light and sound sensors data is being sent to Blynk server at periodic intervals. Remember to change BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME to the ones from you Device template.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"670\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2021\/05\/image-6-1030x670.png\" alt=\"\" class=\"wp-image-44610\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-6-1030x670.png 1030w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-6-300x195.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-6-768x500.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-6-1024x666.png 1024w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/image-6.png 1356w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p> After you upload the code to Wio Terminal, it will create a hot spot, which you can connect to with your phone. Upon connection you will be automatically re-directed to a simple configuration page, where you need to enter your WiFi credentials, your API token (you can find it by clicking on your device in My Devices tab and then going to Device Info) and then click on Connect. Then Wio Terminal will connect to WiFi network and Blynk cloud server and start sending the data. You can press on device in My Devices tab and see the pretty graphs and status message. You can see the test results towards the end of the video.<\/p>\n\n\n\n<p>Obviously, same approach can be applied to detecting irregularities in other machinery operation &#8211; we can use accelerometer for pretty much everything with moving parts, since these produce vibration we can measure. If device emits audible sounds, we can use microphone too. A combination of sensors might even work better. Are there any other good applications where predictive maintenance can be used? Write your ideas in the comments! Hope this article and video were useful for you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>And the topic of this article is Anomalies. Or specifically anomaly detection for predictive maintenance.<\/p>\n","protected":false},"author":3505,"featured_media":44613,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","_price":"","_stock":"","_tribe_ticket_header":"","_tribe_default_ticket_provider":"","_tribe_ticket_capacity":"0","_ticket_start_date":"","_ticket_end_date":"","_tribe_ticket_show_description":"","_tribe_ticket_show_not_going":false,"_tribe_ticket_use_global_stock":"","_tribe_ticket_global_stock_level":"","_global_stock_mode":"","_global_stock_cap":"","_tribe_rsvp_for_event":"","_tribe_ticket_going_count":"","_tribe_ticket_not_going_count":"","_tribe_tickets_list":"[]","_tribe_ticket_has_attendee_info_fields":false,"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[1355,3745,1608,3003,3678],"class_list":["post-44402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","tag-artificial-intelligence","tag-edge-machine-learning","tag-machine-learning","tag-wio-terminal","tag-wio-terminal-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release - Latest News from Seeed Studio<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release - Latest News from Seeed Studio\" \/>\n<meta property=\"og:description\" content=\"And the topic of this article is Anomalies. Or specifically anomaly detection for predictive maintenance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/\" \/>\n<meta property=\"og:site_name\" content=\"Latest News from Seeed Studio\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-30T10:45:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-30T13:12:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dmitry Maslov\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dmitry Maslov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/\",\"name\":\"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release - Latest News from Seeed Studio\",\"isPartOf\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg\",\"datePublished\":\"2021-05-30T10:45:39+00:00\",\"dateModified\":\"2021-05-30T13:12:20+00:00\",\"author\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/be44021cef50367de429a4d5f613ed2f\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#primaryimage\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg\",\"contentUrl\":\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg\",\"width\":1280,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.seeedstudio.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#website\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/\",\"name\":\"Latest News from Seeed Studio\",\"description\":\"Emerging IoT, AI and Autonomous Applications on the Edge\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.seeedstudio.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/be44021cef50367de429a4d5f613ed2f\",\"name\":\"Dmitry Maslov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b60714970fdc7dfa4a5d9915477bdd24?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b60714970fdc7dfa4a5d9915477bdd24?s=96&r=g\",\"caption\":\"Dmitry Maslov\"},\"url\":\"https:\/\/www.seeedstudio.com\/blog\/author\/dmitry-maslov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release - Latest News from Seeed Studio","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/","og_locale":"en_US","og_type":"article","og_title":"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release - Latest News from Seeed Studio","og_description":"And the topic of this article is Anomalies. Or specifically anomaly detection for predictive maintenance.","og_url":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/","og_site_name":"Latest News from Seeed Studio","article_published_time":"2021-05-30T10:45:39+00:00","article_modified_time":"2021-05-30T13:12:20+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg","type":"image\/jpeg"}],"author":"Dmitry Maslov","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dmitry Maslov","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/","url":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/","name":"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release - Latest News from Seeed Studio","isPartOf":{"@id":"https:\/\/www.seeedstudio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#primaryimage"},"image":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#primaryimage"},"thumbnailUrl":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg","datePublished":"2021-05-30T10:45:39+00:00","dateModified":"2021-05-30T13:12:20+00:00","author":{"@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/be44021cef50367de429a4d5f613ed2f"},"breadcrumb":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#primaryimage","url":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg","contentUrl":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg","width":1280,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/www.seeedstudio.com\/blog\/2021\/05\/30\/learn-tinyml-using-wio-terminal-and-arduino-ide-5-anomaly-detection-for-predictive-maintenance-with-new-blynk-iot-platform-release\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.seeedstudio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Learn TinyML using Wio Terminal and Arduino IDE #5 Anomaly detection for Predictive maintenance with new Blynk IoT Platform release"}]},{"@type":"WebSite","@id":"https:\/\/www.seeedstudio.com\/blog\/#website","url":"https:\/\/www.seeedstudio.com\/blog\/","name":"Latest News from Seeed Studio","description":"Emerging IoT, AI and Autonomous Applications on the Edge","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.seeedstudio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/be44021cef50367de429a4d5f613ed2f","name":"Dmitry Maslov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b60714970fdc7dfa4a5d9915477bdd24?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b60714970fdc7dfa4a5d9915477bdd24?s=96&r=g","caption":"Dmitry Maslov"},"url":"https:\/\/www.seeedstudio.com\/blog\/author\/dmitry-maslov\/"}]}},"modified_by":"Dmitry Maslov","views":4761,"featured_image_urls":{"full":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg",1280,720,false],"thumbnail":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-80x80.jpg",80,80,true],"medium":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-768x432.jpg",640,360,true],"large":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-1030x579.jpg",640,360,true],"1536x1536":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg",1280,720,false],"2048x2048":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg",1280,720,false],"visody_icon":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg",32,18,false],"magazine-7-slider-full":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1.jpg",1280,720,false],"magazine-7-slider-center":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-936x720.jpg",936,720,true],"magazine-7-featured":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-1024x576.jpg",1024,576,true],"magazine-7-medium":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-720x380.jpg",720,380,true],"magazine-7-medium-square":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2021\/05\/Presentation1-675x450.jpg",675,450,true]},"author_info":{"display_name":"Dmitry Maslov","author_link":"https:\/\/www.seeedstudio.com\/blog\/author\/dmitry-maslov\/"},"category_info":"<a href=\"https:\/\/www.seeedstudio.com\/blog\/category\/news\/\" rel=\"category tag\">News<\/a>","tag_info":"News","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/44402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/users\/3505"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/comments?post=44402"}],"version-history":[{"count":6,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/44402\/revisions"}],"predecessor-version":[{"id":44618,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/44402\/revisions\/44618"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/media\/44613"}],"wp:attachment":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/media?parent=44402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/categories?post=44402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/tags?post=44402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}