44 #define CHILD_ID_DUST_PM10 0
45 #define CHILD_ID_DUST_PM25 1
46 #define DUST_SENSOR_DIGITAL_PIN_PM10 6
47 #define DUST_SENSOR_DIGITAL_PIN_PM25 3
49 uint32_t SLEEP_TIME = 30*1000;
52 float valDUSTPM25 =0.0;
53 float lastDUSTPM25 =0.0;
54 float valDUSTPM10 =0.0;
55 float lastDUSTPM10 =0.0;
59 uint32_t sampletime_ms = 30000;
60 uint32_t lowpulseoccupancy = 0;
62 long concentrationPM25 = 0;
63 long concentrationPM10 = 0;
65 MyMessage dustMsgPM10(CHILD_ID_DUST_PM10, V_LEVEL);
66 MyMessage msgPM10(CHILD_ID_DUST_PM10, V_UNIT_PREFIX);
67 MyMessage dustMsgPM25(CHILD_ID_DUST_PM25, V_LEVEL);
68 MyMessage msgPM25(CHILD_ID_DUST_PM25, V_UNIT_PREFIX);
72 pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT);
73 pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT);
82 present(CHILD_ID_DUST_PM10, S_DUST);
84 present(CHILD_ID_DUST_PM25, S_DUST);
92 concentrationPM25=(long)getPM(DUST_SENSOR_DIGITAL_PIN_PM25);
93 Serial.print(
"PM25: ");
94 Serial.println(concentrationPM25);
97 if ((concentrationPM25 != lastDUSTPM25)&&(concentrationPM25>0)) {
98 send(dustMsgPM25.
set((int32_t)ceil(concentrationPM25)));
99 lastDUSTPM25 = ceil(concentrationPM25);
103 concentrationPM10=getPM(DUST_SENSOR_DIGITAL_PIN_PM10);
104 Serial.print(
"PM10: ");
105 Serial.println(concentrationPM10);
110 long ppmv=(concentrationPM10*0.0283168/100/1000) * (0.08205*temp)/0.01;
112 if ((ceil(concentrationPM10) != lastDUSTPM10)&&((long)concentrationPM10>0)) {
113 send(dustMsgPM10.
set((int32_t)ppmv));
114 lastDUSTPM10 = ceil(concentrationPM10);
123 long getPM(
int DUST_SENSOR_DIGITAL_PIN)
126 starttime = millis();
130 duration = pulseIn(DUST_SENSOR_DIGITAL_PIN,
LOW);
131 lowpulseoccupancy += duration;
134 if ((endtime-starttime) > sampletime_ms) {
135 ratio = (lowpulseoccupancy-endtime+starttime)/(sampletime_ms*10.0);
136 long concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62;
147 lowpulseoccupancy = 0;
148 return(concentration);