[vc_row][vc_column][vc_column_text]In this tutorial we are going to use Dust sensor on pcDuino to measure air pollution pm2.5.
[/vc_column_text][vc_tour][vc_tab title=”Dust Sensor ” tab_id=”1398961315-1-47″][vc_column_text]Main feature:
- Output signal is PWM;
- Easy installation;
- Single-supply;
[/vc_column_text][/vc_tab][vc_tab title=”Parts List” tab_id=”1398961315-2-80″][vc_column_text]
- 1 x Arduino Uno
- 1 x Dust Sensor
- 1 x Mini Breadboard
- Several Jumper wires
[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1398961922223-2-6″][vc_column_text]We wire the parts in the following way:
- Pin 2 of dust sensor -> Digital 8 of Arduino Uno
- Pin 3 of dust sensor -> +5V of Arduino Uno
- Pin 5 of dust sensor -> Ground of Arduino Uno
The following is the picture of the setup:
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1398962253899-3-0″][vc_column_text]
#include<string.h>
byte buff[2];
int pin = 8;//DSM501A input D8
unsigned long duration;
unsigned long starttime;
unsigned long endtime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
int i=0;
void setup()
{
Serial.begin(9600);
pinMode(8,INPUT);
starttime = millis();
}
void loop()
{
duration = pulseIn(pin, LOW);
lowpulseoccupancy += duration;
endtime = millis();
if ((endtime-starttime) > sampletime_ms)
{
ratio = (lowpulseoccupancy-endtime+starttime + sampletime_ms)/(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("lowpulseoccupancy:");
Serial.print(lowpulseoccupancy);
Serial.print("\n");
Serial.print("ratio:");
Serial.print("\n");
Serial.print(ratio);
Serial.print("DSM501A:");
Serial.println(concentration);
Serial.print(";\n\n");
lowpulseoccupancy = 0;
starttime = millis();
}
}
[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1398962527946-4-2″][vc_column_text]After power it on, there is no LED indicator on the dust sensor to indicate if the module is running.

Leave a Reply
You must be logged in to post a comment.