Since lot of processes in the factories and manufacturing plants are automated and becoming more and more complex, there is a need for a robust fault finding, sensing and alarming system that will enable the authorities to manage the plant efficiently and act promptly in case of an anomaly to prevent any further mishaps. In this project we will build such system based on Bolt Wi-Fi module that will notify the concerned person on Telegram in case of a gas leak. Alternatively, we can make minor modifications in the code so that it can act as pollution monitoring system.
Make the hardware setup as shown in the above images.
Step 2 : Setting Up Product in Bolt Cloud (Optional)If you want to use your system as pollution monitor, then we need to get the threshold values of our sensor by observing what would be the range of values under normal conditions. For this, we need to setup a product as shown below.
After following the above images, we need to save the product by clicking on save button. Then, we need to link our device with the product.
Now, after making all the connections, switch on the Bolt module. The device status should show online. Now click on small monitor symbol 'view this device' button. A graph of recorded values will be shown. Keep recording the values for about an hour or two. The graph should look something like this. Also, by pressing the predict button, we can predict the future values based on past values. This is machine learning feature enabled on the Bolt Cloud.
As it is seen from the graph, the values usually range from 400 to 650. We thus choose our threshold at 750 or 800 and write a python program to alert the user whenever this threshold is crossed.
Step 3 : Writing Python Program for Gas Leak SensorMaking the same hardware connections as in Step 1, we open up an Ubuntu Server Terminal as a Digital Ocean Droplet or by using VirtualBox.
After logging into the server, we create our project directory:
mkdir gas_sensor
We enter the directory by typing:
cd gas_sensor
We then make a configuration file 'conf.py' in which we will store our Bolt Device ID and API key.
sudo nano conf.py
Also, since we will be using Telegram to receive notifications, we enter Channel ID and Bot ID in this file as well. Here, we are going to use Z-score analysis so that our thresholds are changing dynamically as per the data. Thus, we also include 'frame size' and 'multiplication factor'.
bolt_api_key = "XXXX" # This is your Bolt Cloud API Key
device_id = "XXXX" # This is the device ID
telegram_chat_id = "@XXXX" # This is Channel ID. Paste after @
telegram_bot_id = "botXXXX" # This is the telegram bot ID
FRAME_SIZE = 15 # No. of previous values needed to decide Z-score
MUL_FACTOR = 10 # Decides how far threshold will be from the data
Now we will save this file by pressing 'Ctrl+x' then 'y' (yes) to confirm and then 'Enter'.
Now, we will create another file called 'gas_sensor.py'
sudo nano gas_sensor.py
Type in the python code as given in the 'Code Section'
Save the above file and then run it using following command
sudo python3 gas_sensor.py
The output when the above code is run is as follows:
The thresholds are not calculated until the 15th value of the sensor reading is received since we have set the frame size to 15. After receiving all the 15 values, upper and lower bounds are calculated. However, in case of detecting gas leak, we are interested only in the upper bound.
Now, to emulate gas leak, we use body spray. Hold the spray canister at some distance from the sensor and spray it. The alert will be sent to your Telegram Channel.
So, there you have it. This sensor project has many applications, two of which we have already discussed. This system can also be used as a breath analyzer where rather than using Telegram, we can attach a simple buzzer to one of the digital pins of the Bolt Module which will go off once the set threshold is crossed.
Please share your thoughts on this project.
Comments