Detecting a sudden change



  • Hello all!

    I'm building a PM2.5 particle matter sensor and I'm trying to figure out how I would go about to detect sudden changes of measured particles occurs.

    I expect that there is a background level of particle matters that vary very slowly maybe between 0 and 20 µg/m3. I'd want to be alerted if that level rises all off a sudden. That happens frequently here when the flue gases from my neighbors chimney flows towards the ground level and enters my mechanical ventilation intake. I'd like the alert to be active until "normal" levels have been reached and a new alert if it happens again after that.

    I'm putting my question here in hope that you might happen to know a "software design pattern" some reusable solution for a similar problem. I have seen a Lua Script for Humidity control that does a similar thing but a c++ code snippet to be inspired by would make things easier.

    Do you have any idea about how this should be done clean and beautifully?

    Thanks in advance. Cheers!



  • @รอเร-อ It all depends on what sensor you are using.

    I am using 2 different sensors and I can tell you that there is a wide variation throught the day. If I shower in the en-suite shower the bedroom sensor shows this. If I use a wok to stir fry then all the 'dust' sensors pick up the tine droplets of hot oil that circulate in the air.

    Background levels here are under 60uG/m3 on the first floor, about 90ug/M3 on ground floor and 0-9 ppm of ppm25 and 0-6ppm of ppm10.

    For your use a better suited sensor would be worth finding as optical sensors will react to moisture as well as dust. Perhaps in the end you will need a combination of sensors? I hope this helps you think of a solution.

    As for detecting a sudden change then you just need to remember the last reading and compare it to the new reading. If the difference is more than your chosen value then you have an alert state!


  • Mod

    @รอเร-อ you probably want to filter spikes in the sensor readings to prevent reacting on outliers.
    I understand your sensor is located outside. Here is an example over 2 days from my pm sensor also located outside:
    Screenshot_20210524-091925_Chrome.jpg
    I would try a long, slow filter window to establish a baseline value, and a short, fast filter window to react on changes relatively quickly. Then when the slow filtered value differs more than x from the fast filtered value you need to stop the intake of fresh air.
    Search for "exponential moving average" to implement such filters.

    Btw. I only read a pm value once a minute or so. If filtering using a few values the response will be in the order of a few minutes at best.



  • @Yveaux Thanks!

    Nice graph. I will do something similar in Grafana. I think my MySensors device should also report every minute, perhaps using the highest sampled value. All values are sent to MQTT by my gateway and my Home Automation will store the time value pairs in influxdb. Right now I'm waiting for the hardware to arrive... 😀


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 2
  • 198
  • 3
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts