Sensors sometimes give strange readings — what do I do? — answered by Engineer Saeed Baatiah
This is normal and expected, and the mistake is treating it as a rare fault. Anomalous readings come from electrical noise, vibration or a falling battery. The software remedy has three layers: discard anything outside the physically possible range, smooth readings with a short rolling average, and never fire an alert from a single reading but from several consecutive ones — otherwise the team loses trust in alerts and starts ignoring them.
Start by classifying the anomaly, because each type needs a different remedy: a single instantaneous spike is usually electrical noise or vibration, a slow gradual drift is usually a falling battery or an ageing sensor, a physically impossible value is a fault or a wiring error, and a total stop is network or power. The four need different responses, and conflating them makes the system shout about the wrong things.
The three software layers apply in this order: discard anything outside the physically possible range before it is even stored, then smooth readings with a short rolling average that absorbs instantaneous spikes, then require several consecutive readings before firing any alert. And an important rule: keep the raw reading stored even if you never display it, since you may need it later to diagnose a fault — smoothing is for display, not for the archive.
- Classify first: spike, gradual drift, impossible value, stop
- Discard the impossible, then smooth, then require repetition
- Always keep the raw data — smoothing is for display, not the archive