[vc_row][vc_column width=”1/1″][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_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Dust sensor” tab_id=”1387207523-1-41″][vc_column_text]
Main feature:
- Output signal is PWM;
- Easy installation;
- Single-supply;
Parameter:
- 5VDC;
- Scope of detecting particles:Max 8000pcs/283ml;
[/vc_column_text][/vc_tab][vc_tab title=”Compile and run” tab_id=”1387207523-2-96″][vc_column_text]Hardware:
- 1 x pcDuino
- 1 x Dust Sensor
- Several jumper wire
Wiring diagram:
- Dust Sensor Pin 1 => pcDuino GND
- Dust Sensor Pin 3 => pcDuino 5V
- Dust Sensor Pin 4 => pcDuino D8
Run code: (You need to preheat the dust sensor more than 3 minutes before first use )
1. Launch Arduino IDE that comes with pcDuino and enter the following code (the code is shown in next tab):
2. Click the run button:
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1387209864712-2-5″][vc_column_text]<code>
/************************************/
/* Dust Sensor Pin 1 => pcDuino GND */
/* Dust Sensor Pin 3 => pcDuino 5V */
/* Dust Sensor Pin 4 => pcDuino D8 */
/************************************/
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup()
{
pinMode(pin,INPUT);
starttime = millis();//get the current time;
}
void loop()
{
duration = pulseIn(pin,LOW,1000000);
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
printf(“lowpulseoccupancy: %ld \nratio: %f \nconcentration: %f\n\n”,lowpulseoccupancy,ratio,concentration);
lowpulseoccupancy = 0;
starttime = millis();
}
}
</code>[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Comments are closed.