The government declared the following rules for manufacturing tablets/medicine in all pharmaceutical companies:
- The manufacturer is allowed to maintain the temperature of the tablets between, -40 and -30 degrees Celsius, the temperature of the tablets should never remain between -33 and -30 degrees for longer than 20 minutes at a time.
- Also, the manufacturer should maintain a log of when the cooling chamber for the production of the tablets is opened.
- These rules should be implemented within a month of their declaration. Failing to comply would lead to cancellation of the pharmaceutical production permit.
- The government declared these rules to ensure that the medicine produced at all pharmaceutical companies was good enough to be used by the general public.
- This project is related to solving the problem that is faced by many pharmaceutical companies who don’t have automated alert system that alert the people responsible for management of cooling the chamber at a certain range of temperature.
- Because of temperature going below the lower threshold or going above the upper threshold value will cause the damage to tablets or medicine and that will cause a huge lose to the pharmaceutical companies.
- Here, the dynamic thresholds are calculated for anomaly detection using Z-score analysis wherein if the temperature increases or decreases suddenly, Email alerts are sent.
- The pharmaceutical companies use a cooling chamber which is similar to a refrigerator to keep the tablets and maintain the temperature in the required limits.
- However, since we don’t have a cooling chamber which can maintain a temperature in the range, of -40 to -30 degrees Celsius, you can instead use a regular refrigerator at your home for this project.
Let us begin with the hardware connections. Make sure that you power ON the Bolt module only after all connections are done.
Follow the steps below to set up your hardware:
CONNECTING THE TEMPERATURE SENSOR
Take LM35 temperature sensor and connect its three leads via male/female jumper wires to the respective pins of the Bolt module. Keeping the flat side of the sensor towards you:
a. Connect the leftmost lead which is the supply terminal to the 5V pin of the Bolt module.
b. Connect the middle lead which is the analog output terminal to the Analog Input pin (A0) of Bolt module.
c. Connect the rightmost lead which is the ground terminal to the GND pin of the Bolt module.
That’s all for the hardware assembly. The complete system is show below:
Hardware assembly
4. CONFIGURING OF SOFTWARENow, we move on to the software configurations. The code is written using Python3 on Ubuntu which uses digital ocean droplet. Follow the steps below to complete the software setup:
Step 1: Installing Ubuntu VPS (Optional)If you don’t have Ubuntu OS on the host computer, an Ubuntu VPS can be set up either creating a Digital Ocean Droplet or by using VMware or Virtual Box. After setting up Ubuntu, login, update the packages and install Python3 as well as the ‘bolt Iot’ Python library.
Step 2: Creating Mailgun accountWhile creating the account make sure to choose the programming language as Python and enter the Email Id on which you wish t o receive the Email alerts. Post account creation, get API credentials. Copy and save the Sandbox URL and API key. As both of them will be required in configuration file which will be created later.
Step 3: Locating the API Key and Device IDThe Bolt Cloud API key can be found by clicking the 'API' tab on the dashboard of your Bolt Cloud account and the Bolt Device ID can be found by clicking on the ‘Devices’ tab as shown below:
Bolt cloud API Key
Bolt Device ID
The API key and the device ID can be copied directly by clicking on the copy button as shown above.
Step 4: Defining Static ThresholdsWe have seen that, the general temperature range for proper functioning of cooling chamber is -40°Cto -30°C. The temperature sensor that we are using can measure temperatures within the range -55°C to 150°C and gives an output value in analog form which is then received by the A0 pin of the Bolt module and converted to digital form by an inbuilt ADC (Analog to Digital Converter). The formula to convert this digital sensor value denoted by ‘r’ to temperature in °C denoted by ‘T’ is given by:
T = r/10.24An equivalent of this formula is ‘r = T * 10.24’ which can be used to calculate the static thresholds in terms of digital sensor value:If the temperature measured crosses the thresholds, Email alert is sent to the Email Id registered on mail gun.
Step 5: Defining Constant Parameters for Anomaly DetectionIn the procedure of anomaly detection using Z – score analysis, the concept of dynamic thresholds is brought into the picture. For each new sensor value that is collected, a new Z – score is calculated based on few previously collected data points. This Z – score is then used for the calculation of the higher and lower dynamic thresholds. The current sensor value is then compared with these thresholds and if it is found to lie outside these thresholds, an anomaly is detected due to which, Email alert is sent to the Email Id registered on mailgun
If the temperature of the cooling chamber increases or decreases suddenly, the dynamic thresholds are not able to change fast enough causing the current sensor value to lie outside the thresholds.
The formulas to be used for performing Z – score analysis are:
Where,
r – Frame size (number of previous data points)
C – Multiplication factor
Mn – Mean of the previous data points
Zn – Z – score
Vi – Current sensor value
Tn – Dynamic threshold
The constant parameters ‘r’ and ‘C’ need to be tuned as per system requirements. Here, we will be defining the frame size (r) and the multiplication factor (C) as follows:
r = 10
C = 1.
Step 6:Create a product on the Bolt Cloud, to monitor the data from the LM35, and link it to your Bolt.
In the above image we are creating a new product named Project Capstone. Then we link this product to Bolt Wi-Fi module.
Step7: Write the product code, required to run the polynomial regression algorithm on the data sent by the Bolt.
setChartLibrary('google-chart');
setChartTitle('Polynomial Regression');
setChartType('predictionGraph');
setAxisName('time_stamp', 'temp');
mul(0.0977);
plotChart('time_stamp', 'temp');
Step 8: Keep the temperature monitoring circuit inside your fridge with the door of the fridge closed, and let the system record the temperature readings for about 2 hours.
After applying Polynomial Regression:
It’s a good practice to store all your credentials in a separate file instead of including them in your code. So, create a configuration file with ‘.py’ extension and open up nano editor to assign each of your credentials to a variable so that they can be accessed later by importing this file into your main program. Save the file after typing in the credentials.
Here, the file is named ‘email_conf.py’ and the contents of the file must be as follows:
Create a new Python file, which will contain the main code, within the same directory as the configuration file and open the nano editor for this file. Here, the file is named ‘temp_email.py’. Type in the code attached and save the file.
Sending Email alert when temperature crosses the threshold.
READINGS:
Modify the python code, to do Z-score analysis and print the line “Someone has opened the refrigerator door” when an anomaly is detected. For writing the final code for Z-score analysis, create another file and name it as: Project_capstone.
Readings:
Sending email alert for the temperature of the refrigerator.
Tune the Z-score analysis code, such that, it detects an anomaly when someone opens the door of the fridge.
- There are Temperature Sensor applications in many industries including medical, motorsport, HVAC, agriculture, industrial, aerospace and automotive.
- Some of the specific temperature sensor applications which we have come across :
- Motors– There are many different aspects of motors and most of these require temperature measurement to ensure the motor itself does not overheat.
- Surface plates – Ring terminal temperature sensors are often used on surface plates as they can be mounted onto a flat surface and measure temperature effectively.
- Home appliances – Kettles, toasters, washing machines, dishwashers and coffee machines will all contain temperature sensors.
- Computers– Within computers there are temperature sensors to ensure the system does not overheat.
- Industrial equipment – Temperature sensors used within these applications will need to be robust as the environment can be very demanding.
- Warming Electrical Radiators – NTC thermistors are used to control the heat on electric radiators.
- Exhaust Gas Monitoring on Motorsport Vehicles – Motorsport temperature sensors need to be highly reliable and durable to ensure performance is not compromised in this harsh environment.
- Food Production; 3D printed chocolates – Temperature sensors are used to monitor the temperature of the melted chocolate for 3D printing.
The Temperature Monitoring and Alerting System that we have created can thus be used to maintain the temperature of cooling which would avoid the damage to tablets or medicines which can cause a huge lose to the pharmaceutical company.
Comments