Approximately 334 million people worldwide are suffering from asthma. Exposure to air pollution, dust, environmental allergens, and dust mites increases the risk of an asthma attack for those who have asthma. Our goal is to make the air around these people safer by developing a system that can detect dust and alert when air pollution levels are increasing. By installing our system inside asthma patients' homes, we can monitor the air quality in real time and activate the air filtration well in advance.
About the code:
First we need to include thingsProperties.h and Arduino_MKRIoTCarrier.h libraries. We will begin by creating the carrier object by using the MKRIoTCarrier carrier command. Next step we define some variables:Display colors for the led screen, sensors variables and boolean variable.
The void setup() of this program:
The first thing we do is to set the serial communication at a baud rate of 9600, which is a standard rate. We also include the command while(ArduinoCloude); which basically means that unless we connect the device to the cloud nothing will happen. After it, we use the command CARRIER_CASE = false;, which indicates that we are not using the plastic enclosure. Finally we use the commands pinMode in order to define our input channels and then use carrier.begin() to initialize the carrier.
the void loop() of this program:First we will read the temperature and the humidity sensors on the MKR IoT Carrier, Then we would like to print the values in the Serial Monitor.
Every 3s we will take a measurement of the dust sensor and the air quality sensor, this will be done by putting the if statement if ( (millis() - start_time) > sample_time_ms).
Based on the formula provided on the official Grove Sensors website, we can calculate the concentration of dust circulating in the air.
Our next step will be to examine the air quality using if statements:
- Very High Pollution → current_quality >= 1000
- High Pollution → current_quality >= 700
- Low Pollution → current_quality >= 300
- Fresh air → current_quality < 300
In order to display air quality and give the user immediate feedback, we will use 5 if else statements. In each statement we will display on the carrier screen the message according to the concentration and the current_quality.
The last part of the code enables the user to turn on and off the fan, using onTouchDown trigger and boolean variable fan_flag







Comments