Electorials Electronics
Published © GPL3+

Review 004: Grove - Dust Sensor (PPD42NS) Review

A review of the Grove - Dust Sensor (PPD42NS) from Seeed Studio.

BeginnerProtip12 minutes2,575
Review 004: Grove - Dust Sensor (PPD42NS) Review

Things used in this project

Story

Read more

Code

Arduino Grove - Dust Sensor (PPD42NS) Sample Code

C/C++
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 2000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup() {
  Serial.begin(9600);
  pinMode(8,INPUT);
  starttime = millis();//get the current time;
}
void loop() {
  duration = pulseIn(pin, LOW);
  lowpulseoccupancy = lowpulseoccupancy+duration;
  if ((millis()-starttime) >= sampletime_ms)//if the sampel time = = 30s
  {
    ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
    concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
    Serial.print("Concentration = ");
    Serial.print(concentration);
    Serial.println(" pcs/0.01cf");
    Serial.println("\n");
    lowpulseoccupancy = 0;
    starttime = millis();
  }
}

Credits

Electorials Electronics

Electorials Electronics

85 projects • 63 followers
I'm an electronic hobbyist interested in anything, from Arduino to drones. I plan to educate people with the content on my website.

Comments