Sometimes, in the development of our work, we need to monitor some physical variable of a process, and either because measuring it directly is not safe or we simply do not have the corresponding sensor to do it, we are limited to sampling it. In some cases in this process, there are other variables that are indirectly correlated with the one that we cannot measure, which we do have the possibility of monitoring.
As a proof of concept to this case, I show you how I determine the air quality based on how an air purifier vibrates while cleaning impurities and gases in the environment automatically.
For this, I trained a neural network putting the purifier in its 3 speeds and capturing its vibrations in each case, when the purifier is configured in automatic mode, it selects one of its speeds depending on how much the environment has to be cleaned, hence the relationship between air quality and the characteristic vibrations of each speed.
The HardwareUsing a movement recognition model made in Edge Impulse, I am able to classify different vibration profiles of an air purifier to infer the pollution of the room air.
Training the modelEdge Impulse lets you create your vibration datasets from different sources, directly from the end device (the way I did it) or using your smartphone accelerometer.
To correctly upload the data to Edge Impulse using the data forwarder, you just need to send the 3 accelerometer axis separated by commas.
/* Print sensor values */
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.println(a.acceleration.z);
delay(5); //delay that determines output frequency > 100 hz at least
- Create an Edge Impulse account for free.
- Install the Edge Impulse CLI on your computer.
- Open your command prompt (CMD) and run:
edge-impulse-data-forwarder
- You will be asked to log in, use the credentials of your Edge Impulse account. (CMD)
- Then, select the project where you want to send the sensor data. (CMD)
- And go to the Data acquisition tab on your Edge Impulse project. (Browser)
- Set the label, and length for your sample. (Browser)
- Click on "Start sampling". (Browser)
I sampled for 10 seconds the vibrations produced by the air purifier running at its 3 different speeds, as the movement is continuous I didn't need to split the samples on smaller windows.
My dataset consists on +1:30 minutes recordings of each speed mode:
- Turned off
- Medium = slightly polluted
- High mode = highly polluted
- Night = clean air
This project is public on Edge Impulse so you can clone it, modify it and test it!
Impulse designMy model consists of a Spectral Analysis processing block + a Classification (Keras) learning block:
Important:
- Window size: 1000 ms.
- Window increase: 500 ms.
- Didn't touch the settings of the Spectral Analysis block and NN architecture.
I achieved quite a good accuracy, validated with the "Live classification" functionality with new data, the model was performing very well.
Note: a 100% accuracy is not always a good sign, this may mean that your model is overfitted and will struggle on classifying new data. Please check the real behavior of your model by using the "Live classification" with different data than the one used for training or spend a try and error process changing the model parameters and staying with the better results ones.
Deploy the model back to the microcontrollerIn the Deployment section, create an Arduino library, enabling the EON compiler for 8bits:
The library will be downloaded on a ZIP file.
- On your Arduino IDE navigate to "Sketch" > "Include Library" > "Add.ZIP Library..."
- Search for your downloaded library directory and add it to your IDE.
- Open the inference code, build it and flash your ESP32 board.
- Test the project.
I am happy with the results of the project/proof of concept, it's important to give a conscious use of the new possibilities that machine learning is giving us nowadays and find useful and meaningful applications for it.
I think that there's a lot of data hidden behind the daily basis things that we can use to make our life better, air pollution is a real thing and its important to have a clean and adequate workspace because more than ever before we are spending a lot of time in offices, rooms, and workshops.
The project can be improved in different ways:
- Using a better development platform such as WisBlock for a tiny deployment.
- Make the project run on batteries and send the status to an app like Ubidots.
Comments