pms5003-python
pms5003-python copied to clipboard
Reset changes the behaviour of the sensor
What
When i first plugged in and used the PMS5003 sensor, it felt like it wasn't working as expected, the reading from the sensor didn't really change even when i blocked the sensor fan and holes in the front. Here's a graph of the readings over several days:
After looking through the code for this library i noticed that there was a reset API, so i called that which seemed to help, and the sensor did seem to behave differently and the results in the graph also looked a bit more interesting:
However, when ever i restart my python application (which also now performs a reset on the sensor), the sensor behaviour changes on every restart:
I would expect that reset shouldn't change the characteristics of the sensor so drastically.
Here's the snippet of the code:
#!/usr/bin/env python3
import sys
import time
import logging
from pms5003 import PMS5003
from pms5003 import ReadTimeoutError as pmsReadTimeoutError
from pms5003 import SerialTimeoutError
from prometheus_client import start_http_server,Gauge
env_sensor_pm1_gauge = Gauge('env_sensor_pm1', 'particle monitoring 1 in ug/m3')
env_sensor_pm25_gauge = Gauge('env_sensor_pm25', 'particle monitoring 2.5 in ug/m3')
env_sensor_pm10_gauge = Gauge('env_sensor_pm10', 'particle monitoring 10 in ug/m3')
env_sensor_pm_03_pl_gauge = Gauge('env_sensor_pm03_litre', 'particles >0.3um per 1/10 litre of air')
env_sensor_pm_05_pl_gauge = Gauge('env_sensor_pm05_litre', 'particles >0.5um per 1/10 litre of air')
env_sensor_pm_1_pl_gauge = Gauge('env_sensor_pm1_litre', 'particles >1um per 1/10 litre of air')
env_sensor_pm_25_pl_gauge = Gauge('env_sensor_pm25_litre', 'particles >2.5um per 1/10 litre of air')
env_sensor_pm_5_pl_gauge = Gauge('env_sensor_pm5_litre', 'particles >5um per 1/10 litre of air')
env_sensor_pm_10_pl_gauge = Gauge('env_sensor_pm10_litre', 'particles >10um per 1/10 litre of air')
# PMS5003 particulate sensor
pms5003 = PMS5003()
time.sleep(1.0)
def main():
pms5003.reset()
# The main loop
while True:
pms_data = None
try:
pms_data = pms5003.read()
except (SerialTimeoutError, pmsReadTimeoutError):
logging.warning("Failed to read PMS5003")
else:
env_sensor_pm1_gauge.set(pms_data.pm_ug_per_m3(1.0))
env_sensor_pm25_gauge.set(pms_data.pm_ug_per_m3(2.5))
env_sensor_pm10_gauge.set(pms_data.pm_ug_per_m3(10))
env_sensor_pm_03_pl_gauge.set(pms_data.pm_per_1l_air(0.3))
env_sensor_pm_05_pl_gauge.set(pms_data.pm_per_1l_air(0.5))
env_sensor_pm_1_pl_gauge.set(pms_data.pm_per_1l_air(1))
env_sensor_pm_25_pl_gauge.set(pms_data.pm_per_1l_air(2.5))
env_sensor_pm_5_pl_gauge.set(pms_data.pm_per_1l_air(5))
env_sensor_pm_10_pl_gauge.set(pms_data.pm_per_1l_air(10))
time.sleep(30) # Sleep for 30 seconds before getting more data
if __name__ == "__main__":
try:
start_http_server(8000)
main()
except KeyboardInterrupt:
print("shutting down")
sys.exit(0)
I'm running this on a Raspberry Pi Zero 2, 64 bit version of headless Raspbian.
Any idea why this is happening?
Sorry for the lack of response - this looks abnormal but I don't have a good sense for why it's happening.
IIRC there's some warmup time for the sensor, but it shouldn't result in readings this wildly different. These are nothing if not quirky sensors though. Have you had any different results since?
Hi, thanks for the response. I've since stopped and started the service several times and it doesn't seem to happen every time the sensor is reset. It might jump a bit (in that it is sensing more particles in the air) but then usually settles back down.
I realise that you didn't make the sensor module, but I think it's quite a disappointing sensor. I have an air purifier which speeds up the fan when it senses more dust, smoke and aerosol gas in the air, whereas the PMS5003 doesn't seem to pick up on this change in the air and the graph is flat!
I think it's quite a disappointing sensor
I don't think you're alone in that sentiment. There is much written about it, and working around its idiosyncrasies online. This one seems particularly salient and they've put in quite some effort - https://www.airgradient.com/blog/low-readings-from-pms5003/
I suspect your fan probably includes some sort of VOC/Gas sensor and detects things beyond the capabilities of PMS5003? Or uses other measurements as a proxy for air quality. I don't imagine it has a more sophisticated particulate sensor- part of the reason for PMS5003 being so prevalent, I think, is that the whole class of sensor is not cheap.
I don't think PMS5003 is supposed to be this quirky though, I wonder if you're seeing something related to that article linked above. It would be the first I've heard of it, if so, since we're not integrating these sensors into products then I don't get much exposure to their ongoing realworld performance and uh- perhaps hobbyists are more forgiving of quirks that might be solvable.
Thanks for the response!
https://www.airgradient.com/blog/low-readings-from-pms5003/
Thanks for the link! It looks like they were able to resolve the issue with scaling factors. The issue I'm seeing is unlikely to be resolved in the same way (I did try, but I'm still seeing strangeness when performing a reset on the sensor).
I think the next steps for me are to buy a new sensor and see if that helps resolves the issue. I'll report back with my findings.