SampleCode
NOTE: This code can only be verified in ArduinoIDE 1.6.x or above.
//******************************
//*Abstract: Read value of PM1,PM2.5 and PM10 of air quality
//
//*Version:V3.1
//*Author:Zuyang @ HUST
//*Modified by Cain for Arduino Hardware Serial port compatib
ility
//*Date:March.25.2016
//******************************
#include <Arduino.h>
#define LENG 31 //0x42 + 31 bytes equal to 32 bytes
unsigned char buf[LENG];
int PM01Value=0; //define PM1.0 value of the air dete
ctor module
int PM2_5Value=0; //define PM2.5 value of the air dete
ctor module
int PM10Value=0; //define PM10 value of the air detect
or module
void setup()
{
Serial.begin(9600); //use serial0
Serial.setTimeout(1500); //set the Timeout to 1500ms, lon
ger than the data transmission periodic time of the sensor
}