AirGradient Forum

PMSx003 - Passive mode for longevity

Hi there, I am looking at building one for monitoring my indoor conditions.

However, I see that it runs the PM sensor continuously. Since the laser diode has a finite lifetime, I would like to have it wake up to run for 30sec (recc’d period for fan spooling), take reading, and then sleep for 2mins, repeat. I went through the library to see it has Passive Mode included.

I’m not very well-versed in coding, so I don’t really have a clue how to set it up this way.

At the same time, I’d like to have the rest of the sensor readings being taken at a different interval (e.g. every 5 sec) compared to the PM sensor (every 2 mins). How may I implement these two concurrent “loops” as well?

Has anyone managed to implement something similar?
Any help is appreciated, thanks!

EDIT: Found if-statements with millis() can let me run concurrent events at different intervals. But I’d have to use delay() during the warmup process, which would hold up the loop anyway, since the process will get stuck at that line until it is done waiting. What other ways can make it work?

This thread discusses the same thing, although I haven’t implemented any of the proposed changes:
Extending the life span of the PMS5003 sensor - Components - AirGradient

Thanks. I came across the thread but wasn’t able to find the relevant code on the posted git at first. Had to pore through and find it within one of the earlier commits, which used the timer function. No idea why that portion was gone in the updated code on the project page.