The Bhopal disaster was a chemical accident at the Union Carbide India Limited pesticide plant. In 1984, a methyl isocyanate gas leak killed more than 15, 000 people and affected over 600, 000 workers. Leaving aside the worst disaster of his kind, industries working with chemicals are always subject to leaks that could harm workers. Sometimes those leaks are formed by a specific combination of gases, so off the shelf sensors won't work. Still, a machine learning model could be trained to learn subtle relationships between all the gas readings and identify leaks with high accuracy.
This project uses MiCS-4514 multi gas sensor. The sensor is able to detect the following gases:
- Methane (CH4) (1000–25000) PPM
- Ethanol (C2H5OH) (10-500) PPM
- Hydrogen (H2) (1-1000) PPM
- Ammonia (NH3) (1-500) PPM
- Carbon Monoxide (CO) (1- 1000) PPM
- Nitrogen Dioxide (NO2) (0.1-10) PPM
The device will read the multigas sensor x times for y seconds and then calculate min, max and average. Those values will be forwarded to the Machine Learning model for inference and then a score will be obtained for all trained gases.
Important: if you are going to train the device with toxic gases please take all precautions since several minutes of data should be collected.
- Arduino BLE 33 Sense (you can use any other ARM based Arduino. No onboard sensors are used in this project)
- MiCS-4514 gas sensor
- 5V Cooler (a stronger cooler will perform better)
- Oled screen 128x32
- Buzzer
- 3d printed parts
- DC female connector and 5v Power Supply (you can also use microUSB cable)
Circuit schema will work as a reference. In detail you need to connect Buzzer to D2 and GND. Oled Screen VCC to Arduino 3.3v, GND to Arduino GND, SDA to A4, SCL to A5. Gravity Gas Sensor to Arduino 3.3v, GND, SDA to A4, SCL to A5
3d printed partsDownload the Bhopal 84 parts and 3d print.
Data acquisitionYou have to upload the acquisition script to the Arduino, place the sensor over the leak and get samples in Arduino IDE Serial Monitor.
Here you have all the information and the acquisition script download
CSV file headersThis should be the first header line in the csv file (add the commas)
timestamp CO2avg C2H5OHavg H2avg NH3avg CO2min C2H5OHmin H2min NH3min CO2max C2H5OHmax H2max NH3max
Model trainingFirst check that you have all the data for training and testing uploaded with correct labels. Then go to Impulse Design, Create Impulse. What is an Impulse? An impulse takes raw data, uses signal processing to extract features, and then uses a learning block to classify new data.
In Times Series Data, we will use 1500ms Windows Size and 0, 6 frecuency. Window increase is not important here, since samples are taken at exactly X seconds.
Processing block will be raw data with all axis checked. For classification we will use Keras with 2 output features: regular and harmful.
In Raw Data you can see all values for regular and harmful inside every windows size. Then you have to click Generate Features.
For NN Classifier we will use 60 training cycles, 0.0005 Learning Rate, Validation 20 and Autobalance dataset. It worked for me adding an extra layer Droput Rate 0.1 Click Start Training and check if you get good accuracy. In my case 86% good harmful detection and 96% regular gas detection.
If you are ok with results you can go to Model Testing and check the performance with new data. If there are lots of readings with wrong classification you should check again data acquisition procedure.
Machine Learning settingsThis is well documented in Edge Impulse but it is good to have all the information in one place.
In Impulse Creation you will see several settings that you may have to change.
- Windows size: the size of the data that will be processed. In milliseconds.
- Window increase: if a sampler is larger, use a window.
- Frequency HZ: how frequent is the data.
- Zero pad: if sample is shorter than window size, discard or maintain 0.
Models are trained to understand the relationship between independent variables and an outcome or dependent variable. The model can then be leveraged to predict the outcome of new and unseen input data, or to fill a gap in missing data. Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow. It was developed with a focus on enabling fast experimentation. Where Keras name came from? This was sort of interesting to me: “Keras (κέρας) means horn in Greek. It is a reference to a literary image from ancient Greek and Latin literature, first found in the Odyssey, where dream spirits (Oneiroi, singular Oneiros) are divided between those who deceive dreamers with false visions, who arrive to Earth through a gate of ivory, and those who announce a future that will come to pass, who arrive through a gate of horn. It's a play on the words κέρας (horn) / κραίνω (fulfill), and ἐλέφας (ivory) / ἐλεφαίρομαι (deceive).@ More about Keras https://keras.io/about/
DeploymentAfter a successful Model Testing, everything is ready for deployment. Go to Deployment. Select Arduino Library and save the zip file. Now go to Arduino IDE, Sketch, Include Library, Add Zip library and select the downloaded zip file.
Connect the Arduino to the computer with the USB cable and Upload the bhopalX.ino code. Please note that it will take long minutes to upload.
SettingsIf you want to change calibration time in minutes, use
#define CALIBRATION_TIME 3
If your OLED screen has a different I2C address
#define SCREEN_ADDRESS 0x3C
If you want to use another pin for the Buzzer
# define pinBuzzer 2
If you want to use more readingsfor min, max and average
int measuresNumber=4;
If you want to change the measure timeframe
int measuresTimeFrame=1500; // 1.5 seconds
If you want to change the percentage to identify the gases
float scoreLimit=0.8;
Using Bhopal 84After displaying Bhopal and Edge Impulse logos, the unit will start the calibration phase. During this phase do not place any substance or gas under the sensor unit. It should read normal air conditions. As soon as this step is finished you can put the leaked substance under the sensor unit and it should be detected in 1.5 seconds. Why 1.5 seconds? 4 readings will be made to obtain mix, max and average for all gases. That information will be forwarded to the model and a classification will be returned.
EnhancementsWhat about adding a siren? Just connect a relay to VCC, GND and D3. Connect the siren to NC and Signal. Then use this code:
digitalWrite(3, HIGH); // turn on
delay(10000); // Waits for 10 seconds
digitalWrite(3, LOW); // turn off
Demo
Comments