Arduino Dust Sensor

Put together a Arduino-based dust sensor over the weekend using the following components:

  • Arduino Mega 2560
  • Shinyei PPD42NS dust sensor
  • LCD Shield (16 x 2)
  • shadowandy – my life stories

The codes and wiring instructions for Arduino Mega 2560 and Shinyei PPD42NS is as follow. However, I did include Serial output so you can view the sampling results using Arduino IDE’s Serial Monitor (9600 bauds).

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
byte nano[8] = {B00000,B00000,B00000,B10010,B10010,B10010,B11110,B10000};
byte pow3[8] = {B11000,B00100,B11000,B00100,B11000,B00000,B00000,B00000};
#include <avr/wdt.h>
#define PM25 0
#define PM10 1
int pin[] = {50,51};
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long triggerOn[2];
unsigned long triggerOff[2];
unsigned long lowpulseoccupancy[] = {0,0};
float ratio[] = {0,0};
float count[] = {0,0};
boolean value[] = {HIGH,HIGH};
boolean trigger[] = {false, false};
void setup()
{
  lcd.createChar(0,nano);
  lcd.createChar(1,pow3);
  lcd.begin(16, 2);
  Serial.begin(9600); //Output to Serial at 9600 baud
  pinMode(pin[PM25],INPUT); //Listen at the designated PIN
  wdt_enable(WDTO_8S);
  starttime = millis(); //Fetching the current time
}
void loop()
{
  value[PM25] = digitalRead(pin[PM25]);
  value[PM10] = digitalRead(pin[PM10]);

Put together a dust sensor using Arduino Mega 2560, Shinyei PPD42NS dust sensor and LCD shield.

if(value[PM25] == LOW && trigger[PM25] == false) {
    trigger[PM25] = true;
    triggerOn[PM25] = micros();
  }
  if(value[PM25] == HIGH && trigger[PM25] == true) {
    triggerOff[PM25] = micros();
    lowpulseoccupancy[PM25] += (triggerOff[PM25] triggerOn[PM25]);
    trigger[PM25] = false;
  }
  if(value[PM10] == LOW && trigger[PM10] == false) {
    trigger[PM10] = true;
    triggerOn[PM10] = micros();
  }
  if(value[PM10] == HIGH && trigger[PM10] == true) {
    triggerOff[PM10] = micros();
    lowpulseoccupancy[PM10] += (triggerOff[PM10] triggerOn[PM10]);
    trigger[PM10] = false;
  }
  wdt_reset();
  if ((millis()starttime) > sampletime_ms)//Checking if it is time to sample
  {
For more detail:Arduino Dust Sensor

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter