簡單試用,真的非常簡單,就只是試一試而已,能動就收工。
首先感謝MakerPRO歐先生拿給我一套Grove感測器組合。
拿出Grove灰塵感測器,測量空氣中細懸浮微粒。
#define DUST_SENSOR_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(DUST_SENSOR_PIN, INPUT);
starttime = millis(); //get the current time;
}
void loop(){
duration = pulseIn(DUST_SENSOR_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();
}
}
然後打開序列埠監控視窗。
收工。
No comments:
Post a Comment