int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float pcsPerCF = 0;
float ugm3 = 0;
float ratio = 0;
float concentration = 0;
void setup() {
Serial.begin(9600);
pinMode(8, INPUT);
starttime = millis(); //get the current time;
}
void loop() {
{
duration = pulseIn(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
pcsPerCF = concentration * 100;
ugm3 = pcsPerCF / 13000;
Serial.print(" ");
Serial.print(ugm3);
lowpulseoccupancy = 0;
}
}
}
³×À̹ö ºí·Î±×¿¡ ³ª¿Â Äڵ带 È°¿ëÇÏ¿© ¾î¶²½ÄÀ¸·Î µÎ°³ÀÇ ¼¾¼¿¡¼ ³ª¿Â ÃøÁ¤°ªÀ» ÇÁ¸°Æ® ½Ãų ¼ö ÀÖ´ÂÁö ±Ã±ÝÇÕ´Ï´Ù.
´äº¯ÇØÁֽøé Á¤¸»°¨»çÇÏ°Ú½À´Ï´Ù!!