Introduction:- My project is to make a temperature prediction model and an anomaly detection system. Here is a video of the project in action.
Objective 1:- I want to maintain a temperature threshold between 0.35 and 0.70 degree Celsius in the chamber and hence want to get updated as soon as the temperature values get beyond the threshold so that I can take early actions.
Objective 2:- Another objective is to check whether the temperature for the chamber should never remain between 0.45 and 0.55 degree Celsius range for longer than 20 minutes at a time. It will be checked through the predictor graph made of polynomial regression ML algorithm predicting the next temperature ranges. I will be able to take early action, whenever the graph shows after prediction that the temperature will be maintained within 0.45 and 0.55 degree Celsius range for longer than 20 minutes.
Objective 3:- My last objective is to keep a log of how many times the chamber was opened. It is found through anomaly detection system which uses Z-score analysis and sends the message that “Someone has opened the chamber” when an anomaly is detected.
* I used my fridge instead of the chamber for the project.
Information flow :- Temperature from Surrounding ->LM35 Sensor -> Bolt WIFi Module -> Bolt Cloud via APIsHardware Setup :-
Step 1: Hold the sensor in a manner such that you can read LM35 written on it. In this position, identify the pins of the sensor as VCC, Output and Gnd from your left to right.
Step 2: Using male to female wire connect the 3 pins of the LM35 to the Bolt Wifi Module as follows:
- VCC pin of the LM35 connects to 5v of the Bolt Wifi module.
- Output pin of the LM35 connects to A0 (Analog input pin) of the Bolt Wifi module.
- Gnd pin of the LM35 connects to the Gnd.
Power on the Bolt WiFi Module using USB adapter and connect the Bolt device to a Wi-Fi Network. That's it we are done with hardware connections.
Getting the Bolt API Key and Device IDandWriting the GPIO Control Command
Step 1: Login to cloud.boltiot.com and note the ID of your Bolt WiFi Module. Now click on the API Tab and under the section for Generate Key, click on Enable.
Your API key will may look something like this: f1f918e9-d9c2-4e5b-aed0-b7cb743f74cf.
Step 2: Since LM35 sensor is a analog input device, we will need to get a analogRead command that can be sent to Bolt over the Internet to switch on the LED.
In Bolt Cloud go to Docs Tab -> API Documentation -> GPIO Commands API -> Read Analog InputConfiguring and Deploying the product
Now make a new product and cofigure it as follows..
Now save it and link this product with your device and you are ready to go.
Collect data for about 2-3 hrs to get the proper prediction of the temperature.Data collection and prediction of future temperature values:-
For collecting the data I put the hardware modules in the fridge
I got the following visualisation:-
It's clearly showing that for next 20 mins and more I will get a temperature range between 0.45-0.50 Degree Celsius which is not desirable and hence I can take actions beforehand.
Note:- One must have their own cloud servers to perform tasks of next section. I used Digital Ocean to connect the Bolt Module to my own cloudCode for Threshold checking and Anomaly Detection :-
The above link contains a python code which u need to run on the server for detecting anomaly and alerting for change beyond the thresholds.
Working of the code:-1. For alerting when temperature beyond threshold values :-
Minimum limit & Maximum limit is set. The value given is Sensor value.
Temperature in degree celsius is 0.0977*Sensor Value
If (sensor value < Minimum limit) or(sensor value > Maximum limit)
Alert is given via email that "The current tempertaure is beyond the threshold"
2. For alerting when an anomaly is detected :-
- Function def compute_bounds is used to check whether enough data has been accumulated to calculate the Z-score, we calculate the Z score (Zn) for the data and use it to calculate the upper and lower threshold bounds required to check if a new data point is normal or anomalous.
- The next code is used to initialize the Bolt and SMS variables, which we will use to collect data and send SMS alerts. Here we also initialize an empty list with the name 'history_data' which we will use to store older data, so that we can calculate the Z-score.
- If anomaly detected we will be updated via SMS that ""Someone opened the chamber""
That's it we are done with all our objectives.
Furthermore, you can use your social media account to notify your potential emloyees or colleagues when the temperature sensor connected to Bolt crosses a threshold and can ask for their help as soon as possible. For this project I will use my Twitter account to send the tweet regarding the matter.
For this I need to generate API from my twitter developers account. Visit following link for more information:-
Generate keys from Keys and tokens portion and you will get two Consumer Keys and two Access Token Keys, then edit the Permissions option to read and write.
We wii use Tweepy which is an easy to use Python library for accessing the Twitter API. Twitter provides APIs to access various functionality related to your Twitter account. These API's work over HTTP protocol, i.e. you can make GET, POST requests to access your Twitter account.
Coding with Tweepy to Post alerts
The above link contains a python code which u need to run on the server for alerting via tweet for change beyond the thresholds.
Go ahead ! Build the project... Cheers !!!