Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2023sric:esp32-iaq [2024/05/30 01:08]
bogdan_ionut.spinu [ThingsBoard]
iothings:proiecte:2023sric:esp32-iaq [2024/05/30 10:12] (current)
bogdan_ionut.spinu
Line 1: Line 1:
 ====== ESP32 Indoor Air Quality Monitoring ====== ====== ESP32 Indoor Air Quality Monitoring ======
  
-  * Author: Bogdan-Ionut Spinu+  * Author: Bogdan-Ionuț Spînu
   * Email: bogdan_ionut.spinu@stud.acs.pub.ro   * Email: bogdan_ionut.spinu@stud.acs.pub.ro
   * Master: MPI   * Master: MPI
Line 15: Line 15:
   * ESP32-C3-DevKitM-1   * ESP32-C3-DevKitM-1
   * Sensirion SEN55   * Sensirion SEN55
-The Sensirion Sen55 sensor is an advanced air quality monitoring module designed for high-precision indoor air assessments. It combines the ability to measure particulate matter (PM1.0, PM2.5, PM4.0, and PM10) using laser-based light scattering technology, and volatile organic compounds (VOCs) through metal oxide semiconductor (MOS) technology. Additionally,​ it provides accurate readings of relative humidity and temperature. This sensor is known for its high accuracy and sensitivity,​ ensuring reliable detection of pollutants and environmental conditions. Its compact design facilitates easy integration into various devices and systems, maintaining robust performance in a small form factor. The Sen55 communicates via an I²C interface, simplifying its connection with microcontrollers like the ESP32.+{{ :​iothings:​proiecte:​2023sric:​sen55.png |}} 
 +The Sensirion Sen55 sensor is an advanced air quality monitoring module designed for high-precision indoor air assessments. It combines the ability to measure particulate matter (PM1.0, PM2.5, PM4.0, and PM10) using laser-based light scattering technology, and volatile organic compounds (VOCs) through metal oxide semiconductor (MOS) technology. Additionally,​ it provides accurate readings of relative humidity and temperature. Its compact design facilitates easy integration into various devices and systems, maintaining robust performance in a small form factor. The Sen55 communicates via an I²C interface, simplifying its connection with microcontrollers like the ESP32.
   * JST GHR-06-S connector with 6 jumper wires   * JST GHR-06-S connector with 6 jumper wires
   * USB-A to USB-C cable and an old Samsung charger   * USB-A to USB-C cable and an old Samsung charger
 {{ :​iothings:​proiecte:​2023sric:​esp32-iaq_schema.png |}} {{ :​iothings:​proiecte:​2023sric:​esp32-iaq_schema.png |}}
 +{{ :​iothings:​proiecte:​2023sric:​esp32-iaq.jpg?​700 |}}
  
 ====== Software ====== ====== Software ======
Line 90: Line 92:
         (int16_t)(200 * temp_offset),​ default_slope,​ default_time_constant);​         (int16_t)(200 * temp_offset),​ default_slope,​ default_time_constant);​
 } }
-</​code>​ 
- 
-Threshold values for the indoor air pollutants measured by Sen55, according to various guidelines from WHO, EPA (US Environmental Protection Agency), Reset Air and WELL Building standards: 
-<code c> 
-const double PM1_THRESHOLD = 40; 
-const double PM2P5_THRESHOLD = 15; 
-const double PM2P5_THRESHOLD_DANGEROUS = 90; 
-const double PM4_THRESHOLD = 30; 
-const double PM10_THRESHOLD = 40; 
-const double PM10_THRESHOLD_DANGEROUS = 250; 
-const double HUMIDITY_THRESHOLD_HIGH = 55.0; 
-const double HUMIDITY_THRESHOLD_LOW = 35.0; 
-const double TEMPERATURE_THRESHOLD_HIGH = 24.0; 
-const double TEMPERATURE_THRESHOLD_LOW = 18.0; 
-const double VOC_THRESHOLD = 100; 
-const double VOC_THRESHOLD_DANGEROUS = 610; 
-const double NOX_THRESHOLD = 53; 
 </​code>​ </​code>​
  
Line 175: Line 160:
     }     }
 </​code>​ </​code>​
 +
 +Threshold values for the indoor air pollutants measured by Sen55, according to various guidelines from WHO, EPA (US Environmental Protection Agency), Reset Air and WELL Building standards:
 +<code c>
 +const double PM1_THRESHOLD = 40;
 +const double PM2P5_THRESHOLD = 15;
 +const double PM2P5_THRESHOLD_DANGEROUS = 90;
 +const double PM4_THRESHOLD = 30;
 +const double PM10_THRESHOLD = 40;
 +const double PM10_THRESHOLD_DANGEROUS = 250;
 +const double HUMIDITY_THRESHOLD_HIGH = 55.0;
 +const double HUMIDITY_THRESHOLD_LOW = 35.0;
 +const double TEMPERATURE_THRESHOLD_HIGH = 24.0;
 +const double TEMPERATURE_THRESHOLD_LOW = 18.0;
 +const double VOC_THRESHOLD = 100;
 +const double VOC_THRESHOLD_DANGEROUS = 610;
 +const double NOX_THRESHOLD = 53;
 +</​code>​
 +
 +IAQ index formula – will return a number between 0 and 100 indicating the general quality of the air from the last measurements of the sensor:
 +<code c>
 +double calculateIAQIndex(double pm1, double pm2p5, double pm4, double pm10,
 +                         ​double humidity, double temperature,​ double voc, double nox)
 +{
 +    // Define a non-linear penalty function
 +    double nonLinearPenalty(double deviation, double threshold) {
 +        if (deviation <= 0.0) {
 +            return 0.0; // No penalty if value is within or equal to threshold
 +        } else {
 +            double ratio = deviation / threshold;
 +            return ratio * ratio * 100.0; // Squaring the ratio for non-linear penalty
 +        }
 +    }
 +
 +    double scalePenalty(double value, double threshold_worrying,​ double threshold_dangerous) {
 +        if (value <= threshold_worrying) {
 +            return 0.0; // No penalty if value is within the good range
 +        } else if (value <= threshold_dangerous) {
 +            // Linear penalty from 0 to 50 between threshold_worrying and threshold_dangerous
 +            return 50.0 * (value - threshold_worrying) / (threshold_dangerous - threshold_worrying);​
 +        } else {
 +            // Logarithmic penalty from 50 to 100 beyond threshold_dangerous
 +            return 50.0 + 50.0 * log(1 + (value - threshold_dangerous) / threshold_dangerous);​
 +        }
 +    }
 +
 +    // Calculate penalties for each parameter
 +    double penalty_pm1 = scalePenalty(pm1,​ PM1_THRESHOLD,​ PM10_THRESHOLD_DANGEROUS);​
 +    double penalty_pm2p5 = scalePenalty(pm2p5,​ PM2P5_THRESHOLD,​ PM2P5_THRESHOLD_DANGEROUS);​
 +    double penalty_pm4 = scalePenalty(pm4,​ PM4_THRESHOLD,​ PM10_THRESHOLD_DANGEROUS);​
 +    double penalty_pm10 = scalePenalty(pm10,​ PM10_THRESHOLD,​ PM10_THRESHOLD_DANGEROUS);​
 +    double penalty_humidity = nonLinearPenalty(humidity - HUMIDITY_THRESHOLD_HIGH,​ HUMIDITY_THRESHOLD_HIGH) +
 +                              nonLinearPenalty(HUMIDITY_THRESHOLD_LOW - humidity, HUMIDITY_THRESHOLD_LOW);​
 +    double penalty_temperature = nonLinearPenalty(temperature - TEMPERATURE_THRESHOLD_HIGH,​ TEMPERATURE_THRESHOLD_HIGH) +
 +                                 ​nonLinearPenalty(TEMPERATURE_THRESHOLD_LOW - temperature,​ TEMPERATURE_THRESHOLD_LOW);​
 +    double penalty_voc = scalePenalty(voc,​ VOC_THRESHOLD,​ VOC_THRESHOLD_DANGEROUS);​
 +    double penalty_nox = nonLinearPenalty(nox - NOX_THRESHOLD,​ NOX_THRESHOLD);​
 +
 +    // Calculate total penalty
 +    double total_penalty = penalty_pm1 + penalty_pm2p5 + penalty_pm4 +
 +                           ​penalty_pm10 + 3 * (penalty_humidity + penalty_temperature) +
 +                           ​penalty_voc + penalty_nox;​
 +
 +    // Calculate IAQ index
 +    double iaq_index = 100.0 - total_penalty;​
 +
 +    // Ensure IAQ index is within the range [0, 100]
 +    if (iaq_index < 0.0) {
 +        iaq_index = 0.0;
 +    }
 +
 +    return iaq_index;
 +}
 +</​code>​
 +
 ==== ThingsBoard ==== ==== ThingsBoard ====
-{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb1.png?​700}} +I have used the open-source ThingsBoard platform customized by UPB with my university account for telemetry storage and visualization:​ http://​digitaltwin.upb.ro:​8080/​home. 
-{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb2.png?​700}} + 
-{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb3.png?​700}}+I have configured my device inside ThingsBoard to receive and process JSON data received via MQTT from the ESP32 board, store the timeseries measurements inside a PostgreSQL database and created a dashboard to display the evolution of IAQ parameters over time: 
 + 
 + 
 +{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb4.png?​700 |}} 
 +{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb1.png?​700 ​|}} 
 +{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb2.png?​700 ​|}} 
 +{{ :​iothings:​proiecte:​2023sric:​esp32-iaq_tb3.png?​700 ​|}}
  
 +====== Challenges ======
 +Light sleep mode - optimize power consumption by shutting down wireless peripherals and reducing most voltage supply to RAM and CPUs, and use the RTC controller'​s internal timer to wake up the ESP32 board every 30 seconds to read and send data from sensor (esp_sleep_enable_timer_wakeup()). Due to the WiFi module being powered down and reconnecting every session, which leads to countless reconnections to the MQTT broker that take up more CPU resources and bandwidth than just sending the message itself, I have decided to not use sleep mode anymore.
  
-==== Bibliography ​====+====== ​References ​====== 
 +  - https://​sensirion.com/​products/​catalog/​SEN55/​
   - https://​sensirion.com/​media/​documents/​6791EFA0/​62A1F68F/​Sensirion_Datasheet_Environmental_Node_SEN5x.pdf   - https://​sensirion.com/​media/​documents/​6791EFA0/​62A1F68F/​Sensirion_Datasheet_Environmental_Node_SEN5x.pdf
   - https://​github.com/​espressif/​esp-idf   - https://​github.com/​espressif/​esp-idf
 +  - https://​thingsboard.io/​
   - WHO global air quality guidelines. Particulate matter (PM2.5 and PM10), ozone, nitrogen dioxide, sulfur dioxide and carbon monoxide. Geneva: World Health Organization;​ 2021.   - WHO global air quality guidelines. Particulate matter (PM2.5 and PM10), ozone, nitrogen dioxide, sulfur dioxide and carbon monoxide. Geneva: World Health Organization;​ 2021.
  
iothings/proiecte/2023sric/esp32-iaq.1717020499.txt.gz · Last modified: 2024/05/30 01:08 by bogdan_ionut.spinu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0