Arduino Dust Sensor

Summary of Arduino Dust Sensor


This article guides users in building a weekend Arduino-based dust sensor project. It details the necessary hardware components and provides complete wiring instructions alongside C++ code for the Arduino Mega 2560. The system utilizes a Shinyei PPD42NS sensor to measure particulate matter (PM2.5 and PM10) and displays results on an LCD Shield while simultaneously outputting data via the Serial Monitor at 9600 baud for debugging purposes.

Parts used in the Arduino Dust Sensor:

  • Arduino Mega 2560
  • Shinyei PPD42NS dust sensor
  • LCD Shield (16 x 2)

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

Quick Solutions to Questions related to Arduino Dust Sensor:

  • What components are required for this project?
    The project requires an Arduino Mega 2560, a Shinyei PPD42NS dust sensor, and an LCD Shield (16 x 2).
  • How can I view sampling results during operation?
    You can view the sampling results using the Arduino IDE's Serial Monitor set to 9600 bauds.
  • Does the code support monitoring both PM2.5 and PM10?
    Yes, the provided code defines pins and variables specifically to track PM25 and PM10 values.
  • What is the sample time duration defined in the code?
    The sampletime_ms is set to 30000 milliseconds.
  • Can I use this code with an Arduino Uno instead of the Mega?
    The article explicitly provides codes and instructions for the Arduino Mega 2560 only.
  • How does the code detect low pulse occupancy?
    The code uses micros() to calculate the difference between triggerOn and triggerOff timestamps when the pin value changes.
  • Is the watchdog timer enabled in the setup function?
    Yes, wdt_enable(WDTO_8S) is called within the setup function.
  • What is the baud rate for serial communication?
    The Serial.begin function initializes communication at 9600 baud.

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