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




Current Project / Post can also be found using:

  • dust sensor using microcontroller

Leave a Comment

*
= 5 + 5

Read previous post:
Power Management Solutions Battery Chargers
Power Management Solutions: Battery Chargers

The huge increase of portable devices during the last 10-15 years has lead to numerous companies seeking (and succeeding) to...

Close
Scroll to top