Sensor Event Detection on ESP32

rrwatt
Posts: 19
Joined: Mon Jan 01, 2024 3:13 am

Sensor Event Detection on ESP32

Postby rrwatt » Fri May 31, 2024 11:27 pm

Hey guys,
I am working on some code to detect sudden changes in a sensor value (temperature, humidity, etc.) on ESP32. Currently, my strategy for this is to store a rolling array of the last 20 data points. Then, I calculate the average of the 20 data points as well as the standard deviation. If a data point is more than 5 standard deviations away from the mean, I am reporting it as an anomaly/event. For the most part, this works well (whenever I touch the sensor it reports an event), but it gives me false positives every few minutes, especially when the data points are very close to each other, which is a serious issue for my project. Do you have any ideas or advice? Does anyone know of a more precise algorithm to use?

I would be very grateful for any ideas or feedback.

--rrwatt

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: Sensor Event Detection on ESP32

Postby ESP_Sprite » Sat Jun 01, 2024 1:45 am

The trivial solution would be to do your calculation on more than 20 datapoints, so you get a better idea of the true standard deviation. Another thing would be to build in a per-sensor minimum standard deviation: if the one you calculate is below that, you take that minimum instead.

rrwatt
Posts: 19
Joined: Mon Jan 01, 2024 3:13 am

Re: Sensor Event Detection on ESP32

Postby rrwatt » Tue Jun 04, 2024 12:38 am

Thanks for the reply. I looked into it more and it seems that false positives only occur with very small standard deviations (<0.01°C), so I implemented your suggestion about a minimum standard deviation for each sensor and that seems to have fixed it. I very much appreciate the help.

--rrwatt

Who is online

Users browsing this forum: Google [Bot] and 96 guests