Keeping pharmaceutical products at the correct temperature is a challenge that is critical to helping medical patients maintain their health.During the entire storage and distribution process, if a part of the process is not accounted for, it could be paid at the expense of an individuals life. The pharmaceutical product distribution process involve the movement of drugs and medications from one facility to another. When these products are exposed to incorrect temperatures, the effects of decomposition can occur and diminish the effects intended from the products. This may sometimes lead to a ruined medication that can lead to toxicity and even death. So this brings us the necessity of developing a temperature monitoring and alert system. Manual monitoring of the cooling chambers is a strenuous work. So IoT and Machine learning comes handy providing an easy and efficient solution to solve this issue.
PROJECT OBJECTIVEThis project aims at developing a temperature monitoring system for a cooling chamber using a LM35 temperature sensor and Bolt WiFi module. The sensor readings are published at specified intervals to the cloud for monitoring from any place in the world. A threshold temperature is set and when the temperature exceeds this threshold, an alert mail response is automated to the user using Mailgun. This project further aims at employing machine learning algorithm which is Polynomial Regression to predict the future temperature readings, enabling the user to take an early action if the same temperature value range persists for a prolonged period of time to avoid any damage. To avoid any erratic temperature variation or sudden changes, the anomaly detection algorithm which is Z Score analysis is also incorporated and an automated SMS is delivered to the user in case of any anomaly using Twilio. The buzzer goes on in this case, alerting the workers at the facility. Since arrangement of cooling chamber is not possible, refrigerator is used instead in this project.
1. Hardware SetupThe three pins of LM35 sensor are identified as Vcc, output and ground respectively from your left to right as shown. These pins are fixed into the breadboard. Using the male to male jumpers the 3 pins of LM35 is connected to the Bolt module. The Vcc pin is connected to the 5V of the Bolt Wifi module, the ground pin of LM35 to the ground of Bolt module and the output pin to analog A0 pin of the module.
The sensor outputs the respective temperature changes in the form of voltage readings. The ambient temperature of the transistor present in the sensor changes according to the environment, which is reflected as change in current flowing through it. Many transistors and amplifiers packed in the sensor converts this change in current to change in voltage. Hence if the temperature increases, the voltage increases as well and vice versa. The sensor has an inbuilt Voltage Divider Circuit and therefore is directly connected to the A0 pin of the module. The piezoelectric buzzer used for alert system consists of two pins, one of them is the longer terminal which is positive and the other is shorter which is the negative pin.As shown in the circuit, the positive pin of the buzzer goes to the digital 0 pin of the Bolt Wifi Module and the negative pin to the ground. The Buzzer can be set ON or OFF by assigning HIGH or LOW to the digital 0 pin. Hence the circuitry is ready.
2.1 Create a product
Different types of products can be configured in bolt cloud. Here, the LM35 temperature sensor is an input device because it gathers data from the connected sensors and send it to the bolt cloud at the set interval. Since the sensor is connected to the A0 pin, GPIO option is chosen as shown.
To create a new product follow the steps as per https://docs.boltiot.com/docs/adding-a-product . Once the product is created, following screen will appear:
Note the Bolt device ID which is highlighted here. Similarly go to the API section to enable and note the API key.
Copy this into your notepad for future reference.
2.2 Prediction using Polynomial Regression
Polynomial Regression is a prediction algorithm which helps us to predict the future temperatures in case of persistence of same temperature levels for a long time thereby allowing to take early action.Using the polynomial regression, the complex data set(temperature data) is taken and a polynomial equation is derived which best represents the data set.
The polynomial equation is of the form:
y=f(x)
where f(x) is a function of sum of different powers of x. Usually time is considered as the x value. The corresponding coefficients in the polynomial equation is obtained by observation of the data trend in the algorithm and are tweaked till it matches the data set perfectly. Hence once the equation is obtained, by just substituting the time at which we want the temperature, the respective temperature value is obtained by the above equation.
Hardware Configuration:
Once the product is created, click on the configure option to first configure the hardware as shown and initialize the A0 pin with a variable 'temp'.
Code Configuration:
The following code is written to plot the temperature data and run the polynomial regression algorithm on this data to predict the future temperatures.
Once both code and hardware are configured and saved, the bolt device is linked and the configuration is deployed. The temperature readings for almost one hour is recorded.
Result:
The parameters shown in the graph are explained as follows:
Prediction Points: Tells the Visualizer how many future data points need to be predicted.
No of Polynomial Coefficients: Visualizer processes the given input-time dependent data and outputs the coefficients of the equation
which closely resembles the trend in the input data. This number tells the visualizer how many elements should be present in the function i.e the value of n.
Frame size: No. of the previous data points the visualizer will use to predict the trend.
The predict history graph will help you tune the machine learning model. The parameters can be changed so that this graph closely resembles the actual data which will ensure the predicted future temperature will be accurate.
2.3 Sending Mail alerts by manually setting the temperature threshold
A python code is written to fetch the temperature values collected by bolt and send an email if the temperature value exceeds the defined threshold. For this, Mailgun, an email automation service is used. The latest python version and boltiot python library are installed in the Ubuntu server.
Initially an account is created in mailgun ( https://www.mailgun.com/) as per the steps in https://trainings.boltiot.com/courses/429176/lectures/6656741.
Before we start coding of in python, we need to create a separate configuration file which will have the specific keys for each user/device as shown below. We will import this file in our main code and use the various attributes.
The algorithm to realize this alert system is,
1) The latest temperature value is fetched from the Bolt device.
2) The temperature value is checked if it is in the range specified between min and max values.If it is not in range, the mail is sent.
3) We wait for 10 seconds.And then the steps are repeated from the beginning by setting up an infinite while loop.
RESULT:
The temperature spike above the threshold happens when the refrigerator was opened. As shown when this happens the mail is automated to your mail account.
2.4 Anomaly detection using Z-Score Analysis and alerting by sending an SMS and ringing the buzzer
This method is used to fetch the temperature data continuously from the bolt module and report in case of sudden variation in the temperature value(anomaly). Z-Score Analysis is an anomaly detection technique which dynamically sets the lower and higher boundaries otherwise known as thresholds to enable detection of any sharp variations in temperature levels. The mathematics involved in calculating the Z-score and hence the bounds are as follows:
where r represents the frame size which is the minimum number of input values needed for Z-score analysis and C represents the multiplication factor that determines the closeness of the bounds to the input values curve as it is directly proportional to the Z-Score as shown in the equation. The frame size and the multiplication factor are determined by trial and error.
The mean of all the data points is calculated(Mn). The variation in the values is calculated as (current data value(Vi)- the mean)^2. Using this variation and the frame size, the Z Score(Zn) is calculated as per the equation. Finally the lower bound(Tn) is found by current value - respective Zscore and the upper bound(Tn) is calculated by current value + respective ZScore.
Twilio Message services is used to send the SMS when there is anomaly detected. Twilio account(https://www.twilio.com/) is created as per the steps in https://trainings.boltiot.com/courses/429176/lectures/6656680.
The buzzer connected to the digital 0 pin is also set to high if there is anomaly and acts as an additional alert at the facility.
A configuration file is set up with the specific files as shown and saved.We will import this file in our main code and use the various attributes. We will import this file in our main code and use the various attributes.
The algorithm involved in anomaly detection using Z-Score Analysis is,
1)The latest temperature value is fetched from the Bolt device.
2) The temperature values are stored in a list, that will be used for computing z-score.A minimum number of data points are required for calculation of the z- score
3) The Z-Score is computed and upper and lower threshold bounds for normal and anomalous readings by creating a separate function and sending the history data, frame size and the multiplication factor.
4) The sensor reading is checked within the range for normal readings.If it is not in range, a SMS is sent and the buzzer is set on for 50 secs as an alert.
5) We wait for 10 seconds and repeat the steps.
RESULT:
The above readings were recorded by placing the sensor in the refrigerator. As shown, when there is a sudden change or anomaly such that the temperature exceeded the respective bounds, a SMS is sent and the buzzer is set high. Slow variations in the sensor values will set the bounds also to vary dynamically hence small variations not detected. Any sudden change with respect to the previous data points will trigger the alert.
Hence, successfully a temperature monitor and alert system using IoT and machine learning is developed and implemented.
Comments