An Overview of IoT Monitoring Systems
Smart production systems take action based on data. With an Arduino and sensors, we can build a monitoring system that will notify you if anything goes wrong.
Join the DZone community and get the full member experience.
Join For FreeThe Internet of Things will bring great benefits to the manufacturing industry, and the use of sensors will greatly improve the quality and speed of the production process. Just think about the possibility of smart production systems with the power to make data-informed decisions and take corrective actions to avoid damaging components they are building or even the systems themselves.
There are several scenarios where there is the need to monitor a process and send an alert every time a problem occurs during this process. Monitoring systems and sensors will help with solving these problems, and that’s exactly what I plan to talk about here. This article assumes some familiarity with Arduino hardware and modules.
For instance, we may want to monitor the alignment of some component during a manufacturing process. Moreover, let’s say the IoT system we are building must be able to detect the acceleration or deceleration of this component. These aspects have a great importance in the overall process quality. A scenario where we can apply this monitoring system might include a component that moves from one machine to another during the production process. In this context, we are interested in monitoring its position—or even better, its alignment—and the forces acting on it.
Moreover, what if we want to send an alert as soon as something happens to the production machinery or the component that the machine is working on accelerates or decelerates on its way through a manufacturing process?
In order to achieve this, the IoT monitoring system will need to be integrated with an IoT cloud platform so that we can, for example, send a short message to a user’s mobile phone.
For the sake of simplicity, let’s suppose that a sensor is attached to the component we want to monitor. This sensor detects all the movement and angle or alignment of the component during the manufacturing process. It exchanges data with an Arduino that monitors the data returned by the sensor. If this date hits a certain a threshold, the IoT board sends an alert message using Twilio and TheThings.io. The picture below shows the project overview:
Building the Project
In order to build this project, we need:
Arduino Uno (or compatible board)
MPU 6050
TheThings.io
Twillio account
The MPU 6050 is a 6-axis (Gyro + Accelerometer) sensor with a built-in motion tracking system. In more detail, this sensor has a three-axis gyroscope and three-axis accelerometer with a Digital Motion Processor that helps us to precisely control our component. If you want to have more information about this sensor you can refer to this link.
To enable the notification system based on a short message, this project uses TheThings.io. This platform provides integration features that allow us to create dashboards.
The IoT monitoring project can be divided into two parts:
The first part retrieves data from sensors.
The second part integrates the project with Twilio and TheThings.io.
Integrating the MPU6050 With the Arduino
The MPU6050 sensor is an I2C sensor that manages another pin used as interrupt. The connection schema is trivial and not covered here.
We do not want to only acquire raw data from the 3-axis gyrometer and 3-axis accelerometer. Instead, we want to use the built-in DMP module, which combines data from the two built-in sensors in order to reduce errors when performing complex calculations, so that the movement tracking information retrieved is more precise. In order to use the sensor with Arduino, we have to import the Wire and MPU 6050 libraries. You can download these libraries at this link.
Once we have imported these in our project, we can start developing the code, where the ARDUINO_INTERRUPT_PIN is 2:
#include“ I2Cdev.h”
# include“ MPU6050_6Axis_MotionApps20.h”
# include“ Wire.h”
void setup() {
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000);
device.initialize();
pinMode(ARDUINO_INTERRUPT_PIN, INPUT);
deviceStatus = device.dmpInitialize();
// Set the offset here
if (deviceStatus == 0) {
Serial.println(“Device OK...”);
device.setDMPEnabled(true);
attachInterrupt(digitalPinToInterrupt(ARDUINO_INTERRUPT_PIN), deviceDataReady,
RISING);
deviceStatusCode = device.getIntStatus();
packetSize = device.dmpGetFIFOPacketSize();
Serial.println(“Packet Size: “ + String(packetSize));
}
}
Moreover, we attach the interrupt to the PIN 2 calling the function deviceDataReady. We use this approach because the MPU6050 triggers an interrupt whenever new data is available. The deviceDataReady functions set a variable to true value:
void deviceDataReady() {
interruptReady = true;
}
Finally, we can implement the loop function:
void loop() {
// We wait for the interrupt
while (!interruptReady && fifoCount < packetSize) {
}
interruptReady = false;
deviceStatusCode = device.getIntStatus();
fifoCount = device.getFIFOCount();
if (fifoCount == 1024 || (deviceStatusCode & 0x10) ) {
device.resetFIFO();
}
else if (deviceStatusCode & 0x02) {
Serial.println(“Status 2”);
while (fifoCount < packetSize)
fifoCount = device.getFIFOCount();
device.getFIFOBytes(fifoBuffer, packetSize);
fifoCount -= packetSize;
Serial.println(“Dump data...”);
// Get quaternion data
device.dmpGetQuaternion(&q, fifoBuffer);
device.dmpGetGravity(&gravity, &q);
device.dmpGetEuler(euler, &q);
// Check the delta
device.dmpGetQuaternion(&q, fifoBuffer);
device.dmpGetAccel(&aa, fifoBuffer);
device.dmpGetGravity(&gravity, &q);
device.dmpGetLinearAccel(&aaReal, &aa, &gravity);
// check the delta
}
Here’s a step-by-step explanation of the source code:
The sketch waits until the interrupt is HIGH and the data in the FIFO queue is the right length. Remember that MPU 6050 uses a FIFO queue that holds the processed sensor data.
Once the queue is ready, we can read the data.
The data is represented using quaternions. As stated before, we want to measure the acceleration and the rotation angle. To this purpose, the library provides a set of functions to easily calculate these values. An interesting aspect is that we want to filter the gravity component from the result. For example, to calculate the rotation angle we use:
To know if we have to trigger the notification event, we have to compare the current result with the previous values (stored in another variable). If the difference is bigger than the delta, we trigger the notification event.
Using the same process, we can calculate the acceleration/deceleration of a component through an assembly line.
device.dmpGetQuaternion(&q, fifoBuffer); // Read data from the buffer
device.dmpGetGravity(&gravity, &q); // Get the gravity
device.dmpGetEuler(euler, &q); // Calculate the rotation angle (euler form)
Building the Notification System
Once, we have built the system that detects the motion and alignment we can focus on the notification part. As you may already know, Twilio is a platform that sends short messages. The first step is creating an account. Once the account is ready, you can access your dashboard and get information about your API credentials:
Your account SID and your AUTH Token is what you should be looking for because we will use them with TheThings.io. Before sending a short message, it is important that you create a virtual phone number which supports SMS features.
Here is how you can get a sender number:
You can configure your phone number here:
Note: for this example, we only used the free account to avoid paying any subscription fees. Now we have all the information needed to configure TheThings.io. The first step is creating a new product:
Next:
Once you have configured your sensor you have to activate it in order to send data. TheThings.io provides a simple sketch in order to activate your board. Remember to install the TheThings.io library before running the sketch.
The next step is creating a trigger:
A trigger monitors a variable that our IoT board sends to the TheThings.io platform. When the value of this variable goes over a certain threshold, the platform runs a script. In this context, when the deltas are over the threshold we have defined, we send a variable with a fixed value to the TheThings.io so that the trigger is fired. To implement this trigger, you can refer to this tutorial that describes step-by-step how to invoke Twilio.
Upon defining your threshold values for the delta acceleration and the delta angles, you can test the sketch. The delta is the difference between the two consecutive values. Run the sketch and then rotate the sensor. You will notice that you will receive a short message as soon as the delta retrieved from the sensor is over the threshold you have defined.
Opinions expressed by DZone contributors are their own.
Trending
-
SRE vs. DevOps
-
Reactive Programming
-
Automating the Migration From JS to TS for the ZK Framework
-
5 Key Concepts for MQTT Broker in Sparkplug Specification
Comments