The AI_sense_by_Hazel_n_Igor repository is a workspace for portfolio project of Hazel Wat and Igor Isaev. The work on the project was done during the classes of Data Science Retreat in 2021 (Batch 28).
This repository is forked on https://github.com/igivis7/ and https://github.com/hahahazel to reflect the work of all contributors.
The online version of the app is created with Streamlit and can be found here:
https://share.streamlit.io/igivis7/ai_sense_by_hazel_n_igor_4streamlit_online/main/streamlit_AIsense_by_Hazel_n_Igor.py
- About the project
- Live demo
- How to make it running
- Assembling and Connecting to computer
- Features of the project
This project was dedicated to apply our newly gained knowledge of data science on a real-world task.
As the object of study, we decided to take
Grove multichannel Gas Sensor V2 (GGSv2) sensor and implement Machine Learning to solve an odor recognition task.
During the project we have practiced building of Data Science (DS) project from scratch, mastered our Machine Learning (ML) skills and learned ways to overcome problems.
The GGSv2 sensor consists of 4 measurement heads for measuring Nitrogen dioxide (NO2), Carbon monoxide (CO), Ethyl alcohol (C2H5OH) and Volatile organic compounds (VOCs). Each head is an metal oxide semiconductor gas detector made to measure a certain gas molecule. The combination of the 4 readings allows to detect and distinguish different odors. The GGSv2 sensor can be used together with Arduino boards, WIO terminal, Raspberry Pi or any other device that is able to work with I2C communication protocol.
To make classification of odors a fully connected neural network was implemented.
The live demo (with pre-collected samples), code description, project features, hardware list and possible upgrades are listed below.
There are two options to see run live demo:
- Online version via Streamlit app. There is possible to see GUI and run with pre-trained model and simulated samples. It does not work with hardware (GGSv2).
- go to the app page
- press
Get random premeasured test data
button. - press
Predicting
button to run prediction using existing model.
- Local Streamlit app demo.
- make sure you have installed all required packages in your environment (see the next section)
- go to the folder
cd ./soft/streamlit_app/
- run
streamlit run streamlit_app.py
Here is an instruction to make your copy of the project running.
The procedure is described for a Linux-based OS. It was also was checked with MacOS, but not with Windows.
There a few steps to create a device that is able to detect and distinguish odors:
- Get an Arduino, Gas Sensor, HDT Sensor, and supplementary parts to combine it.
- Assemble the device according to the instructions in the section Assembling and Connecting to computer. And connect to a computer.
- Install Arduino IDE.
- Upload firmaware to arduino:
- open file
GGSv2_n_DHT11_03_10hz.ino
from ./soft/arduino_soft/GGSv2_n_DHT11_03_10hz/ in Arduino IDE - select board
- select port
- check
- upload
- open file
- Create Conda environment and install requirements:
conda create -n pyAIsense python=3.9.7
conda activate pyAIsense
pip install ipykernel
python -m ipykernel install --user --name pyAIsense --display-name "pyAIsense_env"
pip install -r ./info_n_docs/requirements_AIsense.txt
jupyter-notebook
- Collect data with
01_Collect_Data.ipynb
from ./soft/main_soft/
Settings:- in cell
Settings to Change
dir_2_save
directory to save collected data, located in ./data/readbacklabel
name of a sampleadd_label
additional label, not taken into further analysis, but cann't be emptyenv_condition
name of condition for measurement like cold, humid or warmreading_duration
time of sample collection in [min] (0.2min=12sec)
- in cell
Additional Settings
serial_port
the port of Arduino connection. In Linux default is /dev/ttyACM0, but might differ. Use Arduino IDE to find the correct port.
- in cell
- Check the collected data with
02_Check_Data.ipynb
from ./soft/main_soft/
Settings:- cell
Change to the directory with data
dir_data
change to the directory with collected data.
- cell
- Convert multiple files into a single one with
03_Data_to_Single_File.ipynb
from ./soft/main_soft/
Settings:- cell
Change to the directory with data
dir_data
change to the directory with collected data.
To remember:
- cell
Save to a new file
- output of the cell, parameter
filename_to_save
- output of the cell, parameter
- cell
- Train a model with
04_TFmodel_Train.ipynb
from ./soft/main_soft/
Settings:- cell
Settings and Paths
filename2load
this should be the file from03_Data_to_Single_File.ipynb
cellSave to a new file
model_filename
give here the model name To remember:
- cell
Lets see the classes
- output of the cell, parameter
classes_values
- output of the cell, parameter
- cell
- Make live prediction with
05_TFmodel_Predict.ipynb
from ./soft/main_soft/
Settings:- cell
Define the classes to be measured
classes_values
should be list from04_TFmodel_Train.ipynb
cellLets see the classes
output
- cell
set the paths and load data
model_filename
the name of the model from04_TFmodel_Train.ipynb
cellSettings and Paths
- cell
- Make Streamlit app running
- change in file
./soft/streamlit_app/streamlit_app.py
- line 29 :
model_ff
set models name from04_TFmodel_Train.ipynb
cellSettings and Paths
- line 33:
classes_values
should be list from04_TFmodel_Train.ipynb
cellLets see the classes
output - line 63:
serial_port
set correct port of Arduino, can be found via Arduino IDE
- line 29 :
- run the streamlit:
cd ./soft/streamlit_app/
streamlit run streamlit_app.py
- change in file
Parts: Arduino Uno, Grove multichannel Gas Sensor V2 (GGSv2), DHT11
Connections table:
Device Name | Device Pin | Arduino Pin |
---|---|---|
GGSv2 | GND | GND |
VCC | 3.3V | |
SDA | A4 | |
SCL | A5 | |
DHT11 | GND | GND |
VCC | 5V | |
Serial Data | Digital Pin 2 |
List of steps:
- Connect parts according to the table.
- Connect to computer via USB.
- Open Arduino IDE (install it if it is not yet done).
- Open project "GGSv2_n_DHT11_03_10hz.ino".
- Select Arduino Uno as current board. IDE: Tools -> Board -> 'Arduino Uno'
- Check/select the port to which the board is connected. IDE: Tools -> Port -> '/dev/ttyACM0'
- IDE: Sketch -> Verify/Compile
- IDE: Sketch -> Upload
- If appears an error "Error opening serial port '/dev/ttyACM0'"
then in terminal:sudo chmod 666 /dev/ttyACM0
. - See the output: IDE: Tools -> Serial Monitor
The data format should be like: 12:40:15.641 -> 258,61,148,86,25,29
:
12:40:15.641
is a record time- 6 numbers are: NO2 (GM102B), C2H5OH (GM302B), VOC (GM502B), CO (GM702B), temperature [degC], humidity [%]
Schematics of the connections:
![]() |
![]() |
![]() |
See in the separate page: Features and Challenges of work with GGSv2