DUSTY is an IoT service that helps users with asthma or house dust mite allergies to control their symptoms. It is a extensive service that sends the users warnings about the dust content is their house, keeps track on when it is time to clean and sends warnings on weather forecasts, locations and seasons. This helps the user understand where their symptoms come from and take matter into their own hands. In this project I realized a small part of this concept: The warning the sensor gives the user on the dust content in their home.
What are we going to do?DUSTY the dust sensor sends the user warnings when the dust content is to high. The dust sensor would be one the wall in a room in your house. behind it, there would be a LED light which gives the user feedback on the dust content in that room. If the dust content is good the light is green, if it increases the light would turn orange and if the dust content is to hight, the light will turn red.
Step 1Fist of all we have to connect the dust sensor to a Node MCU. In the pictures below you will see how to do this.
Then we will start with a demo code to show data from the dust sensor. Add the following code to a new Arduino sketch
/*
Grove - Dust Sensor Demo v1.0
Interface to Shinyei Model PPD42NS Particle Sensor
Program by Christopher Nafis
Written April 2012
http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
http://www.sca-shinyei.com/pdf/PPD42NS.pdf
JST Pin 1 (Black Wire) => //Arduino GND
JST Pin 3 (Red wire) => //Arduino 5VDC
JST Pin 4 (Yellow wire) => //Arduino Digital Pin 8
*/
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();
}
}
In this code you can test if the dust sensor works. If you go to the serial monitor, you should see something like the picture below:
Next we are going to connect a LED light. Use the pictures below to do this the right way.
Now we will edit our code so that the LED will turn red, orange or green, depending on the dust content.
Go to Void SetUp in your code. Add the following code:
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
Then go down to the end of Void Loop and add the following if else statement:
if (concentration <= 2000)
{
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
Serial.print("Good!");
}
else if (concentration <= 4000)
{
digitalWrite(D1, 255);
digitalWrite(D2, 140);
Serial.print("It is starting to get dusty");
}
else
{
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
Serial.print("Warning!");
}
This code makes your LED turn green if the dust content is 2000 or less. If the dust content is 4000 or less, the LED will turn orange. Else the LED will turn red.
Your final code should look like this:
/*
Grove - Dust Sensor Demo v1.0
Interface to Shinyei Model PPD42NS Particle Sensor
Program by Christopher Nafis
Written April 2012
http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
http://www.sca-shinyei.com/pdf/PPD42NS.pdf
JST Pin 1 (Black Wire) => //Arduino GND
JST Pin 3 (Red wire) => //Arduino 5VDC
JST Pin 4 (Yellow wire) => //Arduino Digital Pin 8
*/
int pin = D8;
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(D8,INPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
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();
}
if (concentration <= 2000)
{
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
Serial.print("Good!");
}
else if (concentration <= 4000)
{
digitalWrite(D1, 255);
digitalWrite(D2, 140);
Serial.print("It is starting to get dusty");
}
else
{
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
Serial.print("Warning!");
}
}
If you run this code and then go to the serial monitor, it'll say 'Good!' if the dust content is good and the LED is green. If the dust content is getting higher and the LED turns orange, it'll say 'It is starting to get dusty'. And then if the dust content is to hight and the LED turns red it'll say 'Warning!'.
And now we have made a warning system for dust content is your house!
I hope you enjoyed it!
Sourceshttp://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
Comments