Nova SDS011 PM sensor: duty cycles

Newbie here. I was struggling to decide whether it’d be best to put this in the sensors or programming questions category, so my apologies if I chose poorly.

I’m working on a PM2.5 air quality project using a Nova Laser PM2.5 Sensor SDS011, Waveshare 1.54-inch e-Paper display, and Arduino Uno. I’m trying to figure out how to reliably get data from my sensor using the Nova_SDS011 Sensor Library. Nova’s website suggests that using the sensor on a non-continuous duty cycle will extend service life. Since I neither have the need nor the memory to take by-the-second measurements or store them to get running averages, I’d like to use a duty cycle of a few minutes and just check air quality then. However, I’m not sure how to use duty cycles in the library I’m using. I’m not a very experienced programmer, so diving into the header files of the library has only yielded a little insight.

Nova’s website and the library header file say that a duty cycle of n minutes (1<n<30) means operating for thirty seconds and then sleeping for n - 0.5 minutes. Is it supposed to pause the sketch while the sensor sleeps? Does this simply mean that the sensor can’t be reached during this time, and that it’s the responsibility of the programmer to time requests to match the duty cycle? If the latter, how can I go about making sure that my sketch runs in sync with the sensor’s duty cycle?

For example, the code below sets a duty cycle of 1 minute and queries the sensor with a 1 second delay between loops. However, I only get one successful query between lots of failed queries rather than 30 seconds’ worth of successful queries between failed queries, so I’m not really sure what’s going on here or how best to use my sensor/write my sketch.

#include <NovaSDS011.h>
#define SDS_PIN_RX 3
#define SDS_PIN_TX 5
NovaSDS011 sds011;


void setup() {

  Serial.begin(9600);
  Serial.println("setting up...");
  
  sds011.begin(SDS_PIN_RX, SDS_PIN_TX);
  sds011.setWorkingMode(WorkingMode::work);
  sds011.setDutyCycle(1);

  Serial.println("Setup finished.");
}



void loop() {

  float p25, p10;
  
  if (sds011.queryData(p25, p10) == QuerryError::no_error)
  {
    Serial.println("PM2.5=" + String(p25) + ", PM10=" + String(p10));    
  } else {
    Serial.println("Failed to get data");
  }

  delay(1000);

}

Here’s the serial monitor output:

14:49:29.920 -> setting up...
14:49:30.107 -> Setup finished.
14:49:30.107 -> Failed to get data
14:49:31.085 -> Failed to get data
14:49:32.109 -> Failed to get data
14:49:33.131 -> PM2.5=8.30, PM10=52.50
14:49:34.107 -> Failed to get data
...
14:50:35.531 -> Failed to get data
14:50:36.552 -> PM2.5=8.30, PM10=48.80
14:50:37.574 -> Failed to get data
...
14:51:35.958 -> Failed to get data
14:51:36.976 -> PM2.5=8.20, PM10=45.50
14:51:38.004 -> Failed to get data
...
14:52:36.380 -> Failed to get data
14:52:37.399 -> PM2.5=7.70, PM10=40.00
14:52:38.418 -> Failed to get data
...
14:53:34.343 -> Failed to get data
14:53:35.373 -> PM2.5=7.70, PM10=43.50
14:53:36.393 -> Failed to get data
...
14:54:37.794 -> Failed to get data
14:54:38.812 -> PM2.5=7.50, PM10=33.30
14:54:39.828 -> Failed to get data
...
14:55:35.170 -> Failed to get data
14:55:36.237 -> PM2.5=7.90, PM10=45.60
14:55:37.206 -> Failed to get data
...

Notably, the successful queries don’t seem to be exactly 1 minute apart, so again, I’m not sure what’s happening here. Any advice would be much appreciated!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.